@harmoniclabs/pebble 0.1.7 → 0.1.8
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.
|
@@ -2,18 +2,13 @@
|
|
|
2
2
|
import { fromHex } from "@harmoniclabs/uint8array-utils";
|
|
3
3
|
const MAX_SAFE_INTEGER = Number(globalThis.Number?.MAX_SAFE_INTEGER ?? ((2 ** 53) - 1));
|
|
4
4
|
const MIN_SAFE_INTEGER = Number(globalThis.Number?.MIN_SAFE_INTEGER ?? -MAX_SAFE_INTEGER);
|
|
5
|
-
|
|
6
|
-
const _sym_to_hash = new WeakMap();
|
|
7
|
-
// we cannot store the symbol itself as it would prevent garbage collection
|
|
8
|
-
/// @ts-ignore Type 'symbol' does not satisfy the constraint 'object'.
|
|
5
|
+
const _sym_to_hash = new Map();
|
|
9
6
|
const _hash_to_sym = new Map();
|
|
10
7
|
let _next_hash = MIN_SAFE_INTEGER;
|
|
11
8
|
const unusedHashes = [];
|
|
12
9
|
function _collectUnusedHashes() {
|
|
13
10
|
for (const [h, s] of _hash_to_sym) {
|
|
14
|
-
|
|
15
|
-
if (!newSymbol
|
|
16
|
-
|| !_sym_to_hash.has(newSymbol)) {
|
|
11
|
+
if (!_sym_to_hash.has(s)) {
|
|
17
12
|
_hash_to_sym.delete(h);
|
|
18
13
|
unusedHashes.push(h);
|
|
19
14
|
}
|
|
@@ -34,8 +29,7 @@ export function hashVarSym(s) {
|
|
|
34
29
|
throw new Error("ran out of IR hashes");
|
|
35
30
|
const result_hash = unusedHashes.shift() ?? _next_hash++;
|
|
36
31
|
_sym_to_hash.set(s, result_hash);
|
|
37
|
-
|
|
38
|
-
_hash_to_sym.set(result_hash, new WeakRef(s));
|
|
32
|
+
_hash_to_sym.set(result_hash, s);
|
|
39
33
|
return fromHex((BigInt(result_hash) + BigInt(MAX_SAFE_INTEGER))
|
|
40
34
|
.toString(16)
|
|
41
35
|
.padStart(16, "0"));
|
package/package.json
CHANGED