2011-01-21 Mikhail Naganov <mnaganov@chromium.org>
authormnaganov@chromium.org <mnaganov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Jan 2011 14:39:58 +0000 (14:39 +0000)
committermnaganov@chromium.org <mnaganov@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 24 Jan 2011 14:39:58 +0000 (14:39 +0000)
        Reviewed by Pavel Feldman.

        Web Inspector: [Chromium] Fix heap snapshot table sorting.

        Fix table sorting to avoid qsort instability artefacts.

        https://bugs.webkit.org/show_bug.cgi?id=52914

        * inspector/front-end/HeapSnapshotView.js:
        (WebInspector.HeapSnapshotView.prototype._sortData):
        (WebInspector.HeapSnapshotDataGridList.propertyComparator.comparator):
        (WebInspector.HeapSnapshotDataGridList.propertyComparator):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@76514 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/HeapSnapshotView.js

index a2d2964..62d7d28 100644 (file)
@@ -1,3 +1,18 @@
+2011-01-21  Mikhail Naganov  <mnaganov@chromium.org>
+
+        Reviewed by Pavel Feldman.
+
+        Web Inspector: [Chromium] Fix heap snapshot table sorting.
+
+        Fix table sorting to avoid qsort instability artefacts.
+
+        https://bugs.webkit.org/show_bug.cgi?id=52914
+
+        * inspector/front-end/HeapSnapshotView.js:
+        (WebInspector.HeapSnapshotView.prototype._sortData):
+        (WebInspector.HeapSnapshotDataGridList.propertyComparator.comparator):
+        (WebInspector.HeapSnapshotDataGridList.propertyComparator):
+
 2011-01-24  Mikhail Naganov  <mnaganov@chromium.org>
 
         Reviewed by Yury Semikhatsky.
index f349361..ec48bf2 100644 (file)
@@ -601,10 +601,10 @@ WebInspector.HeapSnapshotView.prototype = {
         var sortColumnIdentifier = this.dataGrid.sortColumnIdentifier;
         var sortProperty = {
             cons: ["constructorName", null],
-            count: ["count", null],
-            size: ["size", "count"],
-            countDelta: this.showCountDeltaAsPercent ? ["countDeltaPercent", null] : ["countDelta", null],
-            sizeDelta: this.showSizeDeltaAsPercent ? ["sizeDeltaPercent", "countDeltaPercent"] : ["sizeDelta", "sizeDeltaPercent"]
+            count: ["count", "constructorName"],
+            size: ["size", "constructorName"],
+            countDelta: [this.showCountDeltaAsPercent ? "countDeltaPercent" : "countDelta", "constructorName"],
+            sizeDelta: [this.showSizeDeltaAsPercent ? "sizeDeltaPercent" : "sizeDelta", "constructorName"]
         }[sortColumnIdentifier];
 
         this.snapshotDataGridList.sort(WebInspector.HeapSnapshotDataGridList.propertyComparator(sortProperty[0], sortProperty[1], sortAscending));
@@ -1046,10 +1046,17 @@ WebInspector.HeapSnapshotDataGridList.propertyComparator = function(property, pr
     if (!comparator) {
         comparator = function(lhs, rhs) {
             var l = lhs[property], r = rhs[property];
-            if ((l === null || r === null) && property2 !== null)
-                l = lhs[property2], r = rhs[property2];
-            var result = l < r ? -1 : (l > r ? 1 : 0);
-            return isAscending ? result : -result;
+            var result = 0;
+            if (l !== null && r !== null) {
+                result = l < r ? -1 : (l > r ? 1 : 0);
+            }
+            if (result !== 0 || property2 === null) {
+                return isAscending ? result : -result;
+            } else {
+                l = lhs[property2];
+                r = rhs[property2];
+                return l < r ? -1 : (l > r ? 1 : 0);
+            }
         };
         this.propertyComparators[(isAscending ? 1 : 0)][propertyHash] = comparator;
     }