mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Merge pull request #112649 from howardjohn/set/optimize-everything-nothing
Optimize `Everything` and `Nothing` label selectors
This commit is contained in:
commit
bbe050dd01
@ -74,9 +74,12 @@ type Selector interface {
|
|||||||
RequiresExactMatch(label string) (value string, found bool)
|
RequiresExactMatch(label string) (value string, found bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sharing this saves 1 alloc per use; this is safe because it's immutable.
|
||||||
|
var sharedEverythingSelector 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 sharedEverythingSelector
|
||||||
}
|
}
|
||||||
|
|
||||||
type nothingSelector struct{}
|
type nothingSelector struct{}
|
||||||
@ -91,9 +94,12 @@ func (n nothingSelector) RequiresExactMatch(label string) (value string, found b
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sharing this saves 1 alloc per use; this is safe because it's immutable.
|
||||||
|
var sharedNothingSelector 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 sharedNothingSelector
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSelector returns a nil selector
|
// NewSelector returns a nil selector
|
||||||
|
Loading…
Reference in New Issue
Block a user