This was a concern when we originally implemented the m[string(b)] 
optimization.  If someone is simultaneously modifying b, then weird things 
happen during the lookup.  But it won't crash anything, just maybe not 
return what you expect.  And that's ok in cases of a data race, the spec 
makes no promises.

On Saturday, July 23, 2016 at 12:22:39 PM UTC-7, Axel Wagner wrote:
>
> The answer, I think, is yes. Because the only way, that any modification 
> of bytes can occur, is if there's a race and in the case of a race (hehe) 
> all bets are off anyway. I also see no reason for the scope of bytes to 
> have any influence on it, as races can also occur with variables in local 
> scope. If anything, escape analysis might.
>
> But to get a definite answer just try it out. Write the code, throw in 
> some concurrent modifications of bytes just for good measure (so the 
> compiler can't prove that no modification occurs) and look at the generated 
> code.
>
> On Sat, Jul 23, 2016 at 9:09 PM, Jan Mercl <0xj...@gmail.com <javascript:>
> > wrote:
>
>> On Sat, Jul 23, 2016 at 9:03 PM T L <tapi...@gmail.com <javascript:>> 
>> wrote:
>>
>> > If "bytes" is a local variable, it is reasonable the compiler will do 
>> the optimization.
>> > But how about if "bytes" is a global variable?
>>
>> Not sure what a global variable is. Go has universe scope, but user code 
>> cannot declare variables in that scope. Assuming a package scope is meant 
>> instead: such optimization might be possible Iff the compiler is able to 
>> prove that no one is ever mutating the slice.
>>
>> -- 
>>
>> -j
>>
>> -- 
>> 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...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to