Skip to content

Commit

Permalink
Merge pull request #112649 from howardjohn/set/optimize-everything-no…
Browse files Browse the repository at this point in the history
…thing

Optimize `Everything` and `Nothing` label selectors

Kubernetes-commit: bbe050dd01fbf60661b8b8d8f750a0dc675dcbb9
  • Loading branch information
k8s-publishing-bot committed Nov 3, 2022
2 parents b03a432 + 88a1448 commit 9e85d3a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/labels/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ type Selector interface {
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.
func Everything() Selector {
return internalSelector{}
return sharedEverythingSelector
}

type nothingSelector struct{}
Expand All @@ -91,9 +94,12 @@ func (n nothingSelector) RequiresExactMatch(label string) (value string, found b
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
func Nothing() Selector {
return nothingSelector{}
return sharedNothingSelector
}

// NewSelector returns a nil selector
Expand Down

0 comments on commit 9e85d3a

Please sign in to comment.