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

remove unnecessary nil checks before calling len() on slices #701

Merged
merged 1 commit into from
Dec 27, 2024

Conversation

knbr13
Copy link
Contributor

@knbr13 knbr13 commented Dec 27, 2024

this PR removes unnecessary nil checks before calling len() on slices.,

var slice []byte // equal to nil, default value for a slice
if slice != nil && len(slice) > 1 {}
// is the same as
if len(slice) > 1 {}

because len(slice) where slice == nil is always equal to 0,

staticcheck will highlight this optimization with the following message:

log.go:497:5: should omit nil check; len() for []byte is defined as zero (S1009)

@rs rs merged commit 31e7995 into rs:master Dec 27, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants