Use NextLabel in compressionLenHelper

This avoids the allocation of Split and should have slightly better
performance.
This commit is contained in:
Tom Thorogood 2018-11-26 12:02:04 +10:30
parent 3b3a5b7c6a
commit 8e6e188a87
No known key found for this signature in database
GPG Key ID: 86C63CDA416C6D2F
1 changed files with 3 additions and 5 deletions

8
msg.go
View File

@ -985,11 +985,9 @@ func compressionLenHelper(c map[string]int, s string, currentLen int) int {
return 0
}
initLen := currentLen
pref := ""
prev := s
lbs := Split(s)
for j := 0; j < len(lbs); j++ {
pref = s[lbs[j]:]
for off, end := 0, false; !end; off, end = NextLabel(s, off) {
pref := s[off:]
currentLen += len(prev) - len(pref)
prev = pref
if _, ok := c[pref]; !ok {
@ -999,7 +997,7 @@ func compressionLenHelper(c map[string]int, s string, currentLen int) int {
}
} else {
added := currentLen - initLen
if j > 0 {
if off > 0 {
// We added a new PTR
added += 2
}