GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf_hooks: refactor to avoid unsafe array iteration · nodejs/node@a258bc9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • perf_hooks.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/perf_hooks.js‎

Copy file name to clipboardExpand all lines: lib/perf_hooks.js
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const {
44
ArrayIsArray,
55
ArrayPrototypeFilter,
6+
ArrayPrototypeForEach,
67
ArrayPrototypeIncludes,
78
ArrayPrototypeMap,
89
ArrayPrototypePush,
@@ -375,13 +376,13 @@ class PerformanceObserver {
375376
disconnect() {
376377
const observerCountsGC = observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC];
377378
const types = this[kTypes];
378-
for (const key of ObjectKeys(types)) {
379+
ArrayPrototypeForEach(ObjectKeys(types), (key) => {
379380
const item = types[key];
380381
if (item) {
381382
L.remove(item);
382383
observerCounts[key]--;
383384
}
384-
}
385+
});
385386
this[kTypes] = {};
386387
if (observerCountsGC === 1 &&
387388
observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC] === 0) {
@@ -408,14 +409,14 @@ class PerformanceObserver {
408409
this[kBuffer][kEntries] = [];
409410
L.init(this[kBuffer][kEntries]);
410411
this[kBuffering] = Boolean(options.buffered);
411-
for (const entryType of filteredEntryTypes) {
412+
ArrayPrototypeForEach(filteredEntryTypes, (entryType) => {
412413
const list = getObserversList(entryType);
413-
if (this[kTypes][entryType]) continue;
414+
if (this[kTypes][entryType]) return;
414415
const item = { obs: this };
415416
this[kTypes][entryType] = item;
416417
L.append(list, item);
417418
observerCounts[entryType]++;
418-
}
419+
});
419420
if (observerCountsGC === 0 &&
420421
observerCounts[NODE_PERFORMANCE_ENTRY_TYPE_GC] === 1) {
421422
installGarbageCollectionTracking();
@@ -640,6 +641,7 @@ function sortedInsert(list, entry) {
640641
}
641642

642643
class ELDHistogram extends Histogram {
644+
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
643645
enable() { return this[kHandle].enable(); }
644646
disable() { return this[kHandle].disable(); }
645647
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.