Diff
Modified: trunk/Source/WebCore/ChangeLog (114879 => 114880)
--- trunk/Source/WebCore/ChangeLog 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/ChangeLog 2012-04-23 08:49:38 UTC (rev 114880)
@@ -1,3 +1,48 @@
+2012-04-23 Pavel Feldman <pfeld...@chromium.org>
+
+ Web Inspector: introduce String.prototype.starts/endsWith and use it all over the place.
+ https://bugs.webkit.org/show_bug.cgi?id=84574
+
+ Reviewed by Yury Semikhatsky.
+
+ * inspector/front-end/AuditRules.js:
+ (WebInspector.AuditRules.VendorPrefixedCSSProperties.prototype.visitProperty):
+ * inspector/front-end/BreakpointsSidebarPane.js:
+ (WebInspector.EventListenerBreakpointsSidebarPane.prototype._setBreakpoint):
+ (WebInspector.EventListenerBreakpointsSidebarPane.prototype._removeBreakpoint):
+ * inspector/front-end/CSSCompletions.js:
+ (WebInspector.CSSCompletions.prototype.startsWith):
+ (WebInspector.CSSCompletions.prototype._firstIndexOfPrefix):
+ * inspector/front-end/ConsoleView.js:
+ (WebInspector.ConsoleView.prototype._reportCompletions):
+ * inspector/front-end/CookieItemsView.js:
+ (WebInspector.Cookies.cookieMatchesResourceURL):
+ * inspector/front-end/DatabaseQueryView.js:
+ (WebInspector.DatabaseQueryView.prototype.completions):
+ * inspector/front-end/ElementsTreeOutline.js:
+ (WebInspector.ElementsTreeElement.prototype._buildAttributeDOM):
+ * inspector/front-end/ProfileView.js:
+ * inspector/front-end/ProfilesPanel.js:
+ (WebInspector.ProfilesPanel.prototype.addProfileHeader):
+ (WebInspector.ProfilesPanel.prototype.displayTitleForProfileLink):
+ (WebInspector.ProfileSidebarTreeElement):
+ (WebInspector.ProfileSidebarTreeElement.prototype.get mainTitle):
+ * inspector/front-end/ResourceUtils.js:
+ (WebInspector.ParsedURL):
+ (WebInspector.displayNameForURL):
+ (WebInspector.linkifyStringAsFragmentWithCustomLinkifier):
+ (WebInspector.completeURL):
+ * inspector/front-end/SnippetsModel.js:
+ (WebInspector.SnippetsModel.prototype.snippetIdForSourceURL):
+ * inspector/front-end/SourceCSSTokenizer.js:
+ (WebInspector.SourceCSSTokenizer.prototype.nextToken):
+ * inspector/front-end/SourceCSSTokenizer.re2js:
+ * inspector/front-end/TextPrompt.js:
+ (WebInspector.TextPrompt.prototype._completeCommonPrefix):
+ * inspector/front-end/UIUtils.js:
+ (WebInspector.startEditing):
+ * inspector/front-end/utilities.js:
+
2012-04-23 Andreas Kling <kl...@webkit.org>
REGRESSION(r114870): Performance hit on DOM/CloneNodes and DOM/CreateNodes.
Modified: trunk/Source/WebCore/inspector/front-end/AuditRules.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/AuditRules.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/AuditRules.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -1106,7 +1106,7 @@
visitProperty: function(styleSheet, property, result)
{
- if (property.name.indexOf(this._webkitPrefix) !== 0)
+ if (!property.name.startsWith(this._webkitPrefix))
return;
var normalPropertyName = property.name.substring(this._webkitPrefix.length).toLowerCase(); // Start just after the "-webkit-" prefix.
Modified: trunk/Source/WebCore/inspector/front-end/BreakpointsSidebarPane.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/BreakpointsSidebarPane.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/BreakpointsSidebarPane.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -576,9 +576,9 @@
if (!breakpointItem)
return;
breakpointItem.checkbox.checked = true;
- if (eventName.indexOf(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener) === 0)
+ if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener))
DOMDebuggerAgent.setEventListenerBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener.length));
- else if (eventName.indexOf(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation) === 0)
+ else if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation))
DOMDebuggerAgent.setInstrumentationBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation.length));
this._updateCategoryCheckbox(breakpointItem.parent);
},
@@ -589,9 +589,9 @@
if (!breakpointItem)
return;
breakpointItem.checkbox.checked = false;
- if (eventName.indexOf(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener) === 0)
+ if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener))
DOMDebuggerAgent.removeEventListenerBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyListener.length));
- else if (eventName.indexOf(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation) === 0)
+ else if (eventName.startsWith(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation))
DOMDebuggerAgent.removeInstrumentationBreakpoint(eventName.substring(WebInspector.EventListenerBreakpointsSidebarPane.categotyInstrumentation.length));
this._updateCategoryCheckbox(breakpointItem.parent);
},
Modified: trunk/Source/WebCore/inspector/front-end/CSSCompletions.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/CSSCompletions.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/CSSCompletions.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -64,7 +64,7 @@
return [];
var results = [];
- while (firstIndex < this._values.length && this._values[firstIndex].indexOf(prefix) === 0)
+ while (firstIndex < this._values.length && this._values[firstIndex].startsWith(prefix))
results.push(this._values[firstIndex++]);
return results;
},
@@ -88,7 +88,7 @@
do {
var middleIndex = (maxIndex + minIndex) >> 1;
- if (this._values[middleIndex].indexOf(prefix) === 0) {
+ if (this._values[middleIndex].startsWith(prefix)) {
foundIndex = middleIndex;
break;
}
@@ -101,7 +101,7 @@
if (foundIndex === undefined)
return -1;
- while (foundIndex && this._values[foundIndex - 1].indexOf(prefix) === 0)
+ while (foundIndex && this._values[foundIndex - 1].startsWith(prefix))
foundIndex--;
return foundIndex;
Modified: trunk/Source/WebCore/inspector/front-end/ConsoleView.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/ConsoleView.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/ConsoleView.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -471,7 +471,7 @@
if (property.length < prefix.length)
continue;
- if (prefix.length && property.indexOf(prefix) !== 0)
+ if (prefix.length && !property.startsWith(prefix))
continue;
results.push(property);
Modified: trunk/Source/WebCore/inspector/front-end/CookieItemsView.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/CookieItemsView.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/CookieItemsView.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -243,7 +243,7 @@
var url = ""
if (!url || !WebInspector.Cookies.cookieDomainMatchesResourceDomain(cookie.domain, url.host))
return false;
- return (url.path.indexOf(cookie.path) === 0
+ return (url.path.startsWith(cookie.path)
&& (!cookie.port || url.port == cookie.port)
&& (!cookie.secure || url.scheme === "https"));
}
Modified: trunk/Source/WebCore/inspector/front-end/DatabaseQueryView.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/DatabaseQueryView.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/DatabaseQueryView.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -75,7 +75,7 @@
var text = textArray[i].toLowerCase();
if (text.length < prefix.length)
continue;
- if (text.indexOf(prefix) !== 0)
+ if (!text.startsWith(prefix))
continue;
results.push(textArray[i]);
}
Modified: trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -1494,7 +1494,7 @@
var attrValueElement = attrSpanElement.createChild("span", "webkit-html-attribute-value");
attrValueElement.textContent = value;
} else {
- if (value.indexOf("data:") === 0)
+ if (value.startsWith("data:"))
value = value.trimMiddle(60);
attrSpanElement.appendChild(linkify(rewrittenHref, value, "webkit-html-attribute-value", node.nodeName().toLowerCase() === "a"));
}
Modified: trunk/Source/WebCore/inspector/front-end/ProfileView.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/ProfileView.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/ProfileView.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -221,9 +221,9 @@
this._searchFinishedCallback = finishedCallback;
- var greaterThan = (query.indexOf(">") === 0);
- var lessThan = (query.indexOf("<") === 0);
- var equalTo = (query.indexOf("=") === 0 || ((greaterThan || lessThan) && query.indexOf("=") === 1));
+ var greaterThan = (query.startsWith(">"));
+ var lessThan = (query.startsWith("<"));
+ var equalTo = (query.startsWith("=") || ((greaterThan || lessThan) && query.indexOf("=") === 1));
var percentUnits = (query.lastIndexOf("%") === (query.length - 1));
var millisecondsUnits = (query.length > 2 && query.lastIndexOf("ms") === (query.length - 2));
var secondsUnits = (!millisecondsUnits && query.lastIndexOf("s") === (query.length - 1));
Modified: trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -325,7 +325,7 @@
this._profiles.push(profile);
this._profilesIdMap[this._makeKey(profile.uid, typeId)] = profile;
- if (profile.title.indexOf(UserInitiatedProfileName) !== 0) {
+ if (!profile.title.startsWith(UserInitiatedProfileName)) {
var profileTitleKey = this._makeKey(profile.title, typeId);
if (!(profileTitleKey in this._profileGroups))
this._profileGroups[profileTitleKey] = [];
@@ -551,7 +551,7 @@
displayTitleForProfileLink: function(title, typeId)
{
title = unescape(title);
- if (title.indexOf(UserInitiatedProfileName) === 0) {
+ if (title.startsWith(UserInitiatedProfileName)) {
title = WebInspector.UIString("Profile %d", title.substring(UserInitiatedProfileName.length + 1));
} else {
var titleKey = this._makeKey(title, typeId);
@@ -940,7 +940,7 @@
this.profile = ""
this._titleFormat = titleFormat;
- if (this.profile.title.indexOf(UserInitiatedProfileName) === 0)
+ if (this.profile.title.startsWith(UserInitiatedProfileName))
this._profileNumber = this.profile.title.substring(UserInitiatedProfileName.length + 1);
WebInspector.SidebarTreeElement.call(this, className, "", "", profile, false);
@@ -965,7 +965,7 @@
{
if (this._mainTitle)
return this._mainTitle;
- if (this.profile.title.indexOf(UserInitiatedProfileName) === 0)
+ if (this.profile.title.startsWith(UserInitiatedProfileName))
return WebInspector.UIString(this._titleFormat, this._profileNumber);
return this.profile.title;
},
Modified: trunk/Source/WebCore/inspector/front-end/ResourceUtils.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/ResourceUtils.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/ResourceUtils.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -60,12 +60,6 @@
this.path = match[4] || "/";
this.fragment = match[5];
} else {
- if (this.url.indexOf("data:") == 0) {
- this.isValid = true;
- this.path = this.url;
- this.lastPathComponent = this.path;
- return;
- }
if (this.url == "about:blank") {
this.isValid = true;
this.scheme = "about";
@@ -170,7 +164,7 @@
var index = WebInspector.inspectedPageURL.indexOf(lastPathComponent);
if (index !== -1 && index + lastPathComponent.length === WebInspector.inspectedPageURL.length) {
var baseURL = WebInspector.inspectedPageURL.substring(0, index);
- if (url.indexOf(baseURL) === 0)
+ if (url.startsWith(baseURL))
return url.substring(index);
}
@@ -199,7 +193,7 @@
container.appendChild(document.createTextNode(nonLink));
var title = linkString;
- var realURL = (linkString.indexOf("www.") === 0 ? "http://" + linkString : linkString);
+ var realURL = (linkString.startsWith("www.") ? "http://" + linkString : linkString);
var lineColumnMatch = lineColumnRegEx.exec(realURL);
if (lineColumnMatch)
realURL = realURL.substring(0, realURL.length - lineColumnMatch[0].length);
@@ -335,7 +329,7 @@
if (!url || url.indexOf("://") > 0)
return url;
- if (url.trim().indexOf("_javascript_:") === 0)
+ if (url.trim().startsWith("_javascript_:"))
return null; // Do not provide a resource URL for security.
for (var frameOwnerCandidate = node; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
@@ -375,7 +369,7 @@
// Return special URLs as-is.
var trimmedHref = href.trim();
- if (trimmedHref.indexOf("data:") === 0 || trimmedHref.indexOf("_javascript_:") === 0)
+ if (trimmedHref.startsWith("data:") || trimmedHref.startsWith("_javascript_:"))
return href;
}
Modified: trunk/Source/WebCore/inspector/front-end/SnippetsModel.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/SnippetsModel.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/SnippetsModel.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -162,7 +162,7 @@
snippetIdForSourceURL: function(sourceURL)
{
var snippetsPrefix = WebInspector.SnippetsModel.snippetsSourceURLPrefix;
- if (sourceURL.indexOf(snippetsPrefix) !== 0)
+ if (!sourceURL.startsWith(snippetsPrefix))
return null;
var splittedURL = sourceURL.substring(snippetsPrefix.length).split("_");
var snippetId = splittedURL[0];
Modified: trunk/Source/WebCore/inspector/front-end/SourceCSSTokenizer.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/SourceCSSTokenizer.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/SourceCSSTokenizer.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -395,7 +395,7 @@
if (token === "@media") {
this.tokenType = "css-at-rule";
this._condition.parseCondition = this._parseConditions.AT_MEDIA_RULE;
- } else if (token.indexOf("@") === 0) {
+ } else if (token.startsWith("@")) {
this.tokenType = "css-at-rule";
this._condition.parseCondition = this._parseConditions.AT_RULE;
} else
Modified: trunk/Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/SourceCSSTokenizer.re2js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -269,7 +269,7 @@
if (token === "@media") {
this.tokenType = "css-at-rule";
this._condition.parseCondition = this._parseConditions.AT_MEDIA_RULE;
- } else if (token.indexOf("@") === 0) {
+ } else if (token.startsWith("@")) {
this.tokenType = "css-at-rule";
this._condition.parseCondition = this._parseConditions.AT_RULE;
} else
Modified: trunk/Source/WebCore/inspector/front-end/TextPrompt.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/TextPrompt.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/TextPrompt.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -511,7 +511,7 @@
_completeCommonPrefix: function()
{
- if (!this.autoCompleteElement || !this._commonPrefix || !this._userEnteredText || this._commonPrefix.indexOf(this._userEnteredText) !== 0)
+ if (!this.autoCompleteElement || !this._commonPrefix || !this._userEnteredText || !this._commonPrefix.startsWith(this._userEnteredText))
return;
if (!this.isSuggestBoxVisible()) {
Modified: trunk/Source/WebCore/inspector/front-end/UIUtils.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/UIUtils.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/UIUtils.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -359,7 +359,7 @@
} else if (result === "cancel") {
editingCancelled.call(element);
event.consume(true);
- } else if (result && result.indexOf("move-") === 0) {
+ } else if (result && result.startsWith("move-")) {
moveDirection = result.substring(5);
if (event.keyIdentifier !== "U+0009")
blurEventListener();
Modified: trunk/Source/WebCore/inspector/front-end/utilities.js (114879 => 114880)
--- trunk/Source/WebCore/inspector/front-end/utilities.js 2012-04-23 08:40:07 UTC (rev 114879)
+++ trunk/Source/WebCore/inspector/front-end/utilities.js 2012-04-23 08:49:38 UTC (rev 114880)
@@ -127,6 +127,16 @@
return this.substring(0, fragmentIndex);
}
+String.prototype.startsWith = function(substring)
+{
+ return !this.lastIndexOf(substring, 0);
+}
+
+String.prototype.endsWith = function(substring)
+{
+ return this.indexOf(substring, this.length - substring.length) !== -1;
+}
+
Number.constrain = function(num, min, max)
{
if (num < min)