Skip to content

Commit 6adec63

Browse files
aduh95targos
authored andcommitted
perf_hooks: refactor to use more primordials
PR-URL: #36297 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 6c1bbb5 commit 6adec63

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

‎lib/perf_hooks.js‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22

33
const{
44
ArrayIsArray,
5+
ArrayPrototypeFilter,
6+
ArrayPrototypeIncludes,
7+
ArrayPrototypeMap,
8+
ArrayPrototypePush,
9+
ArrayPrototypeSplice,
10+
ArrayPrototypeUnshift,
511
Boolean,
612
NumberIsSafeInteger,
713
ObjectDefineProperties,
814
ObjectDefineProperty,
915
ObjectKeys,
10-
Set,
16+
SafeSet,
1117
Symbol,
1218
}=primordials;
1319

@@ -383,7 +389,9 @@ class PerformanceObserver extends AsyncResource {
383389
if(!ArrayIsArray(entryTypes)){
384390
thrownewERR_INVALID_OPT_VALUE('entryTypes',entryTypes);
385391
}
386-
constfilteredEntryTypes=entryTypes.filter(filterTypes).map(mapTypes);
392+
constfilteredEntryTypes=
393+
ArrayPrototypeMap(ArrayPrototypeFilter(entryTypes,filterTypes),
394+
mapTypes);
387395
if(filteredEntryTypes.length===0){
388396
thrownewERR_VALID_PERFORMANCE_ENTRY_TYPE();
389397
}
@@ -410,7 +418,7 @@ class PerformanceObserver extends AsyncResource {
410418
classPerformance{
411419
constructor(){
412420
this[kIndex]={
413-
[kMarks]: newSet()
421+
[kMarks]: newSafeSet()
414422
};
415423
}
416424

@@ -577,7 +585,7 @@ function observersCallback(entry) {
577585
setupObservers(observersCallback);
578586

579587
functionfilterTypes(i){
580-
returnobserverableTypes.indexOf(`${i}`)>=0;
588+
returnArrayPrototypeIncludes(observerableTypes,`${i}`);
581589
}
582590

583591
functionmapTypes(i){
@@ -615,15 +623,15 @@ function sortedInsert(list, entry) {
615623
constentryStartTime=entry.startTime;
616624
if(list.length===0||
617625
(list[list.length-1].startTime<entryStartTime)){
618-
list.push(entry);
626+
ArrayPrototypePush(list,entry);
619627
return;
620628
}
621629
if(list[0]&&(list[0].startTime>entryStartTime)){
622-
list.unshift(entry);
630+
ArrayPrototypeUnshift(list,entry);
623631
return;
624632
}
625633
constlocation=getInsertLocation(list,entryStartTime);
626-
list.splice(location,0,entry);
634+
ArrayPrototypeSplice(list,location,0,entry);
627635
}
628636

629637
classELDHistogramextendsHistogram{

0 commit comments

Comments
 (0)