mirror of
https://github.com/golang/go
synced 2024-11-21 22:04:39 -07:00
exp/norm: performance improvements of quickSpan
- fixed performance bug that could lead to O(n^2) behavior - performance improvement for ASCII case R=r, r CC=golang-dev https://golang.org/cl/4956060
This commit is contained in:
parent
c7f6f9f318
commit
d5e24b6975
@ -198,12 +198,16 @@ func (f Form) QuickSpan(b []byte) int {
|
||||
func quickSpan(fd *formInfo, b []byte) int {
|
||||
var lastCC uint8
|
||||
var lastSegStart int
|
||||
i := 0
|
||||
var i, nc int
|
||||
for i < len(b) {
|
||||
if b[i] < utf8.RuneSelf {
|
||||
lastSegStart = i
|
||||
i++
|
||||
// Keep the loop tight for ASCII processing, as this is where
|
||||
// most of the time is spent for this case.
|
||||
for i++; i < len(b) && b[i] < utf8.RuneSelf; i++ {
|
||||
}
|
||||
lastSegStart = i - 1
|
||||
lastCC = 0
|
||||
nc = 0
|
||||
continue
|
||||
}
|
||||
info := fd.info(b[i:])
|
||||
@ -212,9 +216,6 @@ func quickSpan(fd *formInfo, b []byte) int {
|
||||
return len(b)
|
||||
}
|
||||
cc := info.ccc
|
||||
if lastCC > cc && cc != 0 {
|
||||
return lastSegStart
|
||||
}
|
||||
if fd.composing {
|
||||
if !info.flags.isYesC() {
|
||||
break
|
||||
@ -224,8 +225,20 @@ func quickSpan(fd *formInfo, b []byte) int {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !fd.composing && cc == 0 {
|
||||
if cc == 0 {
|
||||
lastSegStart = i
|
||||
nc = 0
|
||||
} else {
|
||||
if nc >= maxCombiningChars {
|
||||
lastSegStart = i
|
||||
lastCC = cc
|
||||
nc = 1
|
||||
} else {
|
||||
if lastCC > cc {
|
||||
return lastSegStart
|
||||
}
|
||||
nc++
|
||||
}
|
||||
}
|
||||
lastCC = cc
|
||||
i += int(info.size)
|
||||
|
@ -220,6 +220,11 @@ var quickSpanTests = []PositionTest{
|
||||
// incorrectly ordered combining characters
|
||||
{"\u0300\u0316", 0, ""},
|
||||
{"\u0300\u0316cd", 0, ""},
|
||||
// have a maximum number of combining characters.
|
||||
{strings.Repeat("\u035D", 30) + "\u035B", 62, ""},
|
||||
{"a" + strings.Repeat("\u035D", 30) + "\u035B", 63, ""},
|
||||
{"Ɵ" + strings.Repeat("\u035D", 30) + "\u035B", 64, ""},
|
||||
{"aa" + strings.Repeat("\u035D", 30) + "\u035B", 64, ""},
|
||||
}
|
||||
|
||||
var quickSpanNFDTests = []PositionTest{
|
||||
|
Loading…
Reference in New Issue
Block a user