@miaskiewicz/turbo-dom 0.1.46 → 0.1.47

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miaskiewicz/turbo-dom",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
4
4
  "description": "Faster, more spec-correct DOM for test runners — native html5ever (Rust/WASM) parser + lazy copy-on-write DOM. A drop-in-style alternative to jsdom/happy-dom for vitest & jest.",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -5,7 +5,9 @@ const NS_SHORT = ['', 'svg', 'math'];
5
5
 
6
6
  // Inflate the packed byte blob into named typed-array views (zero-copy).
7
7
  // Mirrors the column order in lib.rs JsSoa::from. One ArrayBuffer, ~13 views.
8
- function unpack(soa) {
8
+ // Exported so the parse cache can unpack ONCE per HTML (the views are read-only
9
+ // over the shared immutable buffer) instead of re-unpacking per Document.
10
+ export function unpack(soa) {
9
11
  const u8 = soa.packed, ab = u8.buffer, base = u8.byteOffset, n = soa.n, m = soa.m;
10
12
  let off = base;
11
13
  const i32 = () => { const a = new Int32Array(ab, off, n); off += n * 4; return a; };
@@ -9,6 +9,7 @@
9
9
  import { createRequire } from 'node:module';
10
10
  import { Document } from './dom.mjs';
11
11
  import { createWindow } from './window.mjs';
12
+ import { unpack } from './buffer.mjs';
12
13
 
13
14
  const require = createRequire(import.meta.url);
14
15
  const native = require('../../index.js');
@@ -33,7 +34,11 @@ function parseBufferCached(html) {
33
34
  if (html !== __parseCacheMRU) { __parseCache.delete(html); __parseCache.set(html, hit); __parseCacheMRU = html; }
34
35
  return hit;
35
36
  }
36
- const soa = native.parseBuffer(html);
37
+ let soa = native.parseBuffer(html);
38
+ // Unpack the packed blob into typed-array views ONCE here, not per Document in
39
+ // every Buffer ctor — the views are read-only over the shared immutable buffer,
40
+ // so all Documents backed by this cached soa reuse them (no re-unpack per file).
41
+ if (soa.packed) soa = unpack(soa);
37
42
  // Evict the single oldest entry, not the whole cache — a suite with >64 distinct
38
43
  // shells should keep its hot fixtures warm, not thrash every one cold on overflow.
39
44
  if (__parseCache.size >= __PARSE_CACHE_MAX) __parseCache.delete(__parseCache.keys().next().value);