Parsing null terminated strings in a binary.

Mats Cronqvist mats.cronqvist@REDACTED
Thu Jan 13 15:49:51 CET 2005

   sorry to keep harping on this...
   ...but would it be (noticably) faster to move the call to size/1 outside the loop?
   or equivalently, how fast is size/1 (compared to the binary match)?
   i would guess plenty fast but i'm too lazy to try it.


Raimo Niskanen wrote:
> You are missing nothing. The code just evolved in my head to
> what it became - some cruft was left. This might be even clearer
> (untested):
> z_split(B, N) when is_binary(B), is_integer(N) ->
>      case B of
> 	<<B1:N/binary,0,B2/binary>> -> 
>             {B1,B2};
>         _ when size(B) > N
>             z_split(B, N+1);
>         _ ->
>             B
>      end.

More information about the erlang-questions mailing list