Skip to content

Commit b69d200

Browse files
authored
refactor(fixed_queue): use real private fields and fix TypeScript ES2022 perf regression (piscinajs#747)
1 parent 89bb036 commit b69d200

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/task_queue/fixed_queue.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,10 @@ const kMask = kSize - 1;
5959
// but allows much quicker checks.
6060

6161
class FixedCircularBuffer {
62-
bottom: number
63-
top: number
64-
list: Array<Task | undefined>
65-
next: FixedCircularBuffer | null
66-
67-
constructor () {
68-
this.bottom = 0;
69-
this.top = 0;
70-
this.list = new Array(kSize);
71-
this.next = null;
72-
}
62+
bottom: number = 0
63+
top: number = 0
64+
list: Array<Task | undefined> = new Array(kSize)
65+
next: FixedCircularBuffer | null = null
7366

7467
isEmpty () {
7568
return this.top === this.bottom;
@@ -116,7 +109,7 @@ class FixedCircularBuffer {
116109
export class FixedQueue implements TaskQueue {
117110
head: FixedCircularBuffer
118111
tail: FixedCircularBuffer
119-
_size: number = 0
112+
#size: number = 0
120113

121114
constructor () {
122115
this.head = this.tail = new FixedCircularBuffer();
@@ -133,13 +126,13 @@ export class FixedQueue implements TaskQueue {
133126
this.head = this.head.next = new FixedCircularBuffer();
134127
}
135128
this.head.push(data);
136-
this._size++;
129+
this.#size++;
137130
}
138131

139132
shift (): Task | null {
140133
const tail = this.tail;
141134
const next = tail.shift();
142-
if (next !== null) this._size--;
135+
if (next !== null) this.#size--;
143136
if (tail.isEmpty() && tail.next !== null) {
144137
// If there is another queue, it forms the new tail.
145138
this.tail = tail.next;
@@ -154,7 +147,7 @@ export class FixedQueue implements TaskQueue {
154147
while (true) {
155148
if (buffer.list.includes(task)) {
156149
buffer.remove(task);
157-
this._size--;
150+
this.#size--;
158151
break;
159152
}
160153
if (buffer.next === null) break;
@@ -179,6 +172,6 @@ export class FixedQueue implements TaskQueue {
179172
}
180173

181174
get size () {
182-
return this._size;
175+
return this.#size;
183176
}
184177
};

0 commit comments

Comments
 (0)