Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks: refactor to use more primordials #36297

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -394,7 +400,9 @@ class PerformanceObserver extends AsyncResource {
if (!ArrayIsArray(entryTypes)) {
throw new ERR_INVALID_ARG_VALUE('options.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 @@ -421,7 +429,7 @@ class PerformanceObserver extends AsyncResource {
class Performance {
constructor() {
this[kIndex] = {
[kMarks]: new Set()
[kMarks]: new SafeSet()
};
}

Expand Down Expand Up @@ -588,7 +596,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 @@ -626,15 +634,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