couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r937528 - /couchdb/trunk/src/couchdb/couch_view.erl
Date Fri, 23 Apr 2010 21:35:40 GMT
Author: kocolosk
Date: Fri Apr 23 21:35:40 2010
New Revision: 937528

URL: http://svn.apache.org/viewvc?rev=937528&view=rev
Log:
faster default view collation. Closes COUCHDB-746

Modified:
    couchdb/trunk/src/couchdb/couch_view.erl

Modified: couchdb/trunk/src/couchdb/couch_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_view.erl?rev=937528&r1=937527&r2=937528&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_view.erl Fri Apr 23 21:35:40 2010
@@ -369,81 +369,67 @@ nuke_dir(Dir) ->
 
 % keys come back in the language of btree - tuples.
 less_json_ids({JsonA, IdA}, {JsonB, IdB}) ->
-    case JsonA == JsonB of
-    false ->
-        less_json(JsonA, JsonB);
-    true ->
-        IdA < IdB
+    case less_json0(JsonA, JsonB) of
+    0 ->
+        IdA < IdB;
+    Result ->
+        Result < 0
     end.
-        
 
-less_json(A, B) ->
-    TypeA = type_sort(A),
-    TypeB = type_sort(B),
-    if TypeA == TypeB ->
-	    less_same_type(A, B);
-       true ->
-	    TypeA < TypeB
-    end.
+less_json(A,B) ->
+    less_json0(A,B) < 0.
 
-type_sort(V) when is_atom(V) -> 0;
-type_sort(V) when is_integer(V) -> 1;
-type_sort(V) when is_float(V) -> 1;
-type_sort(V) when is_binary(V) -> 2;
-type_sort(V) when is_list(V) -> 3;
-type_sort({V}) when is_list(V) -> 4;
-type_sort(V) when is_tuple(V) -> 5.
+less_json0(A,A)                                 -> 0;
 
+less_json0(A,B) when is_atom(A), is_atom(B)     -> atom_sort(A) - atom_sort(B);
+less_json0(A,_) when is_atom(A)                 -> -1;
+less_json0(_,B) when is_atom(B)                 -> 1;
+
+less_json0(A,B) when is_number(A), is_number(B) -> A - B;
+less_json0(A,_) when is_number(A)               -> -1;
+less_json0(_,B) when is_number(B)               -> 1;
+
+less_json0(A,B) when is_binary(A), is_binary(B) -> couch_util:collate(A,B);
+less_json0(A,_) when is_binary(A)               -> -1;
+less_json0(_,B) when is_binary(B)               -> 1;
+
+less_json0(A,B) when is_list(A), is_list(B)     -> less_list(A,B);
+less_json0(A,_) when is_list(A)                 -> -1;
+less_json0(_,B) when is_list(B)                 -> 1;
+
+less_json0({A},{B}) when is_list(A), is_list(B) -> less_props(A,B);
+less_json0({A},_) when is_list(A)               -> -1;
+less_json0(_,{B}) when is_list(B)               -> 1.
 
 atom_sort(null) -> 1;
 atom_sort(false) -> 2;
 atom_sort(true) -> 3.
 
-
-less_same_type(A,B) when is_atom(A) ->
-  atom_sort(A) < atom_sort(B);
-less_same_type(A,B) when is_binary(A) ->
-  couch_util:collate(A, B) < 0;
-less_same_type({AProps}, {BProps}) ->
-  less_props(AProps, BProps);
-less_same_type(A, B) when is_list(A) ->
-  less_list(A, B);
-less_same_type(A, B) ->
-    A < B.
-
 less_props([], [_|_]) ->
-    true;
+    -1;
 less_props(_, []) ->
-    false;
+    1;
 less_props([{AKey, AValue}|RestA], [{BKey, BValue}|RestB]) ->
     case couch_util:collate(AKey, BKey) of
-    -1 -> true;
-    1 -> false;
     0 ->
-        case less_json(AValue, BValue) of
-        true -> true;
-        false ->
-            case less_json(BValue, AValue) of
-            true -> false;
-            false ->
-                less_props(RestA, RestB)
-            end
-        end
+        case less_json0(AValue, BValue) of
+        0 ->
+            less_props(RestA, RestB);
+        Result ->
+            Result
+        end;
+    Result ->
+        Result
     end.
 
 less_list([], [_|_]) ->
-    true;
+    -1;
 less_list(_, []) ->
-    false;
+    1;
 less_list([A|RestA], [B|RestB]) ->
-    case less_json(A,B) of
-    true -> true;
-    false ->
-        case less_json(B,A) of
-        true -> false;
-        false ->
-            less_list(RestA, RestB)
-        end
+    case less_json0(A,B) of
+    0 ->
+        less_list(RestA, RestB);
+    Result ->
+        Result
     end.
-
-



Mime
View raw message