@nxtedition/lib 28.0.15 → 28.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/shared.js +3 -7
- package/slice.js +4 -56
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "28.0.
|
|
3
|
+
"version": "28.0.17",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"type": "module",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"pino": ">=7.0.0",
|
|
93
93
|
"rxjs": "^7.0.0"
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "dfb1058f0e5dea78cb723add803ada5bcfdb908c"
|
|
96
96
|
}
|
package/shared.js
CHANGED
|
@@ -94,9 +94,6 @@ export function reader({ sharedState, sharedBuffer }) {
|
|
|
94
94
|
// wrapped around to the beginning of the buffer.
|
|
95
95
|
if (dataLen === -1) {
|
|
96
96
|
readPos = 0
|
|
97
|
-
// After wrapping, we must re-check against the writer's position.
|
|
98
|
-
// It's possible the writer is now at a position > 0.
|
|
99
|
-
writePos = Atomics.load(state, WRITE_INDEX) | 0
|
|
100
97
|
} else {
|
|
101
98
|
if (dataLen < 0) {
|
|
102
99
|
throw new Error('Invalid data length')
|
|
@@ -122,7 +119,7 @@ export function reader({ sharedState, sharedBuffer }) {
|
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
// IMPORTANT: The reader only updates its shared `readPos` after a batch
|
|
125
|
-
// is processed. This significantly reduces atomic
|
|
122
|
+
// is processed. This significantly reduces atomic operation overhead.
|
|
126
123
|
if (bytes > 0) {
|
|
127
124
|
Atomics.store(state, READ_INDEX, readPos)
|
|
128
125
|
}
|
|
@@ -228,7 +225,7 @@ export function writer({ sharedState, sharedBuffer }, { yield: onYield, logger }
|
|
|
228
225
|
}
|
|
229
226
|
|
|
230
227
|
if (readPos === 0) {
|
|
231
|
-
|
|
228
|
+
_yield(0)
|
|
232
229
|
}
|
|
233
230
|
|
|
234
231
|
// Not enough space at the end. Check if there's space at the beginning.
|
|
@@ -259,7 +256,7 @@ export function writer({ sharedState, sharedBuffer }, { yield: onYield, logger }
|
|
|
259
256
|
// The only free space is between W and R.
|
|
260
257
|
|
|
261
258
|
if (readPos - writePos < required) {
|
|
262
|
-
|
|
259
|
+
_yield(0)
|
|
263
260
|
}
|
|
264
261
|
|
|
265
262
|
return readPos - writePos >= required
|
|
@@ -375,7 +372,6 @@ export function writer({ sharedState, sharedBuffer }, { yield: onYield, logger }
|
|
|
375
372
|
if (!_acquire(len)) {
|
|
376
373
|
const startTime = performance.now()
|
|
377
374
|
logger?.warn({ readPos, writePos }, 'yield started')
|
|
378
|
-
_yield(0)
|
|
379
375
|
for (let n = 0; !_acquire(len); n++) {
|
|
380
376
|
if (performance.now() - startTime > timeout) {
|
|
381
377
|
throw new Error('Timeout while waiting for space in the buffer')
|
package/slice.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import util from 'node:util'
|
|
2
2
|
|
|
3
3
|
const EMPTY_BUF = Buffer.alloc(0)
|
|
4
|
-
const POOL = []
|
|
5
4
|
|
|
6
5
|
export class Slice {
|
|
7
6
|
buffer
|
|
@@ -24,6 +23,10 @@ export class Slice {
|
|
|
24
23
|
byteLength = buffer.byteLength,
|
|
25
24
|
maxByteLength = byteLength,
|
|
26
25
|
) {
|
|
26
|
+
if (!(buffer instanceof Buffer)) {
|
|
27
|
+
throw new TypeError('buffer must be a Buffer')
|
|
28
|
+
}
|
|
29
|
+
|
|
27
30
|
if (byteOffset < 0 || !Number.isInteger(byteOffset)) {
|
|
28
31
|
throw new RangeError(`Invalid byteOffset: ${byteOffset}`)
|
|
29
32
|
}
|
|
@@ -46,61 +49,6 @@ export class Slice {
|
|
|
46
49
|
this.maxByteLength = maxByteLength
|
|
47
50
|
}
|
|
48
51
|
|
|
49
|
-
static create(buffer, byteOffset, byteLength, maxByteLength) {
|
|
50
|
-
if (buffer === undefined) {
|
|
51
|
-
buffer = Slice.EMPTY_BUF
|
|
52
|
-
}
|
|
53
|
-
if (byteOffset === undefined) {
|
|
54
|
-
byteOffset = 0
|
|
55
|
-
}
|
|
56
|
-
if (byteLength === undefined) {
|
|
57
|
-
byteLength = buffer.byteLength
|
|
58
|
-
}
|
|
59
|
-
if (maxByteLength === undefined) {
|
|
60
|
-
maxByteLength = byteLength
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (byteOffset < 0) {
|
|
64
|
-
throw new RangeError('byteOffset must be non-negative')
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (byteLength < 0) {
|
|
68
|
-
throw new RangeError('byteLength must be non-negative')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (byteLength > maxByteLength) {
|
|
72
|
-
throw new RangeError('byteLength cannot be greater than maxByteLength')
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (byteOffset + maxByteLength > buffer.byteLength) {
|
|
76
|
-
throw new RangeError('Slice exceeds buffer length')
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const slice = POOL.pop()
|
|
80
|
-
|
|
81
|
-
if (slice) {
|
|
82
|
-
slice.buffer = buffer
|
|
83
|
-
slice.byteOffset = byteOffset
|
|
84
|
-
slice.byteLength = byteLength
|
|
85
|
-
slice.maxByteLength = maxByteLength
|
|
86
|
-
return slice
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return new Slice(buffer, byteOffset, byteLength, maxByteLength)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static free(slice) {
|
|
93
|
-
if (slice == null) {
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
slice.reset()
|
|
98
|
-
|
|
99
|
-
if (POOL.length < 16 * 1024) {
|
|
100
|
-
POOL.push(slice)
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
52
|
reset() {
|
|
105
53
|
this.buffer = Slice.EMPTY_BUF
|
|
106
54
|
this.byteOffset = 0
|