[erlang-questions] idea: service pack one
Joel Reymont
joelr1@REDACTED
Thu Nov 15 11:57:24 CET 2007
The difference seems to be in matching an empty binary vs <<_Head:N/
binary>>.
Why exactly is the 2nd pattern so much faster?
Thanks, Joel
On Nov 15, 2007, at 6:53 AM, Bjorn Gustavsson wrote:
> index(Str, Char, N) ->
> case Str of
> <<_Head:N/binary, Char, _Tail/binary>> ->
> N + 1;
> <<>> ->
> 0;
> _ ->
> index(Str, Char, N + 1)
> end.
> ...
> Note: Your index function can be written speeded a bit.
> ...
> index(Str, Char, N) ->
> case Str of
> <<_Head:N/binary, Char, _Tail/binary>> ->
> N + 1;
> <<_Head:N/binary>> ->
> 0;
> _ ->
> index(Str, Char, N + 1)
> end.
--
http://wagerlabs.com
More information about the erlang-questions
mailing list