From 6adec6351e7824a2d172549b396318b53a3d5adf Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 21 Nov 2020 20:21:01 +0100 Subject: [PATCH] perf_hooks: refactor to use more primordials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/36297 Reviewed-By: Rich Trott Reviewed-By: Michaƫl Zasso --- lib/perf_hooks.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index 3df0ea16cda1e5..0d6eb59992ad54 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -2,12 +2,18 @@ const { ArrayIsArray, + ArrayPrototypeFilter, + ArrayPrototypeIncludes, + ArrayPrototypeMap, + ArrayPrototypePush, + ArrayPrototypeSplice, + ArrayPrototypeUnshift, Boolean, NumberIsSafeInteger, ObjectDefineProperties, ObjectDefineProperty, ObjectKeys, - Set, + SafeSet, Symbol, } = primordials; @@ -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(); } @@ -410,7 +418,7 @@ class PerformanceObserver extends AsyncResource { class Performance { constructor() { this[kIndex] = { - [kMarks]: new Set() + [kMarks]: new SafeSet() }; } @@ -577,7 +585,7 @@ function observersCallback(entry) { setupObservers(observersCallback); function filterTypes(i) { - return observerableTypes.indexOf(`${i}`) >= 0; + return ArrayPrototypeIncludes(observerableTypes, `${i}`); } function mapTypes(i) { @@ -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 {