[erlang-questions] How to efficiently set the bit at position Index to 1 in a binary?
Zabrane Mickael
zabrane3@REDACTED
Mon Dec 26 05:38:09 CET 2011
Much clear to me now.
There's no recursion in set/2, so I can live with that :-)
On Dec 26, 2011, at 1:57 AM, Magnus Klaar wrote:
> Hi!
>
> Why are you obsessing about creating a sub-binary in this case? A sub-binary is _not_ a full copy of a binary, it's just a binary that's pointing into another binary. It's not very expensive. The only time you have any reason to go through great troubles to optimize this away is when the compiler cannot optimize a match operation that you perform on each iteration over a binary of unknown length.
>
> MVH Magnius
>
> On Sun, Dec 25, 2011 at 11:47 PM, Zabrane Mickael <zabrane3@REDACTED> wrote:
>
> On Dec 25, 2011, at 8:19 PM, Torben Hoffmann wrote:
>
>> Following that you can write it like:
>> set2(N, Bin) ->
>> <<L:N/bits, _:1, R/bits>> = Bin, % LINE 271
>>
>> <<L/bits, 1:1, R/bits>>.
>
>
> on my machine (R15B, R14B04), the warning is still reported.
> src/foo.erl:271: Warning: NOT OPTIMIZED: sub binary is used or returned
>
> Regards,
> Zabrane
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111226/4e4e8a17/attachment.htm>
More information about the erlang-questions
mailing list