On Mon, Apr 12, 2021 at 6:01 PM Luke Wilson <thelukasw...@gmail.com> wrote:

> I've heard several times from members of the community (on Matrix and 
> possibly on answers) that a simple iteration like
>
> const mixed = "\b5Ὂg̀9! ℃ᾭG"
> for _, c := range mixed {
> ... do something with c (but not write to it)
>
> will actually silently allocate a slice of runes and decode the string into 
> it, before iteration. I've heard it is done to prevent problems that occur 
> when a programmer might overwrite data being iterated

I believe no silent allocation and no conversion to a slice of runes
occurs. A single instance of variable c, of type rune, exists within
the loop. There's no problem with modifying 'c'. A problem exists if
the _address_ of 'c' is assumed to point to different variables in
each cycle. That's not the case.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-Wfk%3DSEFxvb%3Dqot9dpC%3Dz6BM48dzPzwct76v2ceCJoNVw%40mail.gmail.com.

Reply via email to