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
360 return cached.([]rune)360 return cached.([]rune)
361 }361 }
362 362
363 var ret []rune363 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)
364 for _, r := range t.R16 {372 for _, r := range t.R16 {
365 for i := uint32(r.Lo); i <= uint32(r.Hi); i += uint32(r.Stride) {373 for i := uint32(r.Lo); i <= uint32(r.Hi); i += uint32(r.Stride) {
366 ret = append(ret, rune(i))374 ret = append(ret, rune(i))
@@ -416,7 +424,7 @@ func charClassGen(re *syntax.Regexp) *Generator[rune] { · 49 unmodified lines
416 return cached.(*Generator[rune])424 return cached.(*Generator[rune])
417 }425 }
418 426
419 t := &unicode.RangeTable{}427 t := &unicode.RangeTable{R32: make([]unicode.Range32, 0, len(re.Rune)/2)}
420 for i := 0; i < len(re.Rune); i += 2 {428 for i := 0; i < len(re.Rune); i += 2 {
421 t.R32 = append(t.R32, unicode.Range32{429 t.R32 = append(t.R32, unicode.Range32{
422 Lo: uint32(re.Rune[i]),430 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