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

refactor: remove redundant len check #2291

Merged
merged 1 commit into from
Sep 27, 2023
Merged

refactor: remove redundant len check #2291

merged 1 commit into from
Sep 27, 2023

Conversation

Juneezee
Copy link
Contributor

len returns 0 if the slice or map is nil. From the Go specification 1:

"1. For a nil slice, the number of iterations is 0."
"3. If the map is nil, the number of iterations is 0."

Therefore, an additional len(v) != 0 check for before the loop is unnecessary.

Footnotes

  1. https://go.dev/ref/spec#For_range

`len` returns 0 if the slice or map is nil. From the Go specification
[1]:

  "1. For a nil slice, the number of iterations is 0."
  "3. If the map is nil, the number of iterations is 0."

Therefore, an additional `len(v) != 0` check for before the loop is
unnecessary.

[1]: https://go.dev/ref/spec#For_range

Signed-off-by: Eng Zer Jun <[email protected]>
Copy link
Owner

@Jguer Jguer left a comment

Choose a reason for hiding this comment

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

thanks for the improvement @Juneezee

@Jguer Jguer merged commit a112155 into Jguer:next Sep 27, 2023
2 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.

2 participants