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

Unified Diff: Source/core/editing/htmlediting.cpp

Issue 21262003: Remove String::adopt(Vector<UChar>) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix typo Created 7 years, 5 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
« no previous file with comments | « Source/bindings/v8/SerializedScriptValue.cpp ('k') | Source/core/page/EventSource.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/htmlediting.cpp
diff --git a/Source/core/editing/htmlediting.cpp b/Source/core/editing/htmlediting.cpp
index 756ee454b249255888de4db3c30eabdac2189af1..5a399f1995e3ab490c54ef29cf072a99243474bf 100644
--- a/Source/core/editing/htmlediting.cpp
+++ b/Source/core/editing/htmlediting.cpp
@@ -52,6 +52,7 @@
#include "core/rendering/RenderObject.h"
#include "wtf/Assertions.h"
#include "wtf/StdLibExtras.h"
+#include "wtf/text/StringBuilder.h"
#include "wtf/unicode/CharacterNames.h"
using namespace std;
@@ -355,27 +356,32 @@ int lastOffsetForEditing(const Node* node)
String stringWithRebalancedWhitespace(const String& string, bool startIsStartOfParagraph, bool endIsEndOfParagraph)
{
- Vector<UChar> rebalancedString;
- append(rebalancedString, string);
+ unsigned length = string.length();
+
+ StringBuilder rebalancedString;
+ rebalancedString.reserveCapacity(length);
bool previousCharacterWasSpace = false;
- for (size_t i = 0; i < rebalancedString.size(); i++) {
- if (!isWhitespace(rebalancedString[i])) {
+ for (size_t i = 0; i < length; i++) {
+ UChar c = string[i];
+ if (!isWhitespace(c)) {
+ rebalancedString.append(c);
previousCharacterWasSpace = false;
continue;
}
- if (previousCharacterWasSpace || (!i && startIsStartOfParagraph) || (i + 1 == rebalancedString.size() && endIsEndOfParagraph)) {
- rebalancedString[i] = noBreakSpace;
+ if (previousCharacterWasSpace || (!i && startIsStartOfParagraph) || (i + 1 == length && endIsEndOfParagraph)) {
+ rebalancedString.append(noBreakSpace);
previousCharacterWasSpace = false;
} else {
- rebalancedString[i] = ' ';
+ rebalancedString.append(' ');
previousCharacterWasSpace = true;
}
-
}
- return String::adopt(rebalancedString);
+ ASSERT(rebalancedString.length() == length);
+
+ return rebalancedString.toString();
}
bool isTableStructureNode(const Node *node)
« no previous file with comments | « Source/bindings/v8/SerializedScriptValue.cpp ('k') | Source/core/page/EventSource.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698