diff options
Diffstat (limited to 'vendor/github.com/peterh/liner/width.go')
-rw-r--r-- | vendor/github.com/peterh/liner/width.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/vendor/github.com/peterh/liner/width.go b/vendor/github.com/peterh/liner/width.go index d8984aae9..42e899983 100644 --- a/vendor/github.com/peterh/liner/width.go +++ b/vendor/github.com/peterh/liner/width.go @@ -25,6 +25,12 @@ var doubleWidth = []*unicode.RangeTable{ func countGlyphs(s []rune) int { n := 0 for _, r := range s { + // speed up the common case + if r < 127 { + n++ + continue + } + switch { case unicode.IsOneOf(zeroWidth, r): case unicode.IsOneOf(doubleWidth, r): @@ -39,6 +45,10 @@ func countGlyphs(s []rune) int { func countMultiLineGlyphs(s []rune, columns int, start int) int { n := start for _, r := range s { + if r < 127 { + n++ + continue + } switch { case unicode.IsOneOf(zeroWidth, r): case unicode.IsOneOf(doubleWidth, r): @@ -58,6 +68,11 @@ func countMultiLineGlyphs(s []rune, columns int, start int) int { func getPrefixGlyphs(s []rune, num int) []rune { p := 0 for n := 0; n < num && p < len(s); p++ { + // speed up the common case + if s[p] < 127 { + n++ + continue + } if !unicode.IsOneOf(zeroWidth, s[p]) { n++ } @@ -71,6 +86,11 @@ func getPrefixGlyphs(s []rune, num int) []rune { func getSuffixGlyphs(s []rune, num int) []rune { p := len(s) for n := 0; n < num && p > 0; p-- { + // speed up the common case + if s[p-1] < 127 { + n++ + continue + } if !unicode.IsOneOf(zeroWidth, s[p-1]) { n++ } |