Skip to content

fix: fix referencing the loop variable and avoid slice grow#226

Open
qshuai wants to merge 1 commit into
jinzhu:masterfrom
qshuai:feature/misuse-temp-value
Open

fix: fix referencing the loop variable and avoid slice grow#226
qshuai wants to merge 1 commit into
jinzhu:masterfrom
qshuai:feature/misuse-temp-value

Conversation

@qshuai

@qshuai qshuai commented Feb 27, 2025

Copy link
Copy Markdown
Contributor

The semantics of for loop variables is controlled by the language version in the module’s go.mod file when using go version 1.22 or later. That is it works well when the version in go module is 1.22 or later. Otherwise the reference using pointer will capture the same loop variable.

In addition, making slice with length avoids slice growing to ensure fairness.

References:

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.

1 participant