@typeberry/convert 0.7.2 → 0.7.3-ffe481c

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.
Files changed (3) hide show
  1. package/index.js +45 -3
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -4558,6 +4558,46 @@ function measure(id) {
4558
4558
  const start = now();
4559
4559
  return () => `${id} took ${(now() - start).toFixed(2)}ms`;
4560
4560
  }
4561
+ const BYTES_IN_MB = (/* unused pure expression or super */ null && (1024 * 1024));
4562
+ const toMb = (bytes) => (bytes / BYTES_IN_MB).toFixed(1);
4563
+ const signedMb = (bytes) => `${bytes >= 0 ? "+" : "-"}${toMb(bytes)}`;
4564
+ /** Raw process memory usage, or `null` in environments without `process` (e.g. browser). */
4565
+ function rawMemoryUsage() {
4566
+ if (isBrowser() || typeof process.memoryUsage !== "function") {
4567
+ return null;
4568
+ }
4569
+ return process.memoryUsage();
4570
+ }
4571
+ /**
4572
+ * Format current process memory usage as a human readable string.
4573
+ *
4574
+ * Returns an empty string in the browser where `process.memoryUsage` is unavailable.
4575
+ *
4576
+ * `arrayBuffers` should allow tracking WASM memory, since every instance backs its
4577
+ * memory with `ArrayBuffer`.
4578
+ */
4579
+ function memoryUsage() {
4580
+ const m = rawMemoryUsage();
4581
+ if (m === null) {
4582
+ return "";
4583
+ }
4584
+ return `rss=${toMb(m.rss)}MB heap=${toMb(m.heapUsed)}/${toMb(m.heapTotal)}MB external=${toMb(m.external)}MB arrayBuffers=${toMb(m.arrayBuffers)}MB`;
4585
+ }
4586
+ /** Create a stateful memory usage reporter. */
4587
+ function memoryTracker() {
4588
+ let prev = null;
4589
+ return () => {
4590
+ const m = rawMemoryUsage();
4591
+ if (m === null) {
4592
+ return "";
4593
+ }
4594
+ const delta = prev === null
4595
+ ? ""
4596
+ : ` (Δrss=${signedMb(m.rss - prev.rss)}MB ΔarrayBuffers=${signedMb(m.arrayBuffers - prev.arrayBuffers)}MB)`;
4597
+ prev = m;
4598
+ return `${memoryUsage()}${delta}`;
4599
+ };
4600
+ }
4561
4601
  /** A class that adds `toString` method that prints all properties of an object. */
4562
4602
  class WithDebug {
4563
4603
  toString() {
@@ -4626,7 +4666,7 @@ function seeThrough(v) {
4626
4666
  }
4627
4667
 
4628
4668
  ;// CONCATENATED MODULE: ./packages/core/utils/package.json
4629
- const package_namespaceObject = {"rE":"0.7.2"};
4669
+ const package_namespaceObject = /*#__PURE__*/JSON.parse('{"rE":"0.7.3-ffe481c"}');
4630
4670
  ;// CONCATENATED MODULE: ./packages/core/utils/result.ts
4631
4671
 
4632
4672
  /**
@@ -5441,7 +5481,8 @@ function numbers_u32AsLeBytes(value) {
5441
5481
  */
5442
5482
  function leBytesAsU32(uint8Array) {
5443
5483
  check `${uint8Array.length === 4} Input must be a Uint8Array of length 4`;
5444
- return asTypedNumber(uint8Array[0] | (uint8Array[1] << 8) | (uint8Array[2] << 16) | (uint8Array[3] << 24));
5484
+ // >>> 0 is needed to avoid changing sign of the number (the `<< 24` produces a signed int32)
5485
+ return asTypedNumber((uint8Array[0] | (uint8Array[1] << 8) | (uint8Array[2] << 16) | (uint8Array[3] << 24)) >>> 0);
5445
5486
  }
5446
5487
  /** Get the smallest value between U64 a and values given as input parameters. */
5447
5488
  const minU64 = (a, ...values) => values.reduce((min, value) => (value > min ? min : value), a);
@@ -17369,7 +17410,8 @@ function memory_utils_getPageNumber(address) {
17369
17410
  return page_utils_tryAsPageNumber(address >>> memory_consts_PAGE_SIZE_SHIFT);
17370
17411
  }
17371
17412
  function memory_utils_getStartPageIndex(address) {
17372
- return memory_index_tryAsMemoryIndex((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT);
17413
+ // >>> 0 is needed to avoid changing sign of the number
17414
+ return memory_index_tryAsMemoryIndex(((address >>> memory_consts_PAGE_SIZE_SHIFT) << memory_consts_PAGE_SIZE_SHIFT) >>> 0);
17373
17415
  }
17374
17416
  function getStartPageIndexFromPageNumber(pageNumber) {
17375
17417
  // >>> 0 is needed to avoid changing sign of the number