Skip to content

Commit 9f3fa23

Browse files
fix(css): cover the take paths and shorten the store comments
`take` and `takeRetractable` move the epoch too, so each gets a case asserting the store holds nothing afterwards; both fail without the release. The constructor's store comment goes to the two lines `lib/` allows, and `_moveEpoch`'s description drops the counterfactual.
1 parent 2a7de52 commit 9f3fa23

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎lib/util/SourceProcessor.js‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ class PrintContext {
261261
/** @type {NodePrinter<TPath, TNode, TPrintOptions>} */
262262
this._printer = printer;
263263
// Printed text by node handle, in two columns rather than one `Map`: the
264-
// handles are dense integers, and a stylesheet prints ~300k nodes through
265-
// a store `_moveEpoch` keeps down to the few dozen live at once.
264+
// handles are dense integers, and `_moveEpoch` keeps the live set small.
266265
/** @type {string[]} each finished node's printed text */
267266
this._storeText = [];
268267
/** @type {Int32Array} the epoch each slot was written in */
@@ -432,10 +431,9 @@ class PrintContext {
432431
}
433432

434433
/**
435-
* Move the epoch on, and let go of the text every slot written under the old
436-
* one holds. Only the range actually written is walked, so the whole run
437-
* clears as many slots as it wrote — the O(1) per node the epoch is for,
438-
* where clearing the column by its length would be O(nodes) each time.
434+
* Move the epoch on and release the text every slot written under the old one
435+
* holds. Only the range actually written is walked, so the drop stays O(1)
436+
* per node.
439437
* @returns {void}
440438
*/
441439
_moveEpoch() {

‎test/SourceProcessor.unittest.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ describe("SourceProcessor", () => {
5858
expect(held(context)).toBe(8);
5959
});
6060

61+
it("lets go of the text when a node is taken", () => {
62+
const context = new PrintContext({ mode: "minify" }, () =>
63+
"t".repeat(16)
64+
);
65+
context.printNode(1, null);
66+
expect(held(context)).toBe(16);
67+
context.take(1);
68+
expect(held(context)).toBe(0);
69+
});
70+
71+
it("lets go of the text when a retractable node is taken", () => {
72+
const context = new PrintContext({ mode: "minify" }, () =>
73+
"r".repeat(16)
74+
);
75+
context.printNode(1, null);
76+
expect(held(context)).toBe(16);
77+
context.takeRetractable(1);
78+
expect(held(context)).toBe(0);
79+
});
80+
6181
it("answers for a node printed since the drop, and no earlier one", () => {
6282
const context = new PrintContext({ mode: "minify" }, () => "z");
6383
context.printNode(1, null);

0 commit comments

Comments
 (0)