Skip to content

Commit

Permalink
perf_hooks: refactor to use more primordials
Browse files Browse the repository at this point in the history
PR-URL: #36297
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
aduh95 authored and targos committed Jun 11, 2021
1 parent 6c1bbb5 commit 6adec63
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions lib/perf_hooks.js
Expand Up @@ -2,12 +2,18 @@

const {
ArrayIsArray,
ArrayPrototypeFilter,
ArrayPrototypeIncludes,
ArrayPrototypeMap,
ArrayPrototypePush,
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
Boolean,
NumberIsSafeInteger,
ObjectDefineProperties,
ObjectDefineProperty,
ObjectKeys,
Set,
SafeSet,
Symbol,
} = primordials;

Expand Down Expand Up @@ -383,7 +389,9 @@ class PerformanceObserver extends AsyncResource {
if (!ArrayIsArray(entryTypes)) {
throw new ERR_INVALID_OPT_VALUE('entryTypes', entryTypes);
}
const filteredEntryTypes = entryTypes.filter(filterTypes).map(mapTypes);
const filteredEntryTypes =
ArrayPrototypeMap(ArrayPrototypeFilter(entryTypes, filterTypes),
mapTypes);
if (filteredEntryTypes.length === 0) {
throw new ERR_VALID_PERFORMANCE_ENTRY_TYPE();
}
Expand All @@ -410,7 +418,7 @@ class PerformanceObserver extends AsyncResource {
class Performance {
constructor() {
this[kIndex] = {
[kMarks]: new Set()
[kMarks]: new SafeSet()
};
}

Expand Down Expand Up @@ -577,7 +585,7 @@ function observersCallback(entry) {
setupObservers(observersCallback);

function filterTypes(i) {
return observerableTypes.indexOf(`${i}`) >= 0;
return ArrayPrototypeIncludes(observerableTypes, `${i}`);
}

function mapTypes(i) {
Expand Down Expand Up @@ -615,15 +623,15 @@ function sortedInsert(list, entry) {
const entryStartTime = entry.startTime;
if (list.length === 0 ||
(list[list.length - 1].startTime < entryStartTime)) {
list.push(entry);
ArrayPrototypePush(list, entry);
return;
}
if (list[0] && (list[0].startTime > entryStartTime)) {
list.unshift(entry);
ArrayPrototypeUnshift(list, entry);
return;
}
const location = getInsertLocation(list, entryStartTime);
list.splice(location, 0, entry);
ArrayPrototypeSplice(list, location, 0, entry);
}

class ELDHistogram extends Histogram {
Expand Down

0 comments on commit 6adec63

Please sign in to comment.