<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>Hi folks,</div><div><br></div><div>Here's my code:</div><div><br></div><div>%%--------------------------------------------------------------------</div><div>%% @doc Set the bit at position Index to 1 in the binary Bin.</div><div>%% @end</div><div>%%--------------------------------------------------------------------</div><div>-spec set(Bin :: binary(), Index :: non_neg_integer()) -> binary().</div><div><b>set</b>(<<1:1, _/bits>> = Bin, 0) -></div><div> Bin;</div><div><b>set</b>(<<0:1, Rest/bits>>, 0) -></div><div> <<1:1, Rest/bits>>;</div><div><b>set</b>(Bin, Index) when Index > 0 -></div><div> Before = Index - 1,</div><div> <<Head:Before, _:1, Rest/bits>> = Bin,</div><div> <<Head:Before, 1:1, Rest/bits>>.</div></div><div><br></div><div><br></div><div>After compiling, I'm getting the following warnings:</div><div><div>src/foo.erl:248: Warning: INFO: the '=' operator will prevent delayed sub binary optimization</div><div>src/foo.erl:248: Warning: INFO: the '=' operator will prevent delayed sub binary optimization</div><div>src/foo.erl:250: Warning: NOT OPTIMIZED: sub binary is used or returned</div><div>src/foo.erl:254: Warning: NOT OPTIMIZED: sub binary is used or returned</div></div><div><br></div><div>What's the best/optimized solution and how to get rid of these warnings?</div><br><div>
<div>Regards,</div><div>Zabrane</div>
</div>
<br></body></html>