From 6237ab2c3155ed4c4fa064d1f0cb4f81eda10be1 Mon Sep 17 00:00:00 2001 From: Ilya Tocar Date: Tue, 12 Sep 2017 14:23:09 -0500 Subject: [PATCH] unicode/utf8: make FullRune inlinable MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This has same readability and allows to inline FullRune for massive performance gain: FullASCIIRune-6 4.36ns ± 0% 1.25ns ± 0% -71.33% (p=0.000 n=8+10) FullJapaneseRune-6 4.70ns ± 0% 1.42ns ± 1% -69.68% (p=0.000 n=9+10) Change-Id: I95edd6292417a28aac244e40afb713596a087d93 Reviewed-on: https://go-review.googlesource.com/63332 Run-TryBot: Ilya Tocar TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí --- src/unicode/utf8/utf8.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/unicode/utf8/utf8.go b/src/unicode/utf8/utf8.go index 6ccd464373..db845ab2f2 100644 --- a/src/unicode/utf8/utf8.go +++ b/src/unicode/utf8/utf8.go @@ -110,12 +110,10 @@ func FullRune(p []byte) bool { } // Must be short or invalid. accept := acceptRanges[x>>4] - if n > 1 { - if c := p[1]; c < accept.lo || accept.hi < c { - return true - } else if n > 2 && (p[2] < locb || hicb < p[2]) { - return true - } + if n > 1 && (p[1] < accept.lo || accept.hi < p[1]) { + return true + } else if n > 2 && (p[2] < locb || hicb < p[2]) { + return true } return false } @@ -132,12 +130,10 @@ func FullRuneInString(s string) bool { } // Must be short or invalid. accept := acceptRanges[x>>4] - if n > 1 { - if c := s[1]; c < accept.lo || accept.hi < c { - return true - } else if n > 2 && (s[2] < locb || hicb < s[2]) { - return true - } + if n > 1 && (s[1] < accept.lo || accept.hi < s[1]) { + return true + } else if n > 2 && (s[2] < locb || hicb < s[2]) { + return true } return false } -- 2.50.0