Repository navigation
text: skip escape code parsing when only measuring or trimming - #448
Open
TheNetherWatcher wants to merge 1 commit into
Open
TheNetherWatcher wants to merge 1 commit into
TheNetherWatcher wants to merge 1 commit into
Conversation
LongestLineLen, StringWidthWithoutEscSequences and Trim only need to know where escape sequences start and end, but every completed sequence went through ParseSeq (map, split, replace, string copy). Add an unexported skipParse flag so these callers only track sequence boundaries. Also return the width of ASCII runes directly in RuneWidth instead of going through the runewidth table lookup.
|
Coverage Report for CI Build 42262909460Coverage remained the same at 100.0%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Proposed Changes
LongestLineLen,StringWidthWithoutEscSequencesandTrimonly need to know where escape sequences start and end, but each completed sequence also went throughParseSeq(map,strings.Split,strings.Replace, string copy). An unexportedskipParseflag onEscSeqParserlets these callers track boundaries only.tablecallsLongestLineLenonce per cell and the width/trim helpers per line, andprogresscalls them on every render.RuneWidthreturns the width of ASCII runes directly (1 for printable, 0 for control) instead of going through the runewidth lookup. A test checks all 128 ASCII runes againstrunewidthwithEastAsianWidthon and off.LongestLineLenandTrimbenchmarks next to the existing width one, and a test that askipParseparser reports the sameInSequence()state as a full one, byte by byte, for CSI, 256-colour, OSC 8 (BEL and ST), unterminated and oversized sequences.Benchmarks (Apple M4 Pro,
benchstat, n=10):I also compared the old and new versions of the three functions on 300k random strings (colour codes, OSC 8 links, malformed and oversized sequences, CJK, random trim widths): identical output.