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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 throw new Error("Incomplete JSON"); 115 throw new Error("Incomplete JSON");
116 this._json = this._json.slice(0, closingBracketIndex + 1); 116 this._json = this._json.slice(0, closingBracketIndex + 1);
117 this._snapshot.strings = JSON.parse(this._json); 117 this._snapshot.strings = JSON.parse(this._json);
118 }, 118 },
119 119
120 /** 120 /**
121 * @param {string} chunk 121 * @param {string} chunk
122 */ 122 */
123 write: function(chunk) 123 write: function(chunk)
124 { 124 {
125 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.
126 // Tokenizer takes over input.
127 this._jsonTokenizer.write(chunk);
128 return;
129 }
130
125 this._json += chunk; 131 this._json += chunk;
126 while (true) { 132 while (true) {
127 switch (this._state) { 133 switch (this._state) {
128 case "find-snapshot-info": { 134 case "find-snapshot-info": {
129 var snapshotToken = "\"snapshot\""; 135 var snapshotToken = "\"snapshot\"";
130 var snapshotTokenIndex = this._json.indexOf(snapshotToken); 136 var snapshotTokenIndex = this._json.indexOf(snapshotToken);
131 if (snapshotTokenIndex === -1) 137 if (snapshotTokenIndex === -1)
132 throw new Error("Snapshot token not found"); 138 throw new Error("Snapshot token not found");
139
133 this._json = this._json.slice(snapshotTokenIndex + snapshotToken .length + 1); 140 this._json = this._json.slice(snapshotTokenIndex + snapshotToken .length + 1);
134 this._state = "parse-snapshot-info"; 141 this._state = "parse-snapshot-info";
135 this._progress.updateStatus("Loading snapshot info\u2026"); 142 this._progress.updateStatus("Loading snapshot info\u2026");
143 this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTok enizer(this._writeBalancedJSON.bind(this));
144 this._jsonTokenizer.write(this._json);
136 break; 145 break;
137 } 146 }
138 case "parse-snapshot-info": { 147 case "parse-snapshot-info": {
139 var closingBracketIndex = WebInspector.TextUtils.findBalancedCur lyBrackets(this._json); 148 console.assert(false, "This should nevet happen.")
alph 2015/03/01 11:30:14 typo
pfeldman 2015/03/01 12:18:53 Done.
140 if (closingBracketIndex === -1)
141 return;
142 this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JS ON.parse(this._json.slice(0, closingBracketIndex)));
143 this._json = this._json.slice(closingBracketIndex);
144 this._state = "find-nodes";
145 break; 149 break;
146 } 150 }
147 case "find-nodes": { 151 case "find-nodes": {
148 var nodesToken = "\"nodes\""; 152 var nodesToken = "\"nodes\"";
149 var nodesTokenIndex = this._json.indexOf(nodesToken); 153 var nodesTokenIndex = this._json.indexOf(nodesToken);
150 if (nodesTokenIndex === -1) 154 if (nodesTokenIndex === -1)
151 return; 155 return;
152 var bracketIndex = this._json.indexOf("[", nodesTokenIndex); 156 var bracketIndex = this._json.indexOf("[", nodesTokenIndex);
153 if (bracketIndex === -1) 157 if (bracketIndex === -1)
154 return; 158 return;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 if (bracketIndex === -1) 262 if (bracketIndex === -1)
259 return; 263 return;
260 this._json = this._json.slice(bracketIndex); 264 this._json = this._json.slice(bracketIndex);
261 this._state = "accumulate-strings"; 265 this._state = "accumulate-strings";
262 break; 266 break;
263 } 267 }
264 case "accumulate-strings": 268 case "accumulate-strings":
265 return; 269 return;
266 } 270 }
267 } 271 }
272 },
273
274 /**
275 * @param {string} data
276 */
277 _writeBalancedJSON: function(data)
278 {
279 this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse (data));
280 this._json = this._jsonTokenizer.remainder();
281 this._jsonTokenizer = null;
282 this._state = "find-nodes";
268 } 283 }
269 }; 284 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698