@daneren2005/shared-memory-objects 0.0.19 → 0.0.21
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.
|
@@ -112,7 +112,7 @@ class W {
|
|
|
112
112
|
state;
|
|
113
113
|
lock;
|
|
114
114
|
constructor(t = {}) {
|
|
115
|
-
if (this.buf = t.buf ? t.buf : new ArrayBuffer(t.size || 4096), this.start = t.start != null ?
|
|
115
|
+
if (this.buf = t.buf ? t.buf : new ArrayBuffer(t.size || 4096), this.start = t.start != null ? I(Math.max(t.start, 0), 4) : 0, this.u8 = new Uint8Array(this.buf), this.u32 = new Uint32Array(this.buf), this.state = new Uint32Array(this.buf, this.start, ft / 4), this.lock = new Int32Array(this.buf, this.start + this.state.byteLength - 4, 1), !t.skipInitialization) {
|
|
116
116
|
const e = t.align || 8;
|
|
117
117
|
if (e < 8)
|
|
118
118
|
throw new Error(`invalid alignment: ${e}, must be a pow2 and >= 8`);
|
|
@@ -160,7 +160,7 @@ class W {
|
|
|
160
160
|
if (t <= 0)
|
|
161
161
|
return 0;
|
|
162
162
|
z(this.lock);
|
|
163
|
-
const e =
|
|
163
|
+
const e = I(t + y, this.align), r = this.end;
|
|
164
164
|
let s = this.top, o = this._free, a = 0;
|
|
165
165
|
for (; o; ) {
|
|
166
166
|
const l = this.blockSize(o), n = o + l >= s;
|
|
@@ -196,7 +196,7 @@ class W {
|
|
|
196
196
|
realloc(t, e) {
|
|
197
197
|
if (e <= 0)
|
|
198
198
|
return 0;
|
|
199
|
-
const r =
|
|
199
|
+
const r = C(t);
|
|
200
200
|
let s = 0, o = this._used, a = 0;
|
|
201
201
|
for (; o; ) {
|
|
202
202
|
if (o === r) {
|
|
@@ -212,7 +212,7 @@ class W {
|
|
|
212
212
|
), _(s);
|
|
213
213
|
}
|
|
214
214
|
reallocBlock(t, e) {
|
|
215
|
-
const r = this.blockSize(t), s = t + r, o = s >= this.top, a =
|
|
215
|
+
const r = this.blockSize(t), s = t + r, o = s >= this.top, a = I(e + y, this.align);
|
|
216
216
|
if (a <= r) {
|
|
217
217
|
if (this.doSplit) {
|
|
218
218
|
const l = r - a;
|
|
@@ -220,7 +220,7 @@ class W {
|
|
|
220
220
|
} else o && (this.top = t + a);
|
|
221
221
|
return [t, s];
|
|
222
222
|
}
|
|
223
|
-
return o && t + a < this.end ? (this.top = t + this.setBlockSize(t, a), [t, s]) : (this.free(t), [
|
|
223
|
+
return o && t + a < this.end ? (this.top = t + this.setBlockSize(t, a), [t, s]) : (this.free(t), [C(this.malloc(e)), s]);
|
|
224
224
|
}
|
|
225
225
|
reallocArray(t, e) {
|
|
226
226
|
if (t.buffer !== this.buf)
|
|
@@ -239,7 +239,7 @@ class W {
|
|
|
239
239
|
e = t.byteOffset;
|
|
240
240
|
} else
|
|
241
241
|
e = t;
|
|
242
|
-
e =
|
|
242
|
+
e = C(e);
|
|
243
243
|
let r = this._used;
|
|
244
244
|
for (; r; ) {
|
|
245
245
|
if (r === e)
|
|
@@ -260,7 +260,7 @@ class W {
|
|
|
260
260
|
e = t.byteOffset;
|
|
261
261
|
} else
|
|
262
262
|
e = t;
|
|
263
|
-
z(this.lock), e =
|
|
263
|
+
z(this.lock), e = C(e);
|
|
264
264
|
let r = this._used, s = 0;
|
|
265
265
|
for (; r; ) {
|
|
266
266
|
if (r === e)
|
|
@@ -372,7 +372,7 @@ class W {
|
|
|
372
372
|
), this.doCompact && this.compact();
|
|
373
373
|
}
|
|
374
374
|
initialTop(t = this.align) {
|
|
375
|
-
return
|
|
375
|
+
return I(this.start + ft + y, t) - y;
|
|
376
376
|
}
|
|
377
377
|
/**
|
|
378
378
|
* Traverses free list and attempts to recursively merge blocks
|
|
@@ -411,7 +411,7 @@ class W {
|
|
|
411
411
|
r ? this.setBlockNext(r, t) : this._free = t, this.setBlockNext(t, e);
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
|
-
const _ = (i) => i > 0 ? i + y : 0,
|
|
414
|
+
const _ = (i) => i > 0 ? i + y : 0, C = (i) => i > 0 ? i - y : 0, I = (i, t) => (t--, i + t & ~t), qt = {
|
|
415
415
|
u8: 1,
|
|
416
416
|
u8c: 1,
|
|
417
417
|
i8: 1,
|
|
@@ -1137,9 +1137,13 @@ class m {
|
|
|
1137
1137
|
this.firstBlock.data[d] = 0;
|
|
1138
1138
|
}
|
|
1139
1139
|
*[Symbol.iterator]() {
|
|
1140
|
-
let t = this.getFullDataBlock();
|
|
1141
|
-
for (let
|
|
1142
|
-
yield
|
|
1140
|
+
let t = this.getFullDataBlock(), e = this.dataLength, r = this.length * e;
|
|
1141
|
+
for (let s = 0; s < r; s += e)
|
|
1142
|
+
yield t.subarray(s, s + e);
|
|
1143
|
+
}
|
|
1144
|
+
// Significantly faster but won't be thread safe if anything is removing/adding to it during iteration
|
|
1145
|
+
getCurrentArray() {
|
|
1146
|
+
return this.getFullDataBlock().subarray(0, this.length * this.dataLength);
|
|
1143
1147
|
}
|
|
1144
1148
|
getFullDataBlock() {
|
|
1145
1149
|
let t = Atomics.load(this.firstBlock.data, E);
|
|
@@ -1266,7 +1270,7 @@ class me {
|
|
|
1266
1270
|
}
|
|
1267
1271
|
}
|
|
1268
1272
|
const D = 0, Lt = 1, St = 2, q = 3, Tt = q + m.ALLOCATE_COUNT;
|
|
1269
|
-
class
|
|
1273
|
+
class Ct {
|
|
1270
1274
|
static ALLOCATE_COUNT = 3 + m.ALLOCATE_COUNT * 2;
|
|
1271
1275
|
memory;
|
|
1272
1276
|
// Current Length, Type/DataLength, MaxChunkLength, Pointer vector, Recycle vector
|
|
@@ -1319,7 +1323,7 @@ class It {
|
|
|
1319
1323
|
}
|
|
1320
1324
|
});
|
|
1321
1325
|
else {
|
|
1322
|
-
this.firstBlock = t.allocUI32(
|
|
1326
|
+
this.firstBlock = t.allocUI32(Ct.ALLOCATE_COUNT), this.uint16Array = new Uint16Array(this.firstBlock.data.buffer, this.firstBlock.bufferByteOffset + Lt * Uint32Array.BYTES_PER_ELEMENT, 2);
|
|
1323
1327
|
let r = e?.dataLength ?? 1, s = e?.maxChunkSize ?? 100;
|
|
1324
1328
|
this.pointerVector = new m(t, {
|
|
1325
1329
|
type: Uint32Array,
|
|
@@ -1512,7 +1516,7 @@ class be {
|
|
|
1512
1516
|
this.pointers = [], this.recycledIndexes = [], this.totalLength = 0, this.fullDataBlocks = {};
|
|
1513
1517
|
}
|
|
1514
1518
|
}
|
|
1515
|
-
const
|
|
1519
|
+
const It = new ArrayBuffer(4), Nt = new Uint32Array(It), R = new Uint16Array(It);
|
|
1516
1520
|
function ge(i, t) {
|
|
1517
1521
|
return le(Atomics.load(i, t));
|
|
1518
1522
|
}
|
|
@@ -1588,10 +1592,10 @@ function tt(i) {
|
|
|
1588
1592
|
function Y(i) {
|
|
1589
1593
|
return Yt[0] = i, Ht[0];
|
|
1590
1594
|
}
|
|
1591
|
-
function
|
|
1595
|
+
function Ce(i, t, e) {
|
|
1592
1596
|
return i instanceof Float64Array && (i = new BigInt64Array(i.buffer, i.byteOffset, i.length)), tt(Atomics.exchange(i, t, Y(e)));
|
|
1593
1597
|
}
|
|
1594
|
-
function
|
|
1598
|
+
function Ie(i, t, e, r) {
|
|
1595
1599
|
return i instanceof Float64Array && (i = new BigInt64Array(i.buffer, i.byteOffset, i.length)), tt(Atomics.compareExchange(i, t, Y(e), Y(r)));
|
|
1596
1600
|
}
|
|
1597
1601
|
const w = 0, J = 1, S = 2;
|
|
@@ -1627,13 +1631,13 @@ export {
|
|
|
1627
1631
|
u as SharedList,
|
|
1628
1632
|
Ot as SharedMap,
|
|
1629
1633
|
Be as SharedPointerList,
|
|
1630
|
-
|
|
1634
|
+
Ct as SharedPool,
|
|
1631
1635
|
Mt as SharedString,
|
|
1632
1636
|
m as SharedVector,
|
|
1633
1637
|
Te as addAtomicFloat32,
|
|
1634
1638
|
Le as addAtomicInt,
|
|
1635
1639
|
Rt as compareExchangeFloat32,
|
|
1636
|
-
|
|
1640
|
+
Ie as compareExchangeFloat64,
|
|
1637
1641
|
fe as convert16To32,
|
|
1638
1642
|
le as convert32To16,
|
|
1639
1643
|
$ as convertFloat32ToInt32,
|
|
@@ -1642,7 +1646,7 @@ export {
|
|
|
1642
1646
|
tt as convertInt64ToFloat64,
|
|
1643
1647
|
L as createPointer,
|
|
1644
1648
|
we as exchangeFloat32,
|
|
1645
|
-
|
|
1649
|
+
Ce as exchangeFloat64,
|
|
1646
1650
|
B as getPointer,
|
|
1647
1651
|
ge as load16From32,
|
|
1648
1652
|
Ae as load16From64,
|