@miaskiewicz/turbo-dom 0.1.38 → 0.1.40

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.38",
3
+ "version": "0.1.40",
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",
@@ -240,8 +240,13 @@ export class Node extends EventTarget {
240
240
  }
241
241
 
242
242
  get textContent() {
243
+ const kids = this.__children();
244
+ // hot leaf case (RTL getByText reads textContent on every element): a single
245
+ // text child → return its data directly, skipping the iterator + concat.
246
+ if (kids.length === 1 && kids[0].nodeType === TEXT_NODE) return kids[0].data;
243
247
  let s = '';
244
- for (const c of this.__children()) {
248
+ for (let i = 0; i < kids.length; i++) {
249
+ const c = kids[i];
245
250
  if (c.nodeType === TEXT_NODE) s += c.data;
246
251
  else if (c.nodeType === ELEMENT_NODE || c.nodeType === DOCUMENT_FRAGMENT_NODE) s += c.textContent;
247
252
  }
@@ -23,11 +23,14 @@ export * from './dom.mjs';
23
23
  // native parse + boundary marshaling entirely. Bounded (fixtures are few).
24
24
  const __parseCache = new Map();
25
25
  const __PARSE_CACHE_MAX = 64;
26
+ let __parseCacheMRU; // last (most-recently-used) key — skip the LRU re-insert when unchanged
26
27
  function parseBufferCached(html) {
27
28
  const hit = __parseCache.get(html);
28
29
  if (hit !== undefined) {
29
- // LRU bump: re-insert so this entry is now most-recently-used (Map keeps order)
30
- __parseCache.delete(html); __parseCache.set(html, hit);
30
+ // LRU bump: re-insert so this entry is most-recently-used (Map keeps order).
31
+ // Skip the delete+set entirely when this key is ALREADY the MRU — the common
32
+ // case for a suite that reuses one shell HTML across every file.
33
+ if (html !== __parseCacheMRU) { __parseCache.delete(html); __parseCache.set(html, hit); __parseCacheMRU = html; }
31
34
  return hit;
32
35
  }
33
36
  const soa = native.parseBuffer(html);
@@ -35,6 +38,7 @@ function parseBufferCached(html) {
35
38
  // shells should keep its hot fixtures warm, not thrash every one cold on overflow.
36
39
  if (__parseCache.size >= __PARSE_CACHE_MAX) __parseCache.delete(__parseCache.keys().next().value);
37
40
  __parseCache.set(html, soa);
41
+ __parseCacheMRU = html;
38
42
  return soa;
39
43
  }
40
44