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

Unified Diff: third_party/WebKit/Source/devtools/front_end/script_formatter_worker/CSSFormatter.js

Issue 1809533003: DevTools: remove illusionary caching from String.prototype.lineEndings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/script_formatter_worker/CSSFormatter.js
diff --git a/third_party/WebKit/Source/devtools/front_end/script_formatter_worker/CSSFormatter.js b/third_party/WebKit/Source/devtools/front_end/script_formatter_worker/CSSFormatter.js
index 865d91fd55f2c9d544e7a0b1652ce3bb55b0c63e..0709f518de48228fa3f4de4d8a6c348b8c27b3ee 100644
--- a/third_party/WebKit/Source/devtools/front_end/script_formatter_worker/CSSFormatter.js
+++ b/third_party/WebKit/Source/devtools/front_end/script_formatter_worker/CSSFormatter.js
@@ -36,6 +36,7 @@
FormatterWorker.CSSFormatter = function(content, builder)
{
this._content = content;
+ this._lineEndings = this._content.lineEndings();
this._builder = builder;
this._lastLine = -1;
this._state = {};
@@ -45,22 +46,19 @@ FormatterWorker.CSSFormatter.prototype = {
format: function()
{
var tokenize = FormatterWorker.createTokenizer("text/css");
- var lines = this._content.split("\n");
-
- for (var i = 0; i < lines.length; ++i) {
- var line = lines[i];
- tokenize(line, this._tokenCallback.bind(this, i));
- }
+ tokenize(this._content, this._tokenCallback.bind(this));
},
/**
- * @param {number} startLine
* @param {string} token
* @param {?string} type
- * @param {number} startColumn
+ * @param {number} startPosition
+ * @param {number} endPosition
*/
- _tokenCallback: function(startLine, token, type, startColumn)
+ _tokenCallback: function(token, type, startPosition, endPosition)
{
+ var startLine = this._lineEndings.lowerBound(startPosition);
+ var endLine = this._lineEndings.lowerBound(endPosition);
if (startLine !== this._lastLine)
this._state.eatWhitespace = true;
if (/^property/.test(type) && !this._state.inPropertyValue)
@@ -81,8 +79,6 @@ FormatterWorker.CSSFormatter.prototype = {
this._builder.addNewLine(true);
this._state.afterClosingBrace = false;
}
- var startPosition = this._content.offsetFromPosition(startLine, startColumn);
- var endLine = startLine + token.lineCount() - 1;
if (token === "}") {
if (this._state.inPropertyValue)
this._builder.addNewLine();

Powered by Google App Engine
This is Rietveld 408576698