[erlang-questions] Smart way to trim a binary?
Kostis Sagonas
kostis@REDACTED
Wed Jun 24 14:22:29 CEST 2009
Christian wrote:
> I prefer this approach for implementing is_whitespace. Saves a few
> lines and is quite readable. If I'm lucky the compiler is sufficiently
> smart to optimize it into submission.
>
> is_whitespace(C) -> lists:member(C, "\s\t\r\n").
Actually, the compiler is quite smart NOT to turn it into the form you
are suggesting because the version with lists:member/2 is linear on the
length of the list while the version with many clauses uses pattern
matching compilation to access the proper clause in sub-linear time.
Kostis
More information about the erlang-questions
mailing list