Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if the set is empty , and delete the reduntant type convert. #39260

Merged
merged 1 commit into from
Jan 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions staging/src/k8s.io/apimachinery/pkg/labels/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ func validateLabelValue(v string) error {
// SelectorFromSet returns a Selector which will match exactly the given Set. A
// nil and empty Sets are considered equivalent to Everything().
func SelectorFromSet(ls Set) Selector {
if ls == nil {
if ls == nil || len(ls) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, it's safe to call len on nil maps so you could have just replaced the == nil with the clause you added.

return internalSelector{}
}
var requirements internalSelector
Expand All @@ -807,14 +807,14 @@ func SelectorFromSet(ls Set) Selector {
}
// sort to have deterministic string representation
sort.Sort(ByKey(requirements))
return internalSelector(requirements)
return requirements
}

// SelectorFromValidatedSet returns a Selector which will match exactly the given Set.
// A nil and empty Sets are considered equivalent to Everything().
// It assumes that Set is already validated and doesn't do any validation.
func SelectorFromValidatedSet(ls Set) Selector {
if ls == nil {
if ls == nil || len(ls) == 0 {
return internalSelector{}
}
var requirements internalSelector
Expand All @@ -823,7 +823,7 @@ func SelectorFromValidatedSet(ls Set) Selector {
}
// sort to have deterministic string representation
sort.Sort(ByKey(requirements))
return internalSelector(requirements)
return requirements
}

// ParseToRequirements takes a string representing a selector and returns a list of
Expand Down