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