Commit 6200614
committed
revert(prefix-source): drop buffer()/buffers() caching — unsafe with mutable child
PrefixSource wraps an arbitrary Source. ReplaceSource (.replace,
.insert), ConcatSource (.add), and CompatSource over a mutable
SourceLike all break the immutability assumption. source() reads the
child on every call, so caching the derived buffer would silently go
stale after a child mutation:
const inner = new ReplaceSource(new RawSource("hello world"));
const ps = new PrefixSource("> ", inner);
ps.buffer(); // populates cache: "> hello world"
inner.replace(6, 10, "you");
ps.source(); // "> hello you" -- correct
ps.buffer(); // "> hello world" -- STALE (with caching)
RawSource / OriginalSource / SourceMapSource can cache safely because
they own their value. PrefixSource doesn't have that invariant. The
amortized 10x speedup wasn't worth a correctness regression.
Adds a regression test that calls source/buffer/buffers, mutates the
child, and asserts all three reflect the new state.
If a caller wants the speedup, wrap the PrefixSource in CachedSource —
that's the documented opt-in cache.
https://claude.ai/code/session_01EHhGq9PRFRGefVtwwasCqZ1 parent 0ec6dbd commit 6200614
2 files changed
Lines changed: 47 additions & 59 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 12 | | |
16 | 13 | | |
17 | 14 | | |
| |||
46 | 43 | | |
47 | 44 | | |
48 | 45 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | 46 | | |
60 | 47 | | |
61 | 48 | | |
| |||
75 | 62 | | |
76 | 63 | | |
77 | 64 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
95 | 72 | | |
96 | 73 | | |
97 | 74 | | |
98 | 75 | | |
99 | | - | |
| 76 | + | |
| 77 | + | |
100 | 78 | | |
101 | 79 | | |
102 | 80 | | |
103 | | - | |
104 | 81 | | |
105 | | - | |
106 | | - | |
107 | 82 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 83 | + | |
131 | 84 | | |
132 | | - | |
133 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
134 | 103 | | |
135 | 104 | | |
136 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
210 | 211 | | |
211 | 212 | | |
212 | 213 | | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
213 | 232 | | |
0 commit comments