changeset 36:ca803032d3c4

Performed sorting at an earlier stage when less keys are present, which should improve performance.
author Atul Varma <varmaa@toolness.com>
date Tue, 14 Apr 2009 08:55:23 -0700
parents 3f64fb2aadb2
children cf2122f596c8
files browser-couch.js
diffstat 1 files changed, 5 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/browser-couch.js	Tue Apr 14 08:43:20 2009 -0700
+++ b/browser-couch.js	Tue Apr 14 08:55:23 2009 -0700
@@ -345,6 +345,8 @@
     continueMap();
 
     function doReduce() {
+      mapKeys.sort();
+
       if (reduce) {
         var i = 0;
 
@@ -366,7 +368,7 @@
                    i < mapKeys.length)
 
           if (i == mapKeys.length)
-            doSort();
+            doneWithReduce();
           else {
             if (progress)
               progress("reduce", i / mapKeys.length, continueReduce);
@@ -389,18 +391,11 @@
           }
         }
 
-        doSort();
+        doneWithReduce();
       }
     }
 
-    function doSort() {
-      rows.sort(function compare(a, b) {
-                  if (a.key < b.key)
-                    return -1;
-                  if (a.key > b.key)
-                    return 1;
-                  return 0;
-                });
+    function doneWithReduce() {
       finished({rows: rows});
     }
   }