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

Unified Diff: Source/devtools/front_end/common/TextUtils.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: fixed the load test. 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/common/TextUtils.js
diff --git a/Source/devtools/front_end/common/TextUtils.js b/Source/devtools/front_end/common/TextUtils.js
index 5f7f05feaa355bfc845f677c522679db4dd179d7..12c47459a403b6c56d61582a597bcad5e1c464ff 100644
--- a/Source/devtools/front_end/common/TextUtils.js
+++ b/Source/devtools/front_end/common/TextUtils.js
@@ -121,45 +121,6 @@ WebInspector.TextUtils = {
},
/**
- * @param {string} source
- * @param {number=} startIndex
- * @param {number=} lastIndex
- * @return {number}
- */
- findBalancedCurlyBrackets: function(source, startIndex, lastIndex)
- {
- // The function is performance sensitive.
- lastIndex = lastIndex || source.length;
- startIndex = startIndex || 0;
- var counter = 0;
-
- var index = startIndex;
- while (index < lastIndex) {
- // This part counts brackets until end of string or a double quote.
- for (; index < lastIndex; ++index) {
- var character = source[index];
- if (character === "\"")
- break;
- else if (character === "{")
- ++counter;
- else if (character === "}") {
- if (--counter === 0)
- return index + 1;
- }
- }
- if (index === lastIndex)
- return -1;
- // This part seeks the closing double quote which could have even number of back slashes prefix.
- var regexp = WebInspector.TextUtils._ClosingDoubleQuoteRegexp;
- regexp.lastIndex = index;
- if (!regexp.test(source))
- return -1;
- index = regexp.lastIndex;
- }
- return -1;
- },
-
- /**
* @param {string} line
* @return {string}
*/
@@ -191,7 +152,6 @@ WebInspector.TextUtils = {
}
WebInspector.TextUtils._SpaceCharRegex = /\s/;
-WebInspector.TextUtils._ClosingDoubleQuoteRegexp = /[^\\](?:\\\\)*"/g;
/**
* @enum {string}
@@ -202,3 +162,67 @@ WebInspector.TextUtils.Indent = {
EightSpaces: " ",
TabCharacter: "\t"
}
+
+/**
+ * @constructor
+ * @param {function(string)} callback
+ * @param {boolean=} findMultiple
+ */
+WebInspector.TextUtils.BalancedJSONTokenizer = function(callback, findMultiple)
+{
+ this._callback = callback;
+ this._index = 0;
+ this._balance = 0;
+ this._buffer = "";
+ this._findMultiple = findMultiple || false;
+ this._closingDoubleQuoteRegex = /[^\\](?:\\\\)*"/g;
+}
+
+WebInspector.TextUtils.BalancedJSONTokenizer.prototype = {
+ /**
+ * @param {string} chunk
+ */
+ write: function(chunk)
+ {
+ this._buffer += chunk;
+ var lastIndex = this._buffer.length;
+ var buffer = this._buffer;
+ for (var index = this._index; index < lastIndex; ++index) {
+ var character = buffer[index];
+ if (character === "\"") {
+ this._closingDoubleQuoteRegex.lastIndex = index;
+ if (!this._closingDoubleQuoteRegex.test(buffer))
+ break;
+ index = this._closingDoubleQuoteRegex.lastIndex - 1;
+ } else if (character === "{") {
+ ++this._balance;
+ } else if (character === "}") {
+ if (--this._balance === 0) {
+ this._lastBalancedIndex = index + 1;
+ if (!this._findMultiple)
+ break;
+ }
+ }
+ }
+ this._index = index;
+ this._reportBalanced();
+ },
+
+ _reportBalanced: function()
+ {
+ if (!this._lastBalancedIndex)
+ return;
+ this._callback(this._buffer.slice(0, this._lastBalancedIndex));
+ this._buffer = this._buffer.slice(this._lastBalancedIndex);
+ this._index -= this._lastBalancedIndex;
+ this._lastBalancedIndex = 0;
+ },
+
+ /**
+ * @return {string}
+ */
+ remainder: function()
+ {
+ return this._buffer;
+ }
+}
« no previous file with comments | « Source/devtools/front_end/common/Progress.js ('k') | Source/devtools/front_end/heap_snapshot_worker/HeapSnapshotLoader.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698