Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: remove unnecessary redeclarations in for loops (part 2)#18593

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
aslilac wants to merge4 commits intomain
base:main
Choose a base branch
Loading
fromlilac/go-122-range-fix-all

Conversation

aslilac
Copy link
Member

Now that we're post code-freeze, let's go forth with the other half of this cleanup.

Comment on lines -411 to -413
// When we assign the non-pointer to a
// variable it loses the reference.
replica := replica
Copy link
MemberAuthor

@aslilacaslilacJun 25, 2025
edited
Loading

Choose a reason for hiding this comment

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

@johnstcn you called out this one as potentially being a concern, but I think there are already two "copies" happening here that make this safe

  • it gets copied from the slice to thereplica variable by the loop
  • it gets copied from thereplica variable to the argument value as part of theappend call on the next line

ie. go does nothave "references", it has pointers and values. you're either copying a pointer or you're copying the whole value.

here's a go playground that hopefully instills confidencehttps://go.dev/play/p/MfFltxQepYE

johnstcn reacted with thumbs up emoji
Copy link
Contributor

@dannykoppingdannykopping left a comment

Choose a reason for hiding this comment

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

Thanks@aslilac!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dannykoppingdannykoppingdannykopping approved these changes

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@aslilacaslilac

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@aslilac@dannykopping@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp