Title: [121035] branches/chromium/1180/Source/WebCore/platform
- Revision
- 121035
- Author
- [email protected]
- Date
- 2012-06-22 10:40:14 -0700 (Fri, 22 Jun 2012)
Log Message
Merge 120850 - 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):
[email protected]
Review URL: https://chromiumcodereview.appspot.com/10626020
Modified Paths
Diff
Modified: branches/chromium/1180/Source/WebCore/platform/chromium/ClipboardUtilitiesChromium.cpp (121034 => 121035)
--- branches/chromium/1180/Source/WebCore/platform/chromium/ClipboardUtilitiesChromium.cpp 2012-06-22 17:11:21 UTC (rev 121034)
+++ branches/chromium/1180/Source/WebCore/platform/chromium/ClipboardUtilitiesChromium.cpp 2012-06-22 17:40:14 UTC (rev 121035)
@@ -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: branches/chromium/1180/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp (121034 => 121035)
--- branches/chromium/1180/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp 2012-06-22 17:11:21 UTC (rev 121034)
+++ branches/chromium/1180/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp 2012-06-22 17:40:14 UTC (rev 121035)
@@ -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