@nxtedition/slice 1.0.9 → 1.0.11

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 CHANGED
@@ -26,6 +26,7 @@ export declare class PoolAllocator {
26
26
  constructor(poolTotal?: number);
27
27
  get size(): number;
28
28
  isFromPool(slice: Slice | null | undefined): boolean;
29
+ realloc(byteLength: number): Slice;
29
30
  realloc(slice: Slice, byteLength: number): Slice;
30
31
  get stats(): {
31
32
  size: number;
package/lib/index.js CHANGED
@@ -249,19 +249,28 @@ export class PoolAllocator {
249
249
  return slice != null && slice.buffer === this.#poolBuffer
250
250
  }
251
251
 
252
- realloc(slice , byteLength ) {
253
- if (!Number.isInteger(byteLength) || byteLength < 0) {
252
+
253
+
254
+ realloc(slice , byteLength ) {
255
+ if (typeof slice === 'number') {
256
+ byteLength = slice
257
+ slice = new Slice()
258
+ }
259
+
260
+ if (byteLength == null || !Number.isInteger(byteLength) || byteLength < 0) {
254
261
  throw new TypeError(`Invalid byteLength: ${byteLength}`)
255
262
  }
256
263
 
257
- if (slice.byteLength === byteLength) {
264
+ if (slice == null) {
265
+ slice = new Slice()
266
+ } else if (slice.byteLength === byteLength) {
258
267
  return slice
259
268
  }
260
269
 
261
270
  // Ceil to nearest power of two.
262
271
  const dstIdx = byteLength <= 8 ? 3 : 32 - Math.clz32(byteLength - 1)
263
272
 
264
- if (slice != null && slice.buffer === this.#poolBuffer) {
273
+ if (slice.buffer === this.#poolBuffer) {
265
274
  const srcIdx = 32 - Math.clz32(slice.maxByteLength - 1)
266
275
 
267
276
  if (slice.maxByteLength !== 1 << srcIdx) {
@@ -300,6 +309,8 @@ export class PoolAllocator {
300
309
  slice.maxByteLength = maxByteLength
301
310
 
302
311
  this.#poolSize += maxByteLength
312
+ this.#size += maxByteLength
313
+ this.#padding += maxByteLength - byteLength
303
314
  } else if (
304
315
  dstIdx < this.#pools.length &&
305
316
  this.#poolOffset + maxByteLength <= this.#poolBuffer.byteLength
@@ -312,6 +323,8 @@ export class PoolAllocator {
312
323
  this.#poolOffset += maxByteLength
313
324
  this.#poolCount += 1
314
325
  this.#poolSize += maxByteLength
326
+ this.#size += maxByteLength
327
+ this.#padding += maxByteLength - byteLength
315
328
  } else {
316
329
  slice.buffer = Buffer.allocUnsafeSlow(byteLength)
317
330
  slice.byteOffset = 0
@@ -319,9 +332,6 @@ export class PoolAllocator {
319
332
  slice.maxByteLength = byteLength
320
333
  }
321
334
 
322
- this.#size += slice.maxByteLength
323
- this.#padding += slice.maxByteLength - slice.byteLength
324
-
325
335
  return slice
326
336
  }
327
337
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/slice",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -24,9 +24,9 @@
24
24
  "devDependencies": {
25
25
  "@types/node": "^25.2.3",
26
26
  "amaroc": "^1.0.1",
27
- "oxlint-tsgolint": "^0.12.2",
28
- "rimraf": "^6.1.2",
27
+ "oxlint-tsgolint": "^0.13.0",
28
+ "rimraf": "^6.1.3",
29
29
  "typescript": "^5.9.3"
30
30
  },
31
- "gitHead": "f385fe31237669bf5f9ac1fb5154e5a353710d01"
31
+ "gitHead": "f6592f0be62fecc161237610ae6454ec6585548b"
32
32
  }