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

Unified Diff: Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js

Issue 967853002: DevTools: n^2 -> n while loading heap snapshots and timeline files. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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
Index: Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js
diff --git a/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js b/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js
index 8285fa8ccf5f2cd96e53bed43dbf46c16d8e2616..82b8f43b681af68cdb89bc96c785d609bae54ff4 100644
--- a/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js
+++ b/Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js
@@ -122,6 +122,12 @@ WebInspector.HeapSnapshotLoader.prototype = {
*/
write: function(chunk)
{
+ if (this._state === "parse-snapshot-info") {
alph 2015/03/01 11:30:13 looks like a hack to the state machine. why not ju
pfeldman 2015/03/01 12:18:53 Done.
+ // Tokenizer takes over input.
+ this._jsonTokenizer.write(chunk);
+ return;
+ }
+
this._json += chunk;
while (true) {
switch (this._state) {
@@ -130,18 +136,16 @@ WebInspector.HeapSnapshotLoader.prototype = {
var snapshotTokenIndex = this._json.indexOf(snapshotToken);
if (snapshotTokenIndex === -1)
throw new Error("Snapshot token not found");
+
this._json = this._json.slice(snapshotTokenIndex + snapshotToken.length + 1);
this._state = "parse-snapshot-info";
this._progress.updateStatus("Loading snapshot info\u2026");
+ this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTokenizer(this._writeBalancedJSON.bind(this));
+ this._jsonTokenizer.write(this._json);
break;
}
case "parse-snapshot-info": {
- var closingBracketIndex = WebInspector.TextUtils.findBalancedCurlyBrackets(this._json);
- if (closingBracketIndex === -1)
- return;
- this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse(this._json.slice(0, closingBracketIndex)));
- this._json = this._json.slice(closingBracketIndex);
- this._state = "find-nodes";
+ console.assert(false, "This should nevet happen.")
alph 2015/03/01 11:30:14 typo
pfeldman 2015/03/01 12:18:53 Done.
break;
}
case "find-nodes": {
@@ -265,5 +269,16 @@ WebInspector.HeapSnapshotLoader.prototype = {
return;
}
}
+ },
+
+ /**
+ * @param {string} data
+ */
+ _writeBalancedJSON: function(data)
+ {
+ this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse(data));
+ this._json = this._jsonTokenizer.remainder();
+ this._jsonTokenizer = null;
+ this._state = "find-nodes";
}
-};
+}

Powered by Google App Engine
This is Rietveld 408576698