Skip to content

Commit 9e85d3a

Browse files
Merge pull request #112649 from howardjohn/set/optimize-everything-nothing
Optimize `Everything` and `Nothing` label selectors Kubernetes-commit: bbe050dd01fbf60661b8b8d8f750a0dc675dcbb9
2 parents b03a432 + 88a1448 commit 9e85d3a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/labels/selector.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ type Selector interface {
7474
RequiresExactMatch(label string) (value string, found bool)
7575
}
7676

77+
// Sharing this saves 1 alloc per use; this is safe because it's immutable.
78+
var sharedEverythingSelector Selector = internalSelector{}
79+
7780
// Everything returns a selector that matches all labels.
7881
func Everything() Selector {
79-
return internalSelector{}
82+
return sharedEverythingSelector
8083
}
8184

8285
type nothingSelector struct{}
@@ -91,9 +94,12 @@ func (n nothingSelector) RequiresExactMatch(label string) (value string, found b
9194
return "", false
9295
}
9396

97+
// Sharing this saves 1 alloc per use; this is safe because it's immutable.
98+
var sharedNothingSelector Selector = nothingSelector{}
99+
94100
// Nothing returns a selector that matches no labels
95101
func Nothing() Selector {
96-
return nothingSelector{}
102+
return sharedNothingSelector
97103
}
98104

99105
// NewSelector returns a nil selector

0 commit comments

Comments
 (0)