diff options
Diffstat (limited to 'libgo/go/unicode/utf8/utf8.go')
-rw-r--r-- | libgo/go/unicode/utf8/utf8.go | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/libgo/go/unicode/utf8/utf8.go b/libgo/go/unicode/utf8/utf8.go index 9d35be6c065..6ccd4643738 100644 --- a/libgo/go/unicode/utf8/utf8.go +++ b/libgo/go/unicode/utf8/utf8.go @@ -347,6 +347,7 @@ func EncodeRune(p []byte, r rune) int { p[0] = byte(r) return 1 case i <= rune2Max: + _ = p[1] // eliminate bounds checks p[0] = t2 | byte(r>>6) p[1] = tx | byte(r)&maskx return 2 @@ -354,11 +355,13 @@ func EncodeRune(p []byte, r rune) int { r = RuneError fallthrough case i <= rune3Max: + _ = p[2] // eliminate bounds checks p[0] = t3 | byte(r>>12) p[1] = tx | byte(r>>6)&maskx p[2] = tx | byte(r)&maskx return 3 default: + _ = p[3] // eliminate bounds checks p[0] = t4 | byte(r>>18) p[1] = tx | byte(r>>12)&maskx p[2] = tx | byte(r>>6)&maskx @@ -513,12 +516,10 @@ func ValidString(s string) bool { // Code points that are out of range or a surrogate half are illegal. func ValidRune(r rune) bool { switch { - case r < 0: - return false - case surrogateMin <= r && r <= surrogateMax: - return false - case r > MaxRune: - return false + case 0 <= r && r < surrogateMin: + return true + case surrogateMax < r && r <= MaxRune: + return true } - return true + return false } |