@@ -508,10 +508,9 @@ func (re *Regexp) findAllSubmatch(alloc *allocation, bsrc []byte, src string, cs
508
508
509
509
var matches []int
510
510
accept := true
511
- readMatches (alloc , cs , matchArr .ptr , nmatch , func (match []int ) {
511
+ readMatches (alloc , cs , matchArr .ptr , nmatch , func (match []int ) bool {
512
512
if len (matches ) == 0 {
513
513
// First match, check if it's an empty match following a match, which we ignore.
514
- // TODO: Don't iterate further when ignoring.
515
514
if match [0 ] == match [1 ] && match [0 ] == prevMatchEnd {
516
515
accept = false
517
516
}
@@ -534,7 +533,12 @@ func (re *Regexp) findAllSubmatch(alloc *allocation, bsrc []byte, src string, cs
534
533
}
535
534
prevMatchEnd = match [1 ]
536
535
}
537
- matches = append (matches , match ... )
536
+ if accept {
537
+ matches = append (matches , match ... )
538
+ return true
539
+ } else {
540
+ return false
541
+ }
538
542
})
539
543
if accept {
540
544
deliver (matches )
@@ -564,8 +568,9 @@ func (re *Regexp) FindSubmatch(b []byte) [][]byte {
564
568
565
569
var matches [][]byte
566
570
567
- re .findSubmatch (& alloc , cs , func (match []int ) {
571
+ re .findSubmatch (& alloc , cs , func (match []int ) bool {
568
572
matches = append (matches , matchedBytes (b , match ))
573
+ return true
569
574
})
570
575
571
576
return matches
@@ -584,8 +589,9 @@ func (re *Regexp) FindSubmatchIndex(b []byte) []int {
584
589
585
590
var matches []int
586
591
587
- re .findSubmatch (& alloc , cs , func (match []int ) {
592
+ re .findSubmatch (& alloc , cs , func (match []int ) bool {
588
593
matches = append (matches , match ... )
594
+ return true
589
595
})
590
596
591
597
res := matches
@@ -601,8 +607,9 @@ func (re *Regexp) FindStringSubmatch(s string) []string {
601
607
602
608
var matches []string
603
609
604
- re .findSubmatch (& alloc , cs , func (match []int ) {
610
+ re .findSubmatch (& alloc , cs , func (match []int ) bool {
605
611
matches = append (matches , matchedString (s , match ))
612
+ return true
606
613
})
607
614
608
615
return matches
@@ -621,16 +628,17 @@ func (re *Regexp) FindStringSubmatchIndex(s string) []int {
621
628
622
629
var matches []int
623
630
624
- re .findSubmatch (& alloc , cs , func (match []int ) {
631
+ re .findSubmatch (& alloc , cs , func (match []int ) bool {
625
632
matches = append (matches , match ... )
633
+ return true
626
634
})
627
635
628
636
res := matches
629
637
runtime .KeepAlive (s )
630
638
return res
631
639
}
632
640
633
- func (re * Regexp ) findSubmatch (alloc * allocation , cs cString , deliver func (match []int )) {
641
+ func (re * Regexp ) findSubmatch (alloc * allocation , cs cString , deliver func (match []int ) bool ) {
634
642
numGroups := re .numMatches
635
643
matchArr := alloc .newCStringArray (numGroups )
636
644
defer matchArr .free ()
0 commit comments