Title: [114843] trunk/Source/WebCore
- Revision
- 114843
- Author
- [email protected]
- Date
- 2012-04-21 09:43:25 -0700 (Sat, 21 Apr 2012)
Log Message
Improve performance of removing user and password from URLs
https://bugs.webkit.org/show_bug.cgi?id=84525
Reviewed by Dan Bernstein.
Performance improvement only. Correctness covered by existing regression tests.
The most common use of KURL::setUser and KURL::setPass, by far, is to remove
the user and password from a URL that already has neither. Optimize this by
not re-parsing the URL in that case.
* platform/KURL.cpp:
(WebCore::KURL::setUser): Restructure code so that the code path that removes
the user does no work when there is nothing to remove. Otherwise, leave the
logic of the function untouched.
(WebCore::KURL::setPass): Same thing, only for password rather than user.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (114842 => 114843)
--- trunk/Source/WebCore/ChangeLog 2012-04-21 10:46:53 UTC (rev 114842)
+++ trunk/Source/WebCore/ChangeLog 2012-04-21 16:43:25 UTC (rev 114843)
@@ -1,3 +1,22 @@
+2012-04-21 Darin Adler <[email protected]>
+
+ Improve performance of removing user and password from URLs
+ https://bugs.webkit.org/show_bug.cgi?id=84525
+
+ Reviewed by Dan Bernstein.
+
+ Performance improvement only. Correctness covered by existing regression tests.
+
+ The most common use of KURL::setUser and KURL::setPass, by far, is to remove
+ the user and password from a URL that already has neither. Optimize this by
+ not re-parsing the URL in that case.
+
+ * platform/KURL.cpp:
+ (WebCore::KURL::setUser): Restructure code so that the code path that removes
+ the user does no work when there is nothing to remove. Otherwise, leave the
+ logic of the function untouched.
+ (WebCore::KURL::setPass): Same thing, only for password rather than user.
+
2012-04-20 Sheriff Bot <[email protected]>
Unreviewed, rolling out r114768.
Modified: trunk/Source/WebCore/platform/KURL.cpp (114842 => 114843)
--- trunk/Source/WebCore/platform/KURL.cpp 2012-04-21 10:46:53 UTC (rev 114842)
+++ trunk/Source/WebCore/platform/KURL.cpp 2012-04-21 16:43:25 UTC (rev 114843)
@@ -762,21 +762,24 @@
// FIXME: Non-ASCII characters must be encoded and escaped to match parse() expectations,
// and to avoid changing more than just the user login.
- String u;
+
int end = m_userEnd;
if (!user.isEmpty()) {
- u = user;
+ String u = user;
if (m_userStart == m_schemeEnd + 1)
u = "//" + u;
// Add '@' if we didn't have one before.
if (end == m_hostEnd || (end == m_passwordEnd && m_string[end] != '@'))
u.append('@');
+ parse(m_string.left(m_userStart) + u + m_string.substring(end));
} else {
// Remove '@' if we now have neither user nor password.
if (m_userEnd == m_passwordEnd && end != m_hostEnd && m_string[end] == '@')
end += 1;
+ // We don't want to parse in the extremely common case where we are not going to make a change.
+ if (m_userStart != end)
+ parse(m_string.left(m_userStart) + m_string.substring(end));
}
- parse(m_string.left(m_userStart) + u + m_string.substring(end));
}
void KURL::setPass(const String& password)
@@ -786,21 +789,24 @@
// FIXME: Non-ASCII characters must be encoded and escaped to match parse() expectations,
// and to avoid changing more than just the user password.
- String p;
+
int end = m_passwordEnd;
if (!password.isEmpty()) {
- p = ":" + password + "@";
+ String p = ":" + password + "@";
if (m_userEnd == m_schemeEnd + 1)
p = "//" + p;
// Eat the existing '@' since we are going to add our own.
if (end != m_hostEnd && m_string[end] == '@')
end += 1;
+ parse(m_string.left(m_userEnd) + p + m_string.substring(end));
} else {
// Remove '@' if we now have neither user nor password.
if (m_userStart == m_userEnd && end != m_hostEnd && m_string[end] == '@')
end += 1;
+ // We don't want to parse in the extremely common case where we are not going to make a change.
+ if (m_userEnd != end)
+ parse(m_string.left(m_userEnd) + m_string.substring(end));
}
- parse(m_string.left(m_userEnd) + p + m_string.substring(end));
}
void KURL::setFragmentIdentifier(const String& s)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes