Commit 6a5fc66d authored by yurys@chromium.org's avatar yurys@chromium.org

Introduce HeapSnapshotItem interface

The interface describes common part of nodes as well as containment and retainment edges. It used to iterate over the elements and serialize them.

BUG=None

Review URL: https://codereview.chromium.org/209653003

git-svn-id: svn://svn.chromium.org/blink/trunk@169845 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c66b4401
...@@ -28,8 +28,26 @@ ...@@ -28,8 +28,26 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/**
* @interface
*/
WebInspector.HeapSnapshotItem = function() { }
WebInspector.HeapSnapshotItem.prototype = {
/**
* @return {number}
*/
itemIndex: function() { },
/**
* @return {!Object}
*/
serialize: function() { }
};
/** /**
* @constructor * @constructor
* @implements {WebInspector.HeapSnapshotItem}
* @param {!WebInspector.HeapSnapshot} snapshot * @param {!WebInspector.HeapSnapshot} snapshot
* @param {number=} edgeIndex * @param {number=} edgeIndex
*/ */
...@@ -114,6 +132,16 @@ WebInspector.HeapSnapshotEdge.prototype = { ...@@ -114,6 +132,16 @@ WebInspector.HeapSnapshotEdge.prototype = {
}, },
/** /**
* @override
* @return {number}
*/
itemIndex: function()
{
return this.edgeIndex;
},
/**
* @override
* @return {!WebInspector.HeapSnapshotEdge.Serialized} * @return {!WebInspector.HeapSnapshotEdge.Serialized}
*/ */
serialize: function() serialize: function()
...@@ -129,7 +157,6 @@ WebInspector.HeapSnapshotEdge.prototype = { ...@@ -129,7 +157,6 @@ WebInspector.HeapSnapshotEdge.prototype = {
}; };
/** /**
* @interface * @interface
*/ */
...@@ -142,7 +169,7 @@ WebInspector.HeapSnapshotItemIterator.prototype = { ...@@ -142,7 +169,7 @@ WebInspector.HeapSnapshotItemIterator.prototype = {
hasNext: function() { }, hasNext: function() { },
/** /**
* @return {!WebInspector.HeapSnapshotEdge|!WebInspector.HeapSnapshotNode|!WebInspector.HeapSnapshotRetainerEdge} * @return {!WebInspector.HeapSnapshotItem}
*/ */
item: function() { }, item: function() { },
...@@ -156,15 +183,9 @@ WebInspector.HeapSnapshotItemIterator.prototype = { ...@@ -156,15 +183,9 @@ WebInspector.HeapSnapshotItemIterator.prototype = {
WebInspector.HeapSnapshotItemIndexProvider = function() { } WebInspector.HeapSnapshotItemIndexProvider = function() { }
WebInspector.HeapSnapshotItemIndexProvider.prototype = { WebInspector.HeapSnapshotItemIndexProvider.prototype = {
/**
* @param {!WebInspector.HeapSnapshotEdge|!WebInspector.HeapSnapshotNode|!WebInspector.HeapSnapshotRetainerEdge} item
* @return {number}
*/
indexForItem: function(item) { },
/** /**
* @param {number} newIndex * @param {number} newIndex
* @return {!WebInspector.HeapSnapshotEdge|!WebInspector.HeapSnapshotNode|!WebInspector.HeapSnapshotRetainerEdge} * @return {!WebInspector.HeapSnapshotItem}
*/ */
itemForIndex: function(newIndex) { }, itemForIndex: function(newIndex) { },
}; };
...@@ -180,16 +201,6 @@ WebInspector.HeapSnapshotNodeIndexProvider = function(snapshot) ...@@ -180,16 +201,6 @@ WebInspector.HeapSnapshotNodeIndexProvider = function(snapshot)
} }
WebInspector.HeapSnapshotNodeIndexProvider.prototype = { WebInspector.HeapSnapshotNodeIndexProvider.prototype = {
/**
* @param {!WebInspector.HeapSnapshotEdge|!WebInspector.HeapSnapshotNode|!WebInspector.HeapSnapshotRetainerEdge} item
* @return {number}
*/
indexForItem: function(item)
{
var node = /** @type {!WebInspector.HeapSnapshotNode} */ (item);
return node.nodeIndex;
},
/** /**
* @param {number} index * @param {number} index
* @return {!WebInspector.HeapSnapshotNode} * @return {!WebInspector.HeapSnapshotNode}
...@@ -213,16 +224,6 @@ WebInspector.HeapSnapshotEdgeIndexProvider = function(snapshot) ...@@ -213,16 +224,6 @@ WebInspector.HeapSnapshotEdgeIndexProvider = function(snapshot)
} }
WebInspector.HeapSnapshotEdgeIndexProvider.prototype = { WebInspector.HeapSnapshotEdgeIndexProvider.prototype = {
/**
* @param {!WebInspector.HeapSnapshotEdge|!WebInspector.HeapSnapshotNode|!WebInspector.HeapSnapshotRetainerEdge} item
* @return {number}
*/
indexForItem: function(item)
{
var edge = /** @type {!WebInspector.HeapSnapshotEdge} */ (item);
return edge.edgeIndex;
},
/** /**
* @param {number} index * @param {number} index
* @return {!WebInspector.HeapSnapshotEdge} * @return {!WebInspector.HeapSnapshotEdge}
...@@ -246,16 +247,6 @@ WebInspector.HeapSnapshotRetainerEdgeIndexProvider = function(snapshot) ...@@ -246,16 +247,6 @@ WebInspector.HeapSnapshotRetainerEdgeIndexProvider = function(snapshot)
} }
WebInspector.HeapSnapshotRetainerEdgeIndexProvider.prototype = { WebInspector.HeapSnapshotRetainerEdgeIndexProvider.prototype = {
/**
* @param {!WebInspector.HeapSnapshotEdge|!WebInspector.HeapSnapshotNode|!WebInspector.HeapSnapshotRetainerEdge} item
* @return {number}
*/
indexForItem: function(item)
{
var edge = /** @type {!WebInspector.HeapSnapshotRetainerEdge} */ (item);
return edge.retainerIndex();
},
/** /**
* @param {number} index * @param {number} index
* @return {!WebInspector.HeapSnapshotRetainerEdge} * @return {!WebInspector.HeapSnapshotRetainerEdge}
...@@ -304,6 +295,7 @@ WebInspector.HeapSnapshotEdgeIterator.prototype = { ...@@ -304,6 +295,7 @@ WebInspector.HeapSnapshotEdgeIterator.prototype = {
/** /**
* @constructor * @constructor
* @implements {WebInspector.HeapSnapshotItem}
* @param {!WebInspector.HeapSnapshot} snapshot * @param {!WebInspector.HeapSnapshot} snapshot
* @param {number} retainerIndex * @param {number} retainerIndex
*/ */
...@@ -423,6 +415,16 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = { ...@@ -423,6 +415,16 @@ WebInspector.HeapSnapshotRetainerEdge.prototype = {
}, },
/** /**
* @override
* @return {number}
*/
itemIndex: function()
{
return this._retainerIndex;
},
/**
* @override
* @return {!WebInspector.HeapSnapshotRetainerEdge.Serialized} * @return {!WebInspector.HeapSnapshotRetainerEdge.Serialized}
*/ */
serialize: function() serialize: function()
...@@ -479,12 +481,14 @@ WebInspector.HeapSnapshotRetainerEdgeIterator.prototype = { ...@@ -479,12 +481,14 @@ WebInspector.HeapSnapshotRetainerEdgeIterator.prototype = {
/** /**
* @constructor * @constructor
* @implements {WebInspector.HeapSnapshotItem}
* @param {!WebInspector.HeapSnapshot} snapshot
* @param {number=} nodeIndex * @param {number=} nodeIndex
*/ */
WebInspector.HeapSnapshotNode = function(snapshot, nodeIndex) WebInspector.HeapSnapshotNode = function(snapshot, nodeIndex)
{ {
this._snapshot = snapshot; this._snapshot = snapshot;
this.nodeIndex = nodeIndex; this.nodeIndex = nodeIndex || 0;
} }
/** /**
...@@ -631,6 +635,16 @@ WebInspector.HeapSnapshotNode.prototype = { ...@@ -631,6 +635,16 @@ WebInspector.HeapSnapshotNode.prototype = {
}, },
/** /**
* @override
* @return {number}
*/
itemIndex: function()
{
return this.nodeIndex;
},
/**
* @override
* @return {!WebInspector.HeapSnapshotNode.Serialized} * @return {!WebInspector.HeapSnapshotNode.Serialized}
*/ */
serialize: function() serialize: function()
...@@ -747,7 +761,7 @@ WebInspector.HeapSnapshotIndexRangeIterator.prototype = { ...@@ -747,7 +761,7 @@ WebInspector.HeapSnapshotIndexRangeIterator.prototype = {
}, },
/** /**
* @return {!WebInspector.HeapSnapshotEdge|!WebInspector.HeapSnapshotNode|!WebInspector.HeapSnapshotRetainerEdge} * @return {!WebInspector.HeapSnapshotItem}
*/ */
item: function() item: function()
{ {
...@@ -784,7 +798,7 @@ WebInspector.HeapSnapshotFilteredIterator.prototype = { ...@@ -784,7 +798,7 @@ WebInspector.HeapSnapshotFilteredIterator.prototype = {
}, },
/** /**
* @return {!WebInspector.HeapSnapshotEdge|!WebInspector.HeapSnapshotNode|!WebInspector.HeapSnapshotRetainerEdge} * @return {!WebInspector.HeapSnapshotItem}
*/ */
item: function() item: function()
{ {
...@@ -2071,7 +2085,7 @@ WebInspector.HeapSnapshotItemProvider.prototype = { ...@@ -2071,7 +2085,7 @@ WebInspector.HeapSnapshotItemProvider.prototype = {
return; return;
this._iterationOrder = []; this._iterationOrder = [];
for (var iterator = this._iterator; iterator.hasNext(); iterator.next()) for (var iterator = this._iterator; iterator.hasNext(); iterator.next())
this._iterationOrder.push(this._indexProvider.indexForItem(iterator.item())); this._iterationOrder.push(iterator.item().itemIndex());
}, },
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment