mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
apply string optimizations
This commit is contained in:
parent
909e0eb5dd
commit
2b93de6912
11
src/str.erl
11
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().
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user