History

Less allocations in expandRangeTable()

Fixes #44

Gregory Petrosyan committed 3 years ago

Commit 0922c261 parent c7f1a381 file · +10 −2Browse files

Unified · Split

strings.go+10−2
@@ -360,7 +360,15 @@ func expandRangeTable(t *unicode.RangeTable, key any) []rune { · 359 unmodified lines
360360 return cached.([]rune)
361361 }
362362
363− var ret []rune
363+ n := 0
364+ for _, r := range t.R16 {
365+ n += int(r.Hi-r.Lo)/int(r.Stride) + 1
366+ }
367+ for _, r := range t.R32 {
368+ n += int(r.Hi-r.Lo)/int(r.Stride) + 1
369+ }
370+
371+ ret := make([]rune, 0, n)
364372 for _, r := range t.R16 {
365373 for i := uint32(r.Lo); i <= uint32(r.Hi); i += uint32(r.Stride) {
366374 ret = append(ret, rune(i))
@@ -416,7 +424,7 @@ func charClassGen(re *syntax.Regexp) *Generator[rune] { · 49 unmodified lines
416424 return cached.(*Generator[rune])
417425 }
418426
419− t := &unicode.RangeTable{}
427+ t := &unicode.RangeTable{R32: make([]unicode.Range32, 0, len(re.Rune)/2)}
420428 for i := 0; i < len(re.Rune); i += 2 {
421429 t.R32 = append(t.R32, unicode.Range32{
422430 Lo: uint32(re.Rune[i]),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t