Skip to content

Commit 6adec63

Browse files
aduh95targos
authored andcommitted
perf_hooks: refactor to use more primordials
PR-URL: #36297 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 6c1bbb5 commit 6adec63

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

lib/perf_hooks.js

+15-7
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
throw new ERR_INVALID_OPT_VALUE('entryTypes', entryTypes);
385391
}
386-
const filteredEntryTypes = entryTypes.filter(filterTypes).map(mapTypes);
392+
const filteredEntryTypes =
393+
ArrayPrototypeMap(ArrayPrototypeFilter(entryTypes, filterTypes),
394+
mapTypes);
387395
if (filteredEntryTypes.length === 0) {
388396
throw new ERR_VALID_PERFORMANCE_ENTRY_TYPE();
389397
}
@@ -410,7 +418,7 @@ class PerformanceObserver extends AsyncResource {
410418
class Performance {
411419
constructor() {
412420
this[kIndex] = {
413-
[kMarks]: new Set()
421+
[kMarks]: new SafeSet()
414422
};
415423
}
416424

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

579587
function filterTypes(i) {
580-
return observerableTypes.indexOf(`${i}`) >= 0;
588+
return ArrayPrototypeIncludes(observerableTypes, `${i}`);
581589
}
582590

583591
function mapTypes(i) {
@@ -615,15 +623,15 @@ function sortedInsert(list, entry) {
615623
const entryStartTime = 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
const location = getInsertLocation(list, entryStartTime);
626-
list.splice(location, 0, entry);
634+
ArrayPrototypeSplice(list, location, 0, entry);
627635
}
628636

629637
class ELDHistogram extends Histogram {

0 commit comments

Comments
 (0)