Skip to content

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