From: Christophe Romain Date: Mon, 16 Jun 2014 17:49:08 +0000 (+0200) Subject: apply string optimizations X-Git-Tag: 16.12-beta1~49^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b93de691248629d75e1d2657d09ebd990670924;p=ejabberd apply string optimizations --- diff --git a/src/str.erl b/src/str.erl index 439ae6a7a..43fd51878 100644 --- a/src/str.erl +++ b/src/str.erl @@ -93,7 +93,10 @@ rchr(B, C) -> -spec str(binary(), binary()) -> non_neg_integer(). str(B1, B2) -> - string:str(binary_to_list(B1), binary_to_list(B2)). + case binary:match(B1, B2) of + {R, _Len} -> R+1; + _ -> 0 + end. -spec rstr(binary(), binary()) -> non_neg_integer(). @@ -113,7 +116,7 @@ cspan(B1, B2) -> -spec copies(binary(), non_neg_integer()) -> binary(). copies(B, N) -> - iolist_to_binary(string:copies(binary_to_list(B), N)). + binary:copy(B, N). -spec words(binary()) -> pos_integer(). @@ -201,7 +204,7 @@ join(L, Sep) -> -spec substr(binary(), pos_integer()) -> binary(). substr(B, N) -> - iolist_to_binary(string:substr(binary_to_list(B), N)). + binary_part(B, N-1, byte_size(B)-N+1). -spec chr(binary(), char()) -> non_neg_integer(). @@ -221,7 +224,7 @@ chars(C, N) -> -spec substr(binary(), pos_integer(), non_neg_integer()) -> binary(). substr(B, S, E) -> - iolist_to_binary(string:substr(binary_to_list(B), S, E)). + binary_part(B, S-1, E). -spec strip(binary(), both | left | right, char()) -> binary().