@@ -41,8 +41,6 @@ var matchOps = map[MatchOp]struct{}{
41
41
MatchIsFalse : {},
42
42
}
43
43
44
- type valueRegexpCache []* regexp.Regexp
45
-
46
44
// CreateMatchExpression creates a new MatchExpression instance. Returns an
47
45
// error if validation fails.
48
46
func CreateMatchExpression (op MatchOp , values ... string ) (* MatchExpression , error ) {
@@ -70,8 +68,6 @@ func newMatchExpression(op MatchOp, values ...string) *MatchExpression {
70
68
71
69
// Validate validates the expression.
72
70
func (m * MatchExpression ) Validate () error {
73
- m .valueRe = nil
74
-
75
71
if _ , ok := matchOps [m .Op ]; ! ok {
76
72
return fmt .Errorf ("invalid Op %q" , m .Op )
77
73
}
@@ -105,13 +101,11 @@ func (m *MatchExpression) Validate() error {
105
101
if len (m .Value ) == 0 {
106
102
return fmt .Errorf ("value must be non-empty for Op %q" , m .Op )
107
103
}
108
- m .valueRe = make ([]* regexp.Regexp , len (m .Value ))
109
- for i , v := range m .Value {
110
- re , err := regexp .Compile (v )
104
+ for _ , v := range m .Value {
105
+ _ , err := regexp .Compile (v )
111
106
if err != nil {
112
107
return fmt .Errorf ("value must only contain valid regexps for Op %q (have %v)" , m .Op , m .Value )
113
108
}
114
- m .valueRe [i ] = re
115
109
}
116
110
default :
117
111
if len (m .Value ) == 0 {
@@ -171,18 +165,15 @@ func (m *MatchExpression) Match(valid bool, value interface{}) (bool, error) {
171
165
if len (m .Value ) == 0 {
172
166
return false , fmt .Errorf ("invalid expression, 'value' field must be non-empty for Op %q" , m .Op )
173
167
}
174
- if m .valueRe == nil {
175
- m .valueRe = make ([]* regexp.Regexp , len (m .Value ))
176
- for i , v := range m .Value {
177
- re , err := regexp .Compile (v )
178
- if err != nil {
179
- m .valueRe = nil
180
- return false , fmt .Errorf ("invalid expressiom, 'value' field must only contain valid regexps for Op %q (have %v)" , m .Op , m .Value )
181
- }
182
- m .valueRe [i ] = re
168
+ valueRe := make ([]* regexp.Regexp , len (m .Value ))
169
+ for i , v := range m .Value {
170
+ re , err := regexp .Compile (v )
171
+ if err != nil {
172
+ return false , fmt .Errorf ("invalid expressiom, 'value' field must only contain valid regexps for Op %q (have %v)" , m .Op , m .Value )
183
173
}
174
+ valueRe [i ] = re
184
175
}
185
- for _ , re := range m . valueRe {
176
+ for _ , re := range valueRe {
186
177
if re .MatchString (value ) {
187
178
return true , nil
188
179
}
@@ -490,23 +481,3 @@ func (m *MatchValue) UnmarshalJSON(data []byte) error {
490
481
491
482
return nil
492
483
}
493
-
494
- // DeepCopy supplements the auto-generated code
495
- func (in * valueRegexpCache ) DeepCopy () * valueRegexpCache {
496
- if in == nil {
497
- return nil
498
- }
499
- out := new (valueRegexpCache )
500
- in .DeepCopyInto (out )
501
- return out
502
- }
503
-
504
- // DeepCopyInto is a stub to augment the auto-generated code
505
- //
506
- //nolint:staticcheck // re.Copy is deprecated but we want to use it here
507
- func (in * valueRegexpCache ) DeepCopyInto (out * valueRegexpCache ) {
508
- * out = make (valueRegexpCache , len (* in ))
509
- for i , re := range * in {
510
- (* out )[i ] = re .Copy ()
511
- }
512
- }
0 commit comments