Changeset 209115 in webkit


Ignore:
Timestamp:
Nov 29, 2016 8:22:21 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Improve name sorting in HeapSnapshot data grids
https://bugs.webkit.org/show_bug.cgi?id=165170
<rdar://problem/28784421>

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2016-11-29
Reviewed by Matt Baker.

When sorting the Name column, group named properties and unnamed
properties and sort them each individually:

  • Sort named properties by their property name (property names will be unique if they exist)
  • Sort unnamed properties by their class name (guaranteed)
  • Sort any tied class names by their object id

This makes using the Object Graph with Name sort easier to follow.
In the ascending sort you see all the named properties first,
followed by the unnamed (internal) properties.

  • UserInterface/Views/HeapSnapshotContentView.js:

(WebInspector.HeapSnapshotObjectGraphContentView):
Since this data grid column now sorts on more than just the "Class Name"
rename it to "Name".

  • UserInterface/Views/HeapSnapshotDataGridTree.js:

(WebInspector.HeapSnapshotDataGridTree.buildSortComparator):
Make the sort of the className column more general to handle sorting
by property names, class names, and object identifiers.

  • UserInterface/Views/HeapSnapshotInstanceDataGridNode.js:

(WebInspector.HeapSnapshotInstanceDataGridNode.prototype.get propertyName):
(WebInspector.HeapSnapshotInstanceDataGridNode.prototype.createCellContent):
Provide a lazy propertyName accessor where we compute it once and stash
it on the DataGridNode to avoid extra work when resorting.

(WebInspector.HeapSnapshotInstanceDataGridNode.prototype._populate.propertyName):
(WebInspector.HeapSnapshotInstanceDataGridNode.prototype._populate):
In the initial populated sort, provide the necessary property name property
the sort comparator expects.

Location:
trunk/Source/WebInspectorUI
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r209089 r209115  
     12016-11-29  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Improve name sorting in HeapSnapshot data grids
     4        https://bugs.webkit.org/show_bug.cgi?id=165170
     5        <rdar://problem/28784421>
     6
     7        Reviewed by Matt Baker.
     8
     9        When sorting the Name column, group named properties and unnamed
     10        properties and sort them each individually:
     11
     12          - Sort named properties by their property name (property names will be unique if they exist)
     13          - Sort unnamed properties by their class name (guaranteed)
     14          - Sort any tied class names by their object id
     15
     16        This makes using the Object Graph with Name sort easier to follow.
     17        In the ascending sort you see all the named properties first,
     18        followed by the unnamed (internal) properties.
     19
     20        * UserInterface/Views/HeapSnapshotContentView.js:
     21        (WebInspector.HeapSnapshotObjectGraphContentView):
     22        Since this data grid column now sorts on more than just the "Class Name"
     23        rename it to "Name".
     24
     25        * UserInterface/Views/HeapSnapshotDataGridTree.js:
     26        (WebInspector.HeapSnapshotDataGridTree.buildSortComparator):
     27        Make the sort of the `className` column more general to handle sorting
     28        by property names, class names, and object identifiers.
     29
     30        * UserInterface/Views/HeapSnapshotInstanceDataGridNode.js:
     31        (WebInspector.HeapSnapshotInstanceDataGridNode.prototype.get propertyName):
     32        (WebInspector.HeapSnapshotInstanceDataGridNode.prototype.createCellContent):
     33        Provide a lazy `propertyName` accessor where we compute it once and stash
     34        it on the DataGridNode to avoid extra work when resorting.
     35
     36        (WebInspector.HeapSnapshotInstanceDataGridNode.prototype._populate.propertyName):
     37        (WebInspector.HeapSnapshotInstanceDataGridNode.prototype._populate):
     38        In the initial populated sort, provide the necessary property name property
     39        the sort comparator expects.
     40
    1412016-11-29  Matt Baker  <mattbaker@apple.com>
    242
  • trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js

    r209062 r209115  
    141141localizedStrings["Child Layers"] = "Child Layers";
    142142localizedStrings["Children"] = "Children";
    143 localizedStrings["Class Name"] = "Class Name";
    144143localizedStrings["Classes"] = "Classes";
    145144localizedStrings["Clear"] = "Clear";
  • trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotContentView.js

    r205425 r209115  
    119119            },
    120120            className: {
    121                 title: WebInspector.UIString("Class Name"),
     121                title: WebInspector.UIString("Name"),
    122122                sortable: true,
    123123                disclosure: true,
     
    148148            },
    149149            className: {
    150                 title: WebInspector.UIString("Class Name"),
     150                title: WebInspector.UIString("Name"),
    151151                sortable: true,
    152152                disclosure: true,
  • trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotDataGridTree.js

    r205425 r209115  
    5252        let multiplier = sortOrder === WebInspector.DataGrid.SortOrder.Ascending ? 1 : -1;
    5353        let numberCompare = (columnIdentifier, a, b) => multiplier * (a.data[columnIdentifier] - b.data[columnIdentifier]);
    54         let localeCompare = (columnIdentifier, a, b) => multiplier * (a.data[columnIdentifier].localeCompare(b.data[columnIdentifier]));
     54        let nameCompare = (a, b) => {
     55            // Sort by property name if available. Property names before no property name.
     56            if (a.propertyName || b.propertyName) {
     57                if (a.propertyName && !b.propertyName)
     58                    return multiplier * -1;
     59                if (!a.propertyName && b.propertyName)
     60                    return multiplier * 1;
     61                let propertyNameCompare = a.propertyName.localeCompare(b.propertyName);
     62                console.assert(propertyNameCompare !== 0, "Property names should be unique, we shouldn't have equal property names.");
     63                return multiplier * propertyNameCompare;
     64            }
     65
     66            // Sort by class name and object id if no property name.
     67            let classNameCompare = a.data.className.localeCompare(b.data.className);
     68            if (classNameCompare)
     69                return multiplier * classNameCompare;
     70            if (a.data.id || b.data.id)
     71                return multiplier * (a.data.id - b.data.id);
     72            return 0;
     73        };
    5574
    5675        switch (columnIdentifier) {
     
    6281            return numberCompare.bind(this, "count");
    6382        case "className":
    64             return localeCompare.bind(this, "className");
     83            return nameCompare;
    6584        }
    6685    }
  • trunk/Source/WebInspectorUI/UserInterface/Views/HeapSnapshotInstanceDataGridNode.js

    r208304 r209115  
    9898    get selectable() { return false; }
    9999
     100    get propertyName()
     101    {
     102        if (!this._edge)
     103            return "";
     104
     105        if (!this._propertyName)
     106            this._propertyName = WebInspector.HeapSnapshotRootPath.pathComponentForIndividualEdge(this._edge);
     107        return this._propertyName;
     108    }
     109
    100110    createCells()
    101111    {
     
    147157            if (this._edge) {
    148158                let nameElement = containerElement.appendChild(document.createElement("span"));
    149                 let edgeText = WebInspector.HeapSnapshotRootPath.pathComponentForIndividualEdge(this._edge);
    150                 if (edgeText)
    151                     nameElement.textContent = edgeText + ": " + this._node.className + " ";
     159                let propertyName = this.propertyName;
     160                if (propertyName)
     161                    nameElement.textContent = propertyName + ": " + this._node.className + " ";
    152162                else
    153163                    nameElement.textContent = this._node.className + " ";
     
    209219        this.removeEventListener("populate", this._populate, this);
    210220
     221        function propertyName(edge) {
     222            return edge ? WebInspector.HeapSnapshotRootPath.pathComponentForIndividualEdge(edge) : "";
     223        }
     224
    211225        this._node.retainedNodes((instances, edges) => {
    212226            // Reference edge from instance so we can get it after sorting.
     
    215229
    216230            instances.sort((a, b) => {
    217                 let fakeDataGridNodeA = {data: a};
    218                 let fakeDataGridNodeB = {data: b};
     231                let fakeDataGridNodeA = {data: a, propertyName: propertyName(a.__edge)};
     232                let fakeDataGridNodeB = {data: b, propertyName: propertyName(b.__edge)};
    219233                return this._tree._sortComparator(fakeDataGridNodeA, fakeDataGridNodeB);
    220234            });
Note: See TracChangeset for help on using the changeset viewer.