diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-06-22 13:34:15 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-23 13:10:48 +0200 |
commit | 26132cf5bdae7ec81e9a0708c722ad2a9cf0c2cf (patch) | |
tree | b27de3b227276cf54d39238e8162b79eb029567e /test | |
parent | a67eda39a56440f54be7fbb43974fa7a966bce53 (diff) |
Use utils.StringWidth to optimize rendering performance
runewidth.StringWidth is an expensive call, even if the input string is pure
ASCII. Improve this by providing a wrapper that short-circuits the call to len
if the input is ASCII.
Benchmark results show that for non-ASCII strings it makes no noticable
difference, but for ASCII strings it provides a more than 200x speedup.
BenchmarkStringWidthAsciiOriginal-10 718135 1637 ns/op
BenchmarkStringWidthAsciiOptimized-10 159197538 7.545 ns/op
BenchmarkStringWidthNonAsciiOriginal-10 486290 2391 ns/op
BenchmarkStringWidthNonAsciiOptimized-10 502286 2383 ns/op
Diffstat (limited to 'test')
0 files changed, 0 insertions, 0 deletions