mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +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)
|
RequiresExactMatch(label string) (value string, found bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var everythingSelector Selector = internalSelector{}
|
||||||
|
|
||||||
// Everything returns a selector that matches all labels.
|
// Everything returns a selector that matches all labels.
|
||||||
func Everything() Selector {
|
func Everything() Selector {
|
||||||
return internalSelector{}
|
return everythingSelector
|
||||||
}
|
}
|
||||||
|
|
||||||
type nothingSelector struct{}
|
type nothingSelector struct{}
|
||||||
@ -91,9 +93,11 @@ func (n nothingSelector) RequiresExactMatch(label string) (value string, found b
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var internalNothingSelector Selector = nothingSelector{}
|
||||||
|
|
||||||
// Nothing returns a selector that matches no labels
|
// Nothing returns a selector that matches no labels
|
||||||
func Nothing() Selector {
|
func Nothing() Selector {
|
||||||
return nothingSelector{}
|
return internalNothingSelector
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSelector returns a nil selector
|
// NewSelector returns a nil selector
|
||||||
|
Loading…
Reference in New Issue
Block a user