[erlang-questions] How to efficiently set the bit at position Index to 1 in a binary?
Mon Dec 26 01:57:45 CET 2011
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.
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
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions