mirror of
https://github.com/restic/restic.git
synced 2025-10-10 09:53:43 +00:00
Merge pull request #4291 from greatroar/widechars
ui/termstatus: Optimize Truncate
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user