Commit 0c0b871
committed
Viewer: thread encoding through backends, migrate to ArcSwap
- `FullLoadBackend` / `ByteSeekBackend` / `LineIndexBackend` gain `open_with_encoding(path, encoding)` and decode lines through `decode_line(bytes, encoding)`. ASCII-compatible encodings keep the SIMD `memchr` fast path; UTF-16 uses `NewlineScanner` with carry-byte state for chunked reads
- `LineIndexBackend::extend_to(&self, new_size, cancel) -> Self` and `ByteSeekBackend::extend_to(&self, new_size, cancel) -> Self` produce a fresh backend by value, leaving the original untouched (immutable-backend pattern)
- `ViewerSession.backend` becomes `Arc<ArcSwap<Box<dyn FileViewerBackend>>>` so the upgrade/rebuild threads can replace it without a write lock on the `get_lines` read path
- New `pending_grew: Mutex<Option<u64>>` on `ViewerSession`. The drain-and-swap-under-lock protocol runs in both the existing ByteSeek -> LineIndex upgrade thread and the new encoding-rebuild thread: drain pending_grew -> optional `extend_to(eof)` -> `ArcSwap::store` -> clear `upgrading` / `rebuilding`, all inside one `pending_grew` lock critical section
- `viewer_set_encoding` and `viewer_get_encoding_options` IPC commands, with `EncodingOptions` (current + detected + all choices). `same_byte_layout` predicate identifies the instant-swap path (UTF-8 <-> Windows-1252 family); other swaps snap to ByteSeek immediately and rebuild LineIndex in the background
- `ViewerOpenResult.encoding` so the FE can pre-select the detected encoding in the picker
- Tests: encoding-aware `get_lines` returns correctly decoded UTF-16 strings, `set_encoding` swaps the decoder on FullLoad and triggers a backend rebuild on large files. `test_append_during_encoding_rebuild_not_dropped` simulates a watcher Grew event via the new `test_only_push_pending_grew` hook and pins that the rebuild's drain-and-swap covers the queued EOF1 parent a227078 commit 0c0b871
12 files changed
Lines changed: 998 additions & 133 deletions
File tree
- apps/desktop
- src-tauri
- proptest-regressions/file_viewer
- src
- commands
- file_viewer
- src/lib/ipc
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
193 | 211 | | |
194 | 212 | | |
195 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
33 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
34 | 42 | | |
35 | 43 | | |
36 | 44 | | |
| |||
50 | 58 | | |
51 | 59 | | |
52 | 60 | | |
| 61 | + | |
53 | 62 | | |
54 | 63 | | |
55 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
56 | 83 | | |
57 | 84 | | |
58 | 85 | | |
| |||
84 | 111 | | |
85 | 112 | | |
86 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
87 | 122 | | |
88 | 123 | | |
89 | 124 | | |
| |||
117 | 152 | | |
118 | 153 | | |
119 | 154 | | |
120 | | - | |
| 155 | + | |
121 | 156 | | |
122 | 157 | | |
123 | 158 | | |
| |||
131 | 166 | | |
132 | 167 | | |
133 | 168 | | |
134 | | - | |
| 169 | + | |
135 | 170 | | |
136 | 171 | | |
137 | 172 | | |
138 | 173 | | |
139 | 174 | | |
140 | 175 | | |
141 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
142 | 247 | | |
143 | 248 | | |
144 | 249 | | |
| |||
260 | 365 | | |
261 | 366 | | |
262 | 367 | | |
263 | | - | |
| 368 | + | |
264 | 369 | | |
265 | 370 | | |
266 | 371 | | |
| |||
288 | 393 | | |
289 | 394 | | |
290 | 395 | | |
291 | | - | |
| 396 | + | |
292 | 397 | | |
293 | 398 | | |
294 | 399 | | |
| |||
0 commit comments