Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1597)

Unified Diff: third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js

Issue 2379523002: DevTools: Remove recursion in ProfileTreeModel._calculateTotals (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/profiler/cpu-profiler-calculate-time.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js b/third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js
index 5ceb738dea1fd3d800b7b1685e409932dc1989c8..b8206f4e4d0e159a5fd14aacbc9ba1a4d0edfb64 100644
--- a/third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/ProfileTreeModel.js
@@ -73,8 +73,8 @@ WebInspector.ProfileNode.prototype = {
WebInspector.ProfileTreeModel = function(root)
{
this.root = root;
- this.total = this._calculateTotals(this.root);
this._assignDepthsAndParents();
+ this.total = this._calculateTotals(this.root);
}
WebInspector.ProfileTreeModel.prototype = {
@@ -103,12 +103,23 @@ WebInspector.ProfileTreeModel.prototype = {
},
/**
- * @param {!WebInspector.ProfileNode} node
+ * @param {!WebInspector.ProfileNode} root
* @return {number}
*/
- _calculateTotals: function(node)
+ _calculateTotals: function(root)
{
- node.total = node.children.reduce((acc, child) => acc + this._calculateTotals(child), node.self);
- return node.total;
+ var nodesToTraverse = [root];
+ var dfsList = [];
+ while (nodesToTraverse.length) {
+ var node = nodesToTraverse.pop();
+ node.total = node.self;
+ dfsList.push(node);
+ nodesToTraverse.push(...node.children);
+ }
+ while (dfsList.length > 1) {
+ var node = dfsList.pop();
+ node.parent.total += node.total;
+ }
+ return root.total;
}
}
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/profiler/cpu-profiler-calculate-time.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698