Merge pull request #4291 from greatroar/widechars

ui/termstatus: Optimize Truncate
This commit is contained in:
Michael Eischer
2023-04-14 22:48:34 +02:00
committed by GitHub
2 changed files with 24 additions and 11 deletions

View File

@@ -79,11 +79,15 @@ func BenchmarkTruncateASCII(b *testing.B) {
func BenchmarkTruncateUnicode(b *testing.B) {
s := "Hello World or Καλημέρα κόσμε or こんにちは 世界"
w := 0
for _, r := range s {
for i := 0; i < len(s); {
w++
if wideRune(r) {
wide, utfsize := wideRune(s[i:])
if wide {
w++
}
i += int(utfsize)
}
b.ResetTimer()
benchmarkTruncate(b, s, w-1)
}