Skip to content

Commit 3ce5a1b

Browse files
authored
Merge pull request #1482 from marquiz/devel/api-cleanup-2
apis/nfd: drop the private regexp caching field
2 parents f0d3bce + 8d40524 commit 3ce5a1b

File tree

3 files changed

+9
-42
lines changed

3 files changed

+9
-42
lines changed

pkg/apis/nfd/v1alpha1/expression.go

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ var matchOps = map[MatchOp]struct{}{
4242
MatchIsFalse: {},
4343
}
4444

45-
type valueRegexpCache []*regexp.Regexp
46-
4745
// CreateMatchExpression creates a new MatchExpression instance. Returns an
4846
// error if validation fails.
4947
func CreateMatchExpression(op MatchOp, values ...string) (*MatchExpression, error) {
@@ -71,8 +69,6 @@ func newMatchExpression(op MatchOp, values ...string) *MatchExpression {
7169

7270
// Validate validates the expression.
7371
func (m *MatchExpression) Validate() error {
74-
m.valueRe = nil
75-
7672
if _, ok := matchOps[m.Op]; !ok {
7773
return fmt.Errorf("invalid Op %q", m.Op)
7874
}
@@ -106,13 +102,11 @@ func (m *MatchExpression) Validate() error {
106102
if len(m.Value) == 0 {
107103
return fmt.Errorf("value must be non-empty for Op %q", m.Op)
108104
}
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)
112107
if err != nil {
113108
return fmt.Errorf("value must only contain valid regexps for Op %q (have %v)", m.Op, m.Value)
114109
}
115-
m.valueRe[i] = re
116110
}
117111
default:
118112
if len(m.Value) == 0 {
@@ -172,18 +166,15 @@ func (m *MatchExpression) Match(valid bool, value interface{}) (bool, error) {
172166
if len(m.Value) == 0 {
173167
return false, fmt.Errorf("invalid expression, 'value' field must be non-empty for Op %q", m.Op)
174168
}
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)
184174
}
175+
valueRe[i] = re
185176
}
186-
for _, re := range m.valueRe {
177+
for _, re := range valueRe {
187178
if re.MatchString(value) {
188179
return true, nil
189180
}
@@ -488,23 +479,3 @@ func (m *MatchValue) UnmarshalJSON(data []byte) error {
488479

489480
return nil
490481
}
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-
}

pkg/apis/nfd/v1alpha1/types.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@ type MatchExpression struct {
226226
// In other cases Value should contain at least one element.
227227
// +optional
228228
Value MatchValue `json:"value,omitempty"`
229-
230-
// valueRe caches compiled regexps for "InRegexp" operator
231-
valueRe valueRegexpCache `json:"-"`
232229
}
233230

234231
// MatchOp is the match operator that is applied on values when evaluating a

pkg/apis/nfd/v1alpha1/zz_generated.deepcopy.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)