summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_util.erl
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2008-04-20 18:17:15 +0000
committerDamien F. Katz <damien@apache.org>2008-04-20 18:17:15 +0000
commitfb5b6bbc5aa941478d700e8fb3011c2a24c4d2d4 (patch)
treebcc23ed4869f395e894f76ec3fb5e76f75a5ba98 /src/couchdb/couch_util.erl
parentad230e67fb09883e2171291d5a42635f5e2addb9 (diff)
Added proper UUID generation and changed the details of how way debug logging is done to now use a more effcient macro instead of a function call.
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@649948 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_util.erl')
-rw-r--r--src/couchdb/couch_util.erl28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/couchdb/couch_util.erl b/src/couchdb/couch_util.erl
index f85cc834..504a675a 100644
--- a/src/couchdb/couch_util.erl
+++ b/src/couchdb/couch_util.erl
@@ -40,11 +40,25 @@ start_link(LibDir) ->
new_uuid() ->
- gen_server:call(couch_util, new_uuid).
+ to_hex(erlang:port_control(drv_port(), 2, <<>>)).
+
+to_hex([]) ->
+ [];
+to_hex([H|T]) ->
+ Digit1 = H div 16,
+ Digit2 = H rem 16,
+ [to_digit(Digit1), to_digit(Digit2) | to_hex(T)].
+
+to_digit(N) when N < 10 ->
+ $0 + N;
+to_digit(N) ->
+ $a + N-10.
+
% returns a random integer
rand32() ->
- gen_server:call(couch_util, rand32).
+ [A,B,C,D|_] = erlang:port_control(drv_port(), 2, <<>>),
+ (A bsl 24) + (B bsl 16) + (C bsl 8) + D.
% given a pathname "../foo/bar/" it gives back the fully qualified
% absolute pathname.
@@ -190,8 +204,6 @@ init([]) ->
terminate(_Reason, _Server) ->
ok.
-handle_call(new_uuid, _From, Server) ->
- {reply, new_uuid_int(), Server};
handle_call(rand32, _From, Server) ->
{reply, rand32_int(), Server}.
@@ -205,14 +217,6 @@ handle_info(_Info, State) ->
{noreply, State}.
-new_uuid_int() ->
- % eventually make this a C callout for a real guid (collisions are far less likely
- % when using a proper generation function). For now we just fake it.
- Num1 = random:uniform(16#FFFFFFFF + 1) - 1,
- Num2 = random:uniform(16#FFFFFFFF + 1) - 1,
- Num3 = random:uniform(16#FFFFFFFF + 1) - 1,
- Num4 = random:uniform(16#FFFFFFFF + 1) - 1,
- lists:flatten(io_lib:format("~8.16.0B~8.16.0B~8.16.0B~8.16.0B", [Num1, Num2, Num3, Num4])).