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

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: comments addressed. 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 this._json += chunk; 125 if (this._json !== null)
126 this._json += chunk;
126 while (true) { 127 while (true) {
127 switch (this._state) { 128 switch (this._state) {
128 case "find-snapshot-info": { 129 case "find-snapshot-info": {
129 var snapshotToken = "\"snapshot\""; 130 var snapshotToken = "\"snapshot\"";
130 var snapshotTokenIndex = this._json.indexOf(snapshotToken); 131 var snapshotTokenIndex = this._json.indexOf(snapshotToken);
131 if (snapshotTokenIndex === -1) 132 if (snapshotTokenIndex === -1)
132 throw new Error("Snapshot token not found"); 133 throw new Error("Snapshot token not found");
133 this._json = this._json.slice(snapshotTokenIndex + snapshotToken .length + 1); 134
135 var json = this._json.slice(snapshotTokenIndex + snapshotToken.l ength + 1);
134 this._state = "parse-snapshot-info"; 136 this._state = "parse-snapshot-info";
135 this._progress.updateStatus("Loading snapshot info\u2026"); 137 this._progress.updateStatus("Loading snapshot info\u2026");
138 this._json = null; // tokenizer takes over input.
139 this._jsonTokenizer = new WebInspector.TextUtils.BalancedJSONTok enizer(this._writeBalancedJSON.bind(this));
140 this._jsonTokenizer.write(json);
136 break; 141 break;
137 } 142 }
138 case "parse-snapshot-info": { 143 case "parse-snapshot-info": {
139 var closingBracketIndex = WebInspector.TextUtils.findBalancedCur lyBrackets(this._json); 144 this._jsonTokenizer.write(chunk);
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; 145 break;
146 } 146 }
147 case "find-nodes": { 147 case "find-nodes": {
148 var nodesToken = "\"nodes\""; 148 var nodesToken = "\"nodes\"";
149 var nodesTokenIndex = this._json.indexOf(nodesToken); 149 var nodesTokenIndex = this._json.indexOf(nodesToken);
150 if (nodesTokenIndex === -1) 150 if (nodesTokenIndex === -1)
151 return; 151 return;
152 var bracketIndex = this._json.indexOf("[", nodesTokenIndex); 152 var bracketIndex = this._json.indexOf("[", nodesTokenIndex);
153 if (bracketIndex === -1) 153 if (bracketIndex === -1)
154 return; 154 return;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 if (bracketIndex === -1) 258 if (bracketIndex === -1)
259 return; 259 return;
260 this._json = this._json.slice(bracketIndex); 260 this._json = this._json.slice(bracketIndex);
261 this._state = "accumulate-strings"; 261 this._state = "accumulate-strings";
262 break; 262 break;
263 } 263 }
264 case "accumulate-strings": 264 case "accumulate-strings":
265 return; 265 return;
266 } 266 }
267 } 267 }
268 },
269
270 /**
271 * @param {string} data
272 */
273 _writeBalancedJSON: function(data)
274 {
275 this._json = this._jsonTokenizer.remainder(); // tokenizer releases inp ut.
276 this._jsonTokenizer = null;
277 this._state = "find-nodes";
278 this._snapshot.snapshot = /** @type {!HeapSnapshotHeader} */ (JSON.parse (data));
268 } 279 }
269 }; 280 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698