@@ -984,13 +984,13 @@ func (re *Regexp) FindAll(b []byte, n int) [][]byte {
984
984
if n < 0 {
985
985
n = len (b ) + 1
986
986
}
987
- result := make ( [][]byte , 0 , startSize )
987
+ var result [][]byte
988
988
re .allMatches ("" , b , n , func (match []int ) {
989
+ if result == nil {
990
+ result = make ([][]byte , 0 , startSize )
991
+ }
989
992
result = append (result , b [match [0 ]:match [1 ]])
990
993
})
991
- if len (result ) == 0 {
992
- return nil
993
- }
994
994
return result
995
995
}
996
996
@@ -1002,13 +1002,13 @@ func (re *Regexp) FindAllIndex(b []byte, n int) [][]int {
1002
1002
if n < 0 {
1003
1003
n = len (b ) + 1
1004
1004
}
1005
- result := make ( [][]int , 0 , startSize )
1005
+ var result [][]int
1006
1006
re .allMatches ("" , b , n , func (match []int ) {
1007
+ if result == nil {
1008
+ result = make ([][]int , 0 , startSize )
1009
+ }
1007
1010
result = append (result , match [0 :2 ])
1008
1011
})
1009
- if len (result ) == 0 {
1010
- return nil
1011
- }
1012
1012
return result
1013
1013
}
1014
1014
@@ -1020,13 +1020,13 @@ func (re *Regexp) FindAllString(s string, n int) []string {
1020
1020
if n < 0 {
1021
1021
n = len (s ) + 1
1022
1022
}
1023
- result := make ( []string , 0 , startSize )
1023
+ var result []string
1024
1024
re .allMatches (s , nil , n , func (match []int ) {
1025
+ if result == nil {
1026
+ result = make ([]string , 0 , startSize )
1027
+ }
1025
1028
result = append (result , s [match [0 ]:match [1 ]])
1026
1029
})
1027
- if len (result ) == 0 {
1028
- return nil
1029
- }
1030
1030
return result
1031
1031
}
1032
1032
@@ -1038,13 +1038,13 @@ func (re *Regexp) FindAllStringIndex(s string, n int) [][]int {
1038
1038
if n < 0 {
1039
1039
n = len (s ) + 1
1040
1040
}
1041
- result := make ( [][]int , 0 , startSize )
1041
+ var result [][]int
1042
1042
re .allMatches (s , nil , n , func (match []int ) {
1043
+ if result == nil {
1044
+ result = make ([][]int , 0 , startSize )
1045
+ }
1043
1046
result = append (result , match [0 :2 ])
1044
1047
})
1045
- if len (result ) == 0 {
1046
- return nil
1047
- }
1048
1048
return result
1049
1049
}
1050
1050
@@ -1056,8 +1056,11 @@ func (re *Regexp) FindAllSubmatch(b []byte, n int) [][][]byte {
1056
1056
if n < 0 {
1057
1057
n = len (b ) + 1
1058
1058
}
1059
- result := make ( [][][]byte , 0 , startSize )
1059
+ var result [][][]byte
1060
1060
re .allMatches ("" , b , n , func (match []int ) {
1061
+ if result == nil {
1062
+ result = make ([][][]byte , 0 , startSize )
1063
+ }
1061
1064
slice := make ([][]byte , len (match )/ 2 )
1062
1065
for j := range slice {
1063
1066
if match [2 * j ] >= 0 {
@@ -1066,9 +1069,6 @@ func (re *Regexp) FindAllSubmatch(b []byte, n int) [][][]byte {
1066
1069
}
1067
1070
result = append (result , slice )
1068
1071
})
1069
- if len (result ) == 0 {
1070
- return nil
1071
- }
1072
1072
return result
1073
1073
}
1074
1074
@@ -1080,13 +1080,13 @@ func (re *Regexp) FindAllSubmatchIndex(b []byte, n int) [][]int {
1080
1080
if n < 0 {
1081
1081
n = len (b ) + 1
1082
1082
}
1083
- result := make ( [][]int , 0 , startSize )
1083
+ var result [][]int
1084
1084
re .allMatches ("" , b , n , func (match []int ) {
1085
+ if result == nil {
1086
+ result = make ([][]int , 0 , startSize )
1087
+ }
1085
1088
result = append (result , match )
1086
1089
})
1087
- if len (result ) == 0 {
1088
- return nil
1089
- }
1090
1090
return result
1091
1091
}
1092
1092
@@ -1098,8 +1098,11 @@ func (re *Regexp) FindAllStringSubmatch(s string, n int) [][]string {
1098
1098
if n < 0 {
1099
1099
n = len (s ) + 1
1100
1100
}
1101
- result := make ( [][]string , 0 , startSize )
1101
+ var result [][]string
1102
1102
re .allMatches (s , nil , n , func (match []int ) {
1103
+ if result == nil {
1104
+ result = make ([][]string , 0 , startSize )
1105
+ }
1103
1106
slice := make ([]string , len (match )/ 2 )
1104
1107
for j := range slice {
1105
1108
if match [2 * j ] >= 0 {
@@ -1108,9 +1111,6 @@ func (re *Regexp) FindAllStringSubmatch(s string, n int) [][]string {
1108
1111
}
1109
1112
result = append (result , slice )
1110
1113
})
1111
- if len (result ) == 0 {
1112
- return nil
1113
- }
1114
1114
return result
1115
1115
}
1116
1116
@@ -1123,13 +1123,13 @@ func (re *Regexp) FindAllStringSubmatchIndex(s string, n int) [][]int {
1123
1123
if n < 0 {
1124
1124
n = len (s ) + 1
1125
1125
}
1126
- result := make ( [][]int , 0 , startSize )
1126
+ var result [][]int
1127
1127
re .allMatches (s , nil , n , func (match []int ) {
1128
+ if result == nil {
1129
+ result = make ([][]int , 0 , startSize )
1130
+ }
1128
1131
result = append (result , match )
1129
1132
})
1130
- if len (result ) == 0 {
1131
- return nil
1132
- }
1133
1133
return result
1134
1134
}
1135
1135
0 commit comments