Permalink
Browse files

speed up get_cstring a little by using binary:match directly instead …

…of binary:split
  • Loading branch information...
1 parent 8ea48c7 commit adce0e94ab11f2cf338e63e68e667a192200816f Tony Hannan committed Aug 5, 2011
Showing with 4 additions and 1 deletion.
  1. +4 −1 src/bson_binary.erl
View
@@ -80,7 +80,10 @@ get_string (<<?get_int32 (N), Bin /binary>>) ->
put_cstring (UBin) -> <<UBin /binary, 0:8>>.
-spec get_cstring (binary()) -> {bson:utf8(), binary()}.
-get_cstring (Bin) -> list_to_tuple (binary:split (Bin, <<0>>)).
+get_cstring (Bin) -> % list_to_tuple (binary:split (Bin, <<0>>)).
+ {Pos, _Len} = binary:match (Bin, <<0>>), % _Len = 1 but don't match 1 to avoid check
+ <<UBin :Pos /binary, 0:8, Rest /binary>> = Bin,
+ {UBin, Rest}.
-spec put_document (bson:document()) -> binary().
put_document (Document) ->

0 comments on commit adce0e9

Please sign in to comment.