@flighthq/textshaper 0.3.0-next.1032.e2b99fc → 0.3.0-next.1220.6982c21

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.
@@ -1 +1 @@
1
- {"version":3,"file":"textShaperPool.d.ts","sourceRoot":"","sources":["../src/textShaperPool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAU1D,wBAAgB,gBAAgB,IAAI,SAAS,CAG5C;AAID,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAIrD"}
1
+ {"version":3,"file":"textShaperPool.d.ts","sourceRoot":"","sources":["../src/textShaperPool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAU1D,wBAAgB,gBAAgB,IAAI,SAAS,CAK5C;AASD,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAMrD"}
@@ -6,19 +6,32 @@ import { createShapedRun } from './textShaperRun';
6
6
  // The returned run is in an unspecified state — always populate it before use (e.g. via
7
7
  // `shapeTextRunInto`).
8
8
  export function acquireShapedRun() {
9
- if (_pool.length > 0)
10
- return _pool.pop();
11
- return createShapedRun();
9
+ const pooled = _pool.pop();
10
+ if (pooled === undefined)
11
+ return createShapedRun();
12
+ _pooled.delete(pooled);
13
+ return pooled;
12
14
  }
13
15
  // Returns a ShapedRun to the pool. The run must not be used after release. Pairs with
14
16
  // `acquireShapedRun`. Runs released beyond the pool capacity are silently discarded (GC-collected).
17
+ //
18
+ // Releasing a run that is already pooled is ignored rather than honoured. Without that check the run
19
+ // sits in the pool twice, and the next two acquires hand the same object to two callers who then shape
20
+ // into one buffer -- corruption that surfaces as wrong glyphs far from its cause. Ignoring keeps the
21
+ // pool invariant (an entry appears at most once) intact whatever the caller does.
15
22
  export function releaseShapedRun(run) {
23
+ if (_pooled.has(run))
24
+ return;
16
25
  if (_pool.length < _POOL_MAX_SIZE) {
17
26
  _pool.push(run);
27
+ _pooled.add(run);
18
28
  }
19
29
  }
20
30
  // Maximum number of ShapedRuns to retain in the pool before discarding on release. Keeps
21
31
  // memory bounded in cases where burst shaping produces many runs.
22
32
  const _POOL_MAX_SIZE = 64;
23
33
  const _pool = [];
34
+ // Membership mirror for `_pool`, so the double-release check is O(1) rather than scanning the pool on
35
+ // every release. Weak so a run dropped past capacity stays collectable.
36
+ const _pooled = new WeakSet();
24
37
  //# sourceMappingURL=textShaperPool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"textShaperPool.js","sourceRoot":"","sources":["../src/textShaperPool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,mFAAmF;AACnF,oFAAoF;AACpF,0FAA0F;AAC1F,EAAE;AACF,wFAAwF;AACxF,uBAAuB;AACvB,MAAM,UAAU,gBAAgB;IAC9B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,EAAG,CAAC;IAC1C,OAAO,eAAe,EAAE,CAAC;AAC3B,CAAC;AAED,sFAAsF;AACtF,oGAAoG;AACpG,MAAM,UAAU,gBAAgB,CAAC,GAAc;IAC7C,IAAI,KAAK,CAAC,MAAM,GAAG,cAAc,EAAE,CAAC;QAClC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,yFAAyF;AACzF,kEAAkE;AAClE,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,KAAK,GAAgB,EAAE,CAAC"}
1
+ {"version":3,"file":"textShaperPool.js","sourceRoot":"","sources":["../src/textShaperPool.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,mFAAmF;AACnF,oFAAoF;AACpF,0FAA0F;AAC1F,EAAE;AACF,wFAAwF;AACxF,uBAAuB;AACvB,MAAM,UAAU,gBAAgB;IAC9B,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;IAC3B,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,eAAe,EAAE,CAAC;IACnD,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,sFAAsF;AACtF,oGAAoG;AACpG,EAAE;AACF,qGAAqG;AACrG,uGAAuG;AACvG,qGAAqG;AACrG,kFAAkF;AAClF,MAAM,UAAU,gBAAgB,CAAC,GAAc;IAC7C,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO;IAC7B,IAAI,KAAK,CAAC,MAAM,GAAG,cAAc,EAAE,CAAC;QAClC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;AACH,CAAC;AAED,yFAAyF;AACzF,kEAAkE;AAClE,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,KAAK,GAAgB,EAAE,CAAC;AAC9B,sGAAsG;AACtG,wEAAwE;AACxE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAa,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flighthq/textshaper",
3
- "version": "0.3.0-next.1032.e2b99fc",
3
+ "version": "0.3.0-next.1220.6982c21",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/flighthq/flight.git",
@@ -36,8 +36,8 @@
36
36
  "clean:dist": "tsx ../../scripts/clean-package-dist.ts"
37
37
  },
38
38
  "dependencies": {
39
- "@flighthq/signals": "0.3.0-next.1032.e2b99fc",
40
- "@flighthq/types": "0.3.0-next.1032.e2b99fc"
39
+ "@flighthq/signals": "0.3.0-next.1220.6982c21",
40
+ "@flighthq/types": "0.3.0-next.1220.6982c21"
41
41
  },
42
42
  "devDependencies": {
43
43
  "typescript": "^5.3.0"
@@ -33,4 +33,42 @@ describe('releaseShapedRun', () => {
33
33
  const run = acquireShapedRun();
34
34
  expect(() => releaseShapedRun(run)).not.toThrow();
35
35
  });
36
+
37
+ // A pool entry must appear at most once. Honouring a second release put the run in twice, so the
38
+ // next two acquires handed one object to two callers who then shaped into the same buffer -- the
39
+ // failure shows up as wrong glyphs somewhere else entirely.
40
+ it('ignores a second release of the same run, so two acquires stay distinct', () => {
41
+ const run = acquireShapedRun();
42
+ releaseShapedRun(run);
43
+ releaseShapedRun(run);
44
+
45
+ const first = acquireShapedRun();
46
+ const second = acquireShapedRun();
47
+
48
+ expect(first).not.toBe(second);
49
+ });
50
+
51
+ // The membership record has to be cleared on the way out, or a run legitimately re-released after a
52
+ // later acquire is mistaken for a double release and silently dropped from the pool.
53
+ it('accepts a release again after the run has been re-acquired', () => {
54
+ const run = acquireShapedRun();
55
+ releaseShapedRun(run);
56
+ const reacquired = acquireShapedRun();
57
+ expect(reacquired).toBe(run);
58
+
59
+ releaseShapedRun(reacquired);
60
+ expect(acquireShapedRun()).toBe(run);
61
+ });
62
+
63
+ it('keeps distinct runs distinct through an acquire-release cycle', () => {
64
+ const first = acquireShapedRun();
65
+ const second = acquireShapedRun();
66
+ releaseShapedRun(first);
67
+ releaseShapedRun(second);
68
+
69
+ const a = acquireShapedRun();
70
+ const b = acquireShapedRun();
71
+
72
+ expect(a).not.toBe(b);
73
+ });
36
74
  });