Skip to content

Commit 4f59b33

Browse files
Uzlopakslagiewka
authored andcommitted
chore: FixedQueue does not need special constructor (nodejs#4476)
1 parent bad3f79 commit 4f59b33

1 file changed

Lines changed: 15 additions & 39 deletions

File tree

lib/dispatcher/fixed-queue.js

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,21 @@ const kMask = kSize - 1
5959
* @template T
6060
*/
6161
class FixedCircularBuffer {
62-
constructor () {
63-
/**
64-
* @type {number}
65-
*/
66-
this.bottom = 0
67-
/**
68-
* @type {number}
69-
*/
70-
this.top = 0
71-
/**
72-
* @type {Array<T|undefined>}
73-
*/
74-
this.list = new Array(kSize).fill(undefined)
75-
/**
76-
* @type {T|null}
77-
*/
78-
this.next = null
79-
}
62+
/** @type {number} */
63+
bottom = 0
64+
/** @type {number} */
65+
top = 0
66+
/** @type {Array<T|undefined>} */
67+
list = new Array(kSize).fill(undefined)
68+
/** @type {T|null} */
69+
next = null
8070

81-
/**
82-
* @returns {boolean}
83-
*/
71+
/** @returns {boolean} */
8472
isEmpty () {
8573
return this.top === this.bottom
8674
}
8775

88-
/**
89-
* @returns {boolean}
90-
*/
76+
/** @returns {boolean} */
9177
isFull () {
9278
return ((this.top + 1) & kMask) === this.bottom
9379
}
@@ -101,9 +87,7 @@ class FixedCircularBuffer {
10187
this.top = (this.top + 1) & kMask
10288
}
10389

104-
/**
105-
* @returns {T|null}
106-
*/
90+
/** @returns {T|null} */
10791
shift () {
10892
const nextItem = this.list[this.bottom]
10993
if (nextItem === undefined) { return null }
@@ -118,22 +102,16 @@ class FixedCircularBuffer {
118102
*/
119103
module.exports = class FixedQueue {
120104
constructor () {
121-
/**
122-
* @type {FixedCircularBuffer<T>}
123-
*/
105+
/** @type {FixedCircularBuffer<T>} */
124106
this.head = this.tail = new FixedCircularBuffer()
125107
}
126108

127-
/**
128-
* @returns {boolean}
129-
*/
109+
/** @returns {boolean} */
130110
isEmpty () {
131111
return this.head.isEmpty()
132112
}
133113

134-
/**
135-
* @param {T} data
136-
*/
114+
/** @param {T} data */
137115
push (data) {
138116
if (this.head.isFull()) {
139117
// Head is full: Creates a new queue, sets the old queue's `.next` to it,
@@ -143,9 +121,7 @@ module.exports = class FixedQueue {
143121
this.head.push(data)
144122
}
145123

146-
/**
147-
* @returns {T|null}
148-
*/
124+
/** @returns {T|null} */
149125
shift () {
150126
const tail = this.tail
151127
const next = tail.shift()

0 commit comments

Comments
 (0)