@nxtedition/slice 1.0.2 → 1.0.3
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 +2 -1
- package/lib/index.js +11 -7
- package/package.json +3 -2
package/lib/index.d.ts
CHANGED
|
@@ -24,7 +24,8 @@ export declare class Slice {
|
|
|
24
24
|
export declare class PoolAllocator {
|
|
25
25
|
#private;
|
|
26
26
|
constructor(poolTotal?: number);
|
|
27
|
-
|
|
27
|
+
get size(): number;
|
|
28
|
+
isFromPool(slice: Slice | null | undefined): boolean;
|
|
28
29
|
realloc(slice: Slice, byteLength: number): Slice;
|
|
29
30
|
get stats(): {
|
|
30
31
|
size: number;
|
package/lib/index.js
CHANGED
|
@@ -223,13 +223,13 @@ export class Slice {
|
|
|
223
223
|
|
|
224
224
|
export class PoolAllocator {
|
|
225
225
|
#size = 0
|
|
226
|
+
#padding = 0
|
|
226
227
|
|
|
227
228
|
#pools = []
|
|
228
229
|
#poolBuffer
|
|
229
230
|
#poolOffset = 0
|
|
230
231
|
#poolSize = 0
|
|
231
232
|
#poolCount = 0
|
|
232
|
-
#padding = 0
|
|
233
233
|
|
|
234
234
|
constructor(poolTotal = 128 * 1024 * 1024) {
|
|
235
235
|
this.#poolBuffer = Buffer.allocUnsafe(Number.isFinite(poolTotal) ? poolTotal : 0)
|
|
@@ -238,7 +238,11 @@ export class PoolAllocator {
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
|
|
241
|
+
get size() {
|
|
242
|
+
return this.#size
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
isFromPool(slice ) {
|
|
242
246
|
return slice != null && slice.buffer === this.#poolBuffer
|
|
243
247
|
}
|
|
244
248
|
|
|
@@ -254,19 +258,19 @@ export class PoolAllocator {
|
|
|
254
258
|
// Ceil to nearest power of two.
|
|
255
259
|
const dstIdx = byteLength <= 8 ? 3 : 32 - Math.clz32(byteLength - 1)
|
|
256
260
|
|
|
257
|
-
if (this
|
|
261
|
+
if (slice != null && slice.buffer === this.#poolBuffer) {
|
|
258
262
|
const srcIdx = 32 - Math.clz32(slice.maxByteLength - 1)
|
|
259
263
|
|
|
260
264
|
if (slice.maxByteLength !== 1 << srcIdx) {
|
|
261
265
|
throw new Error(`Invalid pool state`)
|
|
262
266
|
}
|
|
263
267
|
|
|
264
|
-
this.#size -= slice.
|
|
268
|
+
this.#size -= slice.maxByteLength
|
|
265
269
|
this.#padding -= slice.maxByteLength - slice.byteLength
|
|
266
270
|
|
|
267
271
|
if (srcIdx === dstIdx) {
|
|
268
272
|
slice.byteLength = byteLength
|
|
269
|
-
this.#size += slice.
|
|
273
|
+
this.#size += slice.maxByteLength
|
|
270
274
|
this.#padding += slice.maxByteLength - slice.byteLength
|
|
271
275
|
return slice
|
|
272
276
|
}
|
|
@@ -312,7 +316,7 @@ export class PoolAllocator {
|
|
|
312
316
|
slice.maxByteLength = byteLength
|
|
313
317
|
}
|
|
314
318
|
|
|
315
|
-
this.#size += slice.
|
|
319
|
+
this.#size += slice.maxByteLength
|
|
316
320
|
this.#padding += slice.maxByteLength - slice.byteLength
|
|
317
321
|
|
|
318
322
|
return slice
|
|
@@ -322,7 +326,7 @@ export class PoolAllocator {
|
|
|
322
326
|
return {
|
|
323
327
|
size: this.#size,
|
|
324
328
|
padding: this.#padding,
|
|
325
|
-
ratio: this.#size > 0 ?
|
|
329
|
+
ratio: this.#size > 0 ? this.#size / (this.#size - this.#padding) : 1,
|
|
326
330
|
poolTotal: this.#poolBuffer.byteLength,
|
|
327
331
|
poolUsed: this.#poolOffset,
|
|
328
332
|
poolSize: this.#poolSize,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/slice",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -19,5 +19,6 @@
|
|
|
19
19
|
"amaroc": "^1.0.1",
|
|
20
20
|
"rimraf": "^6.1.2",
|
|
21
21
|
"typescript": "^5.9.3"
|
|
22
|
-
}
|
|
22
|
+
},
|
|
23
|
+
"gitHead": "a798a1529b93f64e8dd82ccc8c23579c231afdbd"
|
|
23
24
|
}
|