diff options
author | Christophe Romain <christophe.romain@process-one.net> | 2014-06-16 19:49:08 +0200 |
---|---|---|
committer | Christophe Romain <christophe.romain@process-one.net> | 2016-11-15 14:32:22 +0100 |
commit | 2b93de691248629d75e1d2657d09ebd990670924 (patch) | |
tree | 60f834cbc907ed3172031734084bcc554f833854 /src/str.erl | |
parent | Add configurable weight for commands (diff) |
apply string optimizations
Diffstat (limited to 'src/str.erl')
-rw-r--r-- | src/str.erl | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/str.erl b/src/str.erl index 439ae6a7..43fd5187 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(). |