Skip to content

Commit 5237eff

Browse files
Parse and wrap ansi() codes without per-code allocations (#55)
* Parse and wrap ansi() codes without per-code allocations AnsiCodeParser reads codes in place (no iterator, StringBuilder or per-token strings) and shares palette colour instances. MarkupSet caches one-layer sets and Append results, and compares by reference first. MarkupText skips the normalising copy when runs are already normal. AnsiStyle equality/hash use one bit field; AnsiMarkup caches its hash. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HxaBeF4BjQBGHyZCqibsLX * Narrow the parser's allocation claim to palette colours Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HxaBeF4BjQBGHyZCqibsLX --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent b47d2c1 commit 5237eff

9 files changed

Lines changed: 389 additions & 152 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4444

4545
### Changed
4646

47+
- **`ansi()` codes parse and wrap faster.** `AnsiCodeParser.Parse` reads the codes in place and shares
48+
its palette colours, so for letter and xterm codes the markup is its only allocation (`hr`: 139 ns and 312 B before, 54 ns and
49+
88 B after). Wrapping text in a style seen before reuses its `MarkupSet`, and wrapping styled text
50+
again reuses what that pair made last time; `MarkupText` keeps runs that are already in normal form
51+
instead of copying them. `MarkupText.Wrap(ansi, plain text)` went from 351 ns and 640 B to 154 ns and
52+
208 B, and wrapping it again from 552 ns to 246 ns. `AnsiStyle` compares and hashes its switches as
53+
one bit field, and `AnsiMarkup` keeps its hash.
4754
- **A picture is one `ImageMarkup`, laid out or inline.** `PictureCellsMarkup` is gone: a figure's rows
4855
carry its `ImageMarkup` with `Row` (a `PictureRow`: which row, how many, how many cells wide), and the
4956
serialiser keeps it. MXP, Pueblo, HTML and BBCode write a picture's element once

0 commit comments

Comments
 (0)