Skip to content

Commit

Permalink
Rename and comment on why sharing is safe
Browse files Browse the repository at this point in the history
Kubernetes-commit: 916fe2f89610a058603c1aa5260cd45841aadb0c
  • Loading branch information
howardjohn authored and k8s-publishing-bot committed Nov 1, 2022
1 parent 3adc870 commit 88a1448
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/labels/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ type Selector interface {
RequiresExactMatch(label string) (value string, found bool)
}

var everythingSelector Selector = internalSelector{}
// 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 everythingSelector
return sharedEverythingSelector
}

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

var internalNothingSelector Selector = nothingSelector{}
// 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 internalNothingSelector
return sharedNothingSelector
}

// NewSelector returns a nil selector
Expand Down

0 comments on commit 88a1448

Please sign in to comment.