Skip to content

Commit 88a1448

Browse files
howardjohnk8s-publishing-bot
authored andcommitted
Rename and comment on why sharing is safe
Kubernetes-commit: 916fe2f89610a058603c1aa5260cd45841aadb0c
1 parent 3adc870 commit 88a1448

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/labels/selector.go

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

77-
var everythingSelector Selector = internalSelector{}
77+
// Sharing this saves 1 alloc per use; this is safe because it's immutable.
78+
var sharedEverythingSelector Selector = internalSelector{}
7879

7980
// Everything returns a selector that matches all labels.
8081
func Everything() Selector {
81-
return everythingSelector
82+
return sharedEverythingSelector
8283
}
8384

8485
type nothingSelector struct{}
@@ -93,11 +94,12 @@ func (n nothingSelector) RequiresExactMatch(label string) (value string, found b
9394
return "", false
9495
}
9596

96-
var internalNothingSelector Selector = nothingSelector{}
97+
// Sharing this saves 1 alloc per use; this is safe because it's immutable.
98+
var sharedNothingSelector Selector = nothingSelector{}
9799

98100
// Nothing returns a selector that matches no labels
99101
func Nothing() Selector {
100-
return internalNothingSelector
102+
return sharedNothingSelector
101103
}
102104

103105
// NewSelector returns a nil selector

0 commit comments

Comments
 (0)