@nxtedition/slice 1.0.11 → 1.0.12
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/lib/index.d.ts +5 -0
- package/lib/index.js +21 -7
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -228,7 +228,8 @@ export class PoolAllocator {
|
|
|
228
228
|
#size = 0
|
|
229
229
|
#padding = 0
|
|
230
230
|
|
|
231
|
-
#
|
|
231
|
+
#poolsBucket = []
|
|
232
|
+
#poolsBucketUsed = []
|
|
232
233
|
#poolBuffer
|
|
233
234
|
#poolOffset = 0
|
|
234
235
|
#poolSize = 0
|
|
@@ -237,7 +238,8 @@ export class PoolAllocator {
|
|
|
237
238
|
constructor(poolTotal = 128 * 1024 * 1024) {
|
|
238
239
|
this.#poolBuffer = Buffer.allocUnsafe(Number.isFinite(poolTotal) ? poolTotal : 0)
|
|
239
240
|
for (let n = 0; 2 ** n <= 256 * 1024; n++) {
|
|
240
|
-
this.#
|
|
241
|
+
this.#poolsBucket.push([])
|
|
242
|
+
this.#poolsBucketUsed.push(0)
|
|
241
243
|
}
|
|
242
244
|
}
|
|
243
245
|
|
|
@@ -287,7 +289,8 @@ export class PoolAllocator {
|
|
|
287
289
|
return slice
|
|
288
290
|
}
|
|
289
291
|
|
|
290
|
-
this.#
|
|
292
|
+
this.#poolsBucket[srcIdx].push(slice.byteOffset)
|
|
293
|
+
this.#poolsBucketUsed[srcIdx] -= 1
|
|
291
294
|
this.#poolSize -= slice.maxByteLength
|
|
292
295
|
}
|
|
293
296
|
|
|
@@ -298,21 +301,26 @@ export class PoolAllocator {
|
|
|
298
301
|
}
|
|
299
302
|
|
|
300
303
|
const maxByteLength = 1 << dstIdx
|
|
301
|
-
if (
|
|
304
|
+
if (
|
|
305
|
+
this.#poolsBucket.length > 32 ||
|
|
306
|
+
maxByteLength < byteLength ||
|
|
307
|
+
(maxByteLength & 0x7) !== 0
|
|
308
|
+
) {
|
|
302
309
|
throw new Error(`Invalid pool state`)
|
|
303
310
|
}
|
|
304
311
|
|
|
305
|
-
if (dstIdx < this.#
|
|
312
|
+
if (dstIdx < this.#poolsBucket.length && this.#poolsBucket[dstIdx]?.length) {
|
|
306
313
|
slice.buffer = this.#poolBuffer
|
|
307
|
-
slice.byteOffset = this.#
|
|
314
|
+
slice.byteOffset = this.#poolsBucket[dstIdx].pop()
|
|
308
315
|
slice.byteLength = byteLength
|
|
309
316
|
slice.maxByteLength = maxByteLength
|
|
310
317
|
|
|
318
|
+
this.#poolsBucketUsed[dstIdx] += 1
|
|
311
319
|
this.#poolSize += maxByteLength
|
|
312
320
|
this.#size += maxByteLength
|
|
313
321
|
this.#padding += maxByteLength - byteLength
|
|
314
322
|
} else if (
|
|
315
|
-
dstIdx < this.#
|
|
323
|
+
dstIdx < this.#poolsBucket.length &&
|
|
316
324
|
this.#poolOffset + maxByteLength <= this.#poolBuffer.byteLength
|
|
317
325
|
) {
|
|
318
326
|
slice.buffer = this.#poolBuffer
|
|
@@ -322,6 +330,7 @@ export class PoolAllocator {
|
|
|
322
330
|
|
|
323
331
|
this.#poolOffset += maxByteLength
|
|
324
332
|
this.#poolCount += 1
|
|
333
|
+
this.#poolsBucketUsed[dstIdx] += 1
|
|
325
334
|
this.#poolSize += maxByteLength
|
|
326
335
|
this.#size += maxByteLength
|
|
327
336
|
this.#padding += maxByteLength - byteLength
|
|
@@ -344,6 +353,11 @@ export class PoolAllocator {
|
|
|
344
353
|
poolUsed: this.#poolOffset,
|
|
345
354
|
poolSize: this.#poolSize,
|
|
346
355
|
poolCount: this.#poolCount,
|
|
356
|
+
buckets: this.#poolsBucket.map((pool, i) => ({
|
|
357
|
+
free: pool.length,
|
|
358
|
+
used: this.#poolsBucketUsed[i],
|
|
359
|
+
size: pool.length + this.#poolsBucketUsed[i],
|
|
360
|
+
})),
|
|
347
361
|
}
|
|
348
362
|
}
|
|
349
363
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/slice",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"rimraf": "^6.1.3",
|
|
29
29
|
"typescript": "^5.9.3"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "cfc529e921c93a1fb0292018e2026f2b326ec998"
|
|
32
32
|
}
|