Title: [120850] trunk/Source/WebCore
- Revision
- 120850
- Author
- [email protected]
- Date
- 2012-06-20 12:33:02 -0700 (Wed, 20 Jun 2012)
Log Message
Regression(r116408): Ctrl-A (select all) on large text file hangs the tab with high CPU usage
https://bugs.webkit.org/show_bug.cgi?id=89562
Reviewed by Ryosuke Niwa.
Rather than replace the newlines in-place (in O(n^2)), build a new string using StringBuilder, which takes O(n).
No new tests, this is a perf improvement.
* platform/chromium/ClipboardUtilitiesChromium.cpp:
(WebCore::replaceNewlinesWithWindowsStyleNewlines):
* platform/win/ClipboardUtilitiesWin.cpp:
(WebCore::replaceNewlinesWithWindowsStyleNewlines):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (120849 => 120850)
--- trunk/Source/WebCore/ChangeLog 2012-06-20 19:28:50 UTC (rev 120849)
+++ trunk/Source/WebCore/ChangeLog 2012-06-20 19:33:02 UTC (rev 120850)
@@ -1,3 +1,19 @@
+2012-06-20 Tony Chang <[email protected]>
+
+ Regression(r116408): Ctrl-A (select all) on large text file hangs the tab with high CPU usage
+ https://bugs.webkit.org/show_bug.cgi?id=89562
+
+ Reviewed by Ryosuke Niwa.
+
+ Rather than replace the newlines in-place (in O(n^2)), build a new string using StringBuilder, which takes O(n).
+
+ No new tests, this is a perf improvement.
+
+ * platform/chromium/ClipboardUtilitiesChromium.cpp:
+ (WebCore::replaceNewlinesWithWindowsStyleNewlines):
+ * platform/win/ClipboardUtilitiesWin.cpp:
+ (WebCore::replaceNewlinesWithWindowsStyleNewlines):
+
2012-06-20 Elliott Sprehn <[email protected]>
Add support for fit-content etc
Modified: trunk/Source/WebCore/platform/chromium/ClipboardUtilitiesChromium.cpp (120849 => 120850)
--- trunk/Source/WebCore/platform/chromium/ClipboardUtilitiesChromium.cpp 2012-06-20 19:28:50 UTC (rev 120849)
+++ trunk/Source/WebCore/platform/chromium/ClipboardUtilitiesChromium.cpp 2012-06-20 19:33:02 UTC (rev 120850)
@@ -36,6 +36,7 @@
#include "PlatformString.h"
#include <public/WebClipboard.h>
+#include <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -50,19 +51,14 @@
void replaceNewlinesWithWindowsStyleNewlines(String& str)
{
DEFINE_STATIC_LOCAL(String, windowsNewline, ("\r\n"));
- const static unsigned windowsNewlineLength = windowsNewline.length();
-
- unsigned index = 0;
- unsigned strLength = str.length();
- while (index < strLength) {
- if (str[index] != '\n' || (index > 0 && str[index - 1] == '\r')) {
- ++index;
- continue;
- }
- str.replace(index, 1, windowsNewline);
- strLength = str.length();
- index += windowsNewlineLength;
+ StringBuilder result;
+ for (unsigned index = 0; index < str.length(); ++index) {
+ if (str[index] != '\n' || (index > 0 && str[index - 1] == '\r'))
+ result.append(str[index]);
+ else
+ result.append(windowsNewline);
}
+ str = result.toString();
}
#endif
Modified: trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp (120849 => 120850)
--- trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp 2012-06-20 19:28:50 UTC (rev 120849)
+++ trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp 2012-06-20 19:33:02 UTC (rev 120850)
@@ -35,6 +35,7 @@
#include <wininet.h> // for INTERNET_MAX_URL_LENGTH
#include <wtf/StringExtras.h>
#include <wtf/text/CString.h>
+#include <wtf/text/StringBuilder.h>
#include <wtf/text/WTFString.h>
#if USE(CF)
@@ -299,19 +300,14 @@
void replaceNewlinesWithWindowsStyleNewlines(String& str)
{
DEFINE_STATIC_LOCAL(String, windowsNewline, ("\r\n"));
- const static unsigned windowsNewlineLength = windowsNewline.length();
-
- unsigned index = 0;
- unsigned strLength = str.length();
- while (index < strLength) {
- if (str[index] != '\n' || (index > 0 && str[index - 1] == '\r')) {
- ++index;
- continue;
- }
- str.replace(index, 1, windowsNewline);
- strLength = str.length();
- index += windowsNewlineLength;
+ StringBuilder result;
+ for (unsigned index = 0; index < str.length(); ++index) {
+ if (str[index] != '\n' || (index > 0 && str[index - 1] == '\r'))
+ result.append(str[index]);
+ else
+ result.append(windowsNewline);
}
+ str = result.toString();
}
void replaceNBSPWithSpace(String& str)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes