aboutsummaryrefslogtreecommitdiff
path: root/src/unicode
diff options
context:
space:
mode:
Diffstat (limited to 'src/unicode')
-rw-r--r--src/unicode/utf8/utf8.go32
1 files changed, 4 insertions, 28 deletions
diff --git a/src/unicode/utf8/utf8.go b/src/unicode/utf8/utf8.go
index 9743b74258..180c008ed5 100644
--- a/src/unicode/utf8/utf8.go
+++ b/src/unicode/utf8/utf8.go
@@ -414,35 +414,11 @@ func appendRuneNonASCII(p []byte, r rune) []byte {
func RuneCount(p []byte) int {
np := len(p)
var n int
- for i := 0; i < np; {
- n++
- c := p[i]
- if c < RuneSelf {
- // ASCII fast path
- i++
- continue
- }
- x := first[c]
- if x == xx {
- i++ // invalid.
- continue
- }
- size := int(x & 7)
- if i+size > np {
- i++ // Short or invalid.
- continue
+ for ; n < np; n++ {
+ if c := p[n]; c >= RuneSelf {
+ // non-ASCII slow path
+ return n + RuneCountInString(string(p[n:]))
}
- accept := acceptRanges[x>>4]
- if c := p[i+1]; c < accept.lo || accept.hi < c {
- size = 1
- } else if size == 2 {
- } else if c := p[i+2]; c < locb || hicb < c {
- size = 1
- } else if size == 3 {
- } else if c := p[i+3]; c < locb || hicb < c {
- size = 1
- }
- i += size
}
return n
}