mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Optimize Everything
and Nothing
label selectors
Currently each call makes 1 small alloc. This is not much, but it adds up when this is called millions of times. This simple change just moves to using a shared struct between everything. This is safe as each operation on the Selector is not doing mutations.
This commit is contained in:
parent
299e65cdc5
commit
ca414d707a
@ -74,9 +74,11 @@ type Selector interface {
|
||||
RequiresExactMatch(label string) (value string, found bool)
|
||||
}
|
||||
|
||||
var everythingSelector Selector = internalSelector{}
|
||||
|
||||
// Everything returns a selector that matches all labels.
|
||||
func Everything() Selector {
|
||||
return internalSelector{}
|
||||
return everythingSelector
|
||||
}
|
||||
|
||||
type nothingSelector struct{}
|
||||
@ -91,9 +93,11 @@ func (n nothingSelector) RequiresExactMatch(label string) (value string, found b
|
||||
return "", false
|
||||
}
|
||||
|
||||
var internalNothingSelector Selector = nothingSelector{}
|
||||
|
||||
// Nothing returns a selector that matches no labels
|
||||
func Nothing() Selector {
|
||||
return nothingSelector{}
|
||||
return internalNothingSelector
|
||||
}
|
||||
|
||||
// NewSelector returns a nil selector
|
||||
|
Loading…
Reference in New Issue
Block a user