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 — lib: recycle queues · nodejs/node@830fff0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • fixed_queue.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/fixed_queue.js‎

Copy file name to clipboardExpand all lines: lib/internal/fixed_queue.js
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ class FixedCircularBuffer {
8989
}
9090

9191
module.exports = class FixedQueue {
92+
static #pool = [];
93+
9294
constructor() {
93-
this.head = this.tail = new FixedCircularBuffer();
95+
this.head = this.tail = FixedQueue.#pool.pop() ?? new FixedCircularBuffer();
9496
}
9597

9698
isEmpty() {
@@ -101,7 +103,7 @@ module.exports = class FixedQueue {
101103
if (this.head.isFull()) {
102104
// Head is full: Creates a new queue, sets the old queue's `.next` to it,
103105
// and sets it as the new main queue.
104-
this.head = this.head.next = new FixedCircularBuffer();
106+
this.head = this.head.next = FixedQueue.#pool.pop() ?? new FixedCircularBuffer();
105107
}
106108
this.head.push(data);
107109
}
@@ -113,6 +115,12 @@ module.exports = class FixedQueue {
113115
// If there is another queue, it forms the new tail.
114116
this.tail = tail.next;
115117
tail.next = null;
118+
tail.bottom = 0;
119+
tail.top = 0;
120+
121+
if (FixedQueue.#pool.length < 64) {
122+
FixedQueue.#pool.push(tail); // Recycle old tail
123+
}
116124
}
117125
return next;
118126
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — 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.