Replace usages of Vector<UChar> with existing StringBuilder
https://bugs.webkit.org/show_bug.cgi?id=67079
Patch by Xianzhu Wang <wangxianzhu@chromium.org> on 2011-09-06
Reviewed by Gavin Barraclough.
Source/JavaScriptCore:
This is part of work to support 8-bit string buffers.
Adds StringBuilder::characters() because the original Vector<UChar>::data()
is widely used.
Sets the minimum size of buffer to 16 to prevent possible performance
regression. Further performance investigation should be done in
https://bugs.webkit.org/show_bug.cgi?id=67084.
* wtf/Forward.h:
* wtf/text/StringBuilder.cpp:
(WTF::StringBuilder::appendUninitialized): Sets minimum buffer size to 16 bytes.
* wtf/text/StringBuilder.h:
(WTF::StringBuilder::operator[]):
(WTF::StringBuilder::characters): Added.
Source/WebCore:
No new tests. All existing unit tests and layout tests should run
as before.
* css/CSSOMUtils.cpp:
(WebCore::appendCharacter):
(WebCore::serializeCharacter):
(WebCore::serializeCharacterAsCodePoint):
(WebCore::serializeIdentifier):
(WebCore::serializeString):
* css/CSSOMUtils.h:
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::cssText):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::SelectorChecker::determineLinkStateSlowCase):
* css/CSSWrapShapes.cpp:
(WebCore::CSSWrapShapeRect::cssText):
(WebCore::CSSWrapShapeCircle::cssText):
(WebCore::CSSWrapShapeEllipse::cssText):
(WebCore::CSSWrapShapePolygon::cssText):
* editing/HTMLInterchange.cpp:
(WebCore::convertHTMLTextToInterchangeFormat):
* editing/MarkupAccumulator.cpp:
(WebCore::appendCharactersReplacingEntities):
(WebCore::MarkupAccumulator::serializeNodes):
(WebCore::MarkupAccumulator::appendStartTag):
(WebCore::MarkupAccumulator::appendEndTag):
(WebCore::MarkupAccumulator::concatenateMarkup):
(WebCore::MarkupAccumulator::appendAttributeValue):
(WebCore::MarkupAccumulator::appendCustomAttributes):
(WebCore::MarkupAccumulator::appendQuotedURLAttributeValue):
(WebCore::MarkupAccumulator::appendNodeValue):
(WebCore::MarkupAccumulator::appendNamespace):
(WebCore::MarkupAccumulator::appendText):
(WebCore::MarkupAccumulator::appendComment):
(WebCore::MarkupAccumulator::appendDocumentType):
(WebCore::MarkupAccumulator::appendProcessingInstruction):
(WebCore::MarkupAccumulator::appendElement):
(WebCore::MarkupAccumulator::appendOpenTag):
(WebCore::MarkupAccumulator::appendCloseTag):
(WebCore::MarkupAccumulator::appendAttribute):
(WebCore::MarkupAccumulator::appendCDATASection):
(WebCore::MarkupAccumulator::appendStartMarkup):
(WebCore::MarkupAccumulator::appendEndMarkup):
* editing/MarkupAccumulator.h:
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::appendElement):
(WebCore::StyledMarkupAccumulator::wrapWithNode):
(WebCore::StyledMarkupAccumulator::wrapWithStyleNode):
(WebCore::StyledMarkupAccumulator::appendStyleNodeOpenTag):
(WebCore::StyledMarkupAccumulator::takeResults):
(WebCore::StyledMarkupAccumulator::appendText):
(WebCore::urlToMarkup):
* html/DOMTokenList.cpp:
(WebCore::DOMTokenList::removeToken):
* html/HTMLFontElement.cpp:
(WebCore::parseFontSize):
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::strippedPlaceholder):
* html/parser/CSSPreloadScanner.cpp:
(WebCore::CSSPreloadScanner::emitRule):
* html/parser/CSSPreloadScanner.h:
* html/parser/HTMLEntityParser.cpp:
(WebCore::consumeHTMLEntity):
* html/parser/HTMLEntityParser.h:
* html/parser/HTMLParserIdioms.cpp:
(WebCore::parseHTMLInteger):
(WebCore::parseHTMLNonNegativeInteger):
* html/parser/HTMLTokenizer.cpp:
(WebCore::HTMLTokenizer::processEntity):
(WebCore::HTMLTokenizer::nextToken):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::ExternalCharacterTokenBuffer::giveRemainingTo):
(WebCore::HTMLTreeBuilder::defaultForInTableText):
* html/parser/HTMLTreeBuilder.h:
* inspector/InspectorValues.cpp:
(WebCore::InspectorValue::toJSONString):
(WebCore::InspectorValue::writeJSON):
(WebCore::InspectorBasicValue::writeJSON):
(WebCore::InspectorString::writeJSON):
(WebCore::InspectorObject::writeJSON):
(WebCore::InspectorArray::writeJSON):
* inspector/InspectorValues.h:
* loader/CrossOriginAccessControl.cpp:
(WebCore::createAccessControlPreflightRequest):
* loader/appcache/ApplicationCacheStorage.cpp:
(WebCore::ApplicationCacheStorage::store):
* page/Chrome.cpp:
(WebCore::Chrome::setToolTip):
* page/PageSerializer.cpp:
(WebCore::SerializerMarkupAccumulator::appendText):
(WebCore::SerializerMarkupAccumulator::appendElement):
(WebCore::SerializerMarkupAccumulator::appendCustomAttributes):
* page/SecurityOrigin.cpp:
(WebCore::SecurityOrigin::toString):
* platform/KURL.cpp:
(WebCore::KURL::deprecatedString):
(WebCore::decodeURLEscapeSequences):
* platform/LinkHash.cpp:
(WebCore::squeezeOutNullCharacters):
(WebCore::cleanSlashDotDotSlashes):
(WebCore::mergeDoubleSlashes):
(WebCore::cleanSlashDotSlashes):
(WebCore::cleanPath):
(WebCore::visitedURLInline):
(WebCore::visitedURL):
(WebCore::visitedLinkHash):
* platform/LinkHash.h:
* platform/gtk/DataObjectGtk.cpp:
(WebCore::DataObjectGtk::setURL):
* platform/network/HTTPParsers.cpp:
(WebCore::extractMIMETypeFromMediaType):
* platform/text/TextCodecICU.cpp:
(WebCore::TextCodecICU::decode):
* platform/text/TextStream.cpp:
(WebCore::TextStream::operator<<):
(WebCore::TextStream::release):
* platform/text/TextStream.h:
* plugins/PluginStream.cpp:
(WebCore::PluginStream::startStream):
* rendering/InlineTextBox.cpp:
(WebCore::adjustCharactersAndLengthForHyphen):
* rendering/InlineTextBox.h:
(WebCore::BufferForAppendingHyphen::BufferForAppendingHyphen):
* rendering/RenderListItem.cpp:
(WebCore::RenderListItem::markerTextWithSuffix):
* rendering/RenderListMarker.cpp:
(WebCore::toSymbolic):
(WebCore::RenderListMarker::paint):
(WebCore::RenderListMarker::suffix):
* rendering/RenderTreeAsText.cpp:
(WebCore::quoteAndEscapeNonPrintables):
* rendering/mathml/RenderMathMLFenced.cpp:
(WebCore::RenderMathMLFenced::updateFromElement):
* storage/IDBLevelDBCoding.cpp:
(WebCore::IDBLevelDBCoding::decodeString):
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::getAllResponseHeaders):
* xml/XPathFunctions.cpp:
(WebCore::XPath::FunId::evaluate):
(WebCore::XPath::FunConcat::evaluate):
* xml/XPathUtil.cpp:
(WebCore::XPath::stringValue):
* xml/XSLTProcessorLibxslt.cpp:
(WebCore::writeToStringBuilder):
(WebCore::saveResultToString):
* xml/parser/CharacterReferenceParserInlineMethods.h:
(WebCore::unconsumeCharacters):
(WebCore::consumeCharacterReference):
* xml/parser/XMLCharacterReferenceParser.cpp:
(WebCore::consumeXMLCharacterReference):
* xml/parser/XMLCharacterReferenceParser.h:
* xml/parser/XMLTokenizer.cpp:
(WebCore::XMLTokenizer::nextToken):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@94640 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/xml/XPathFunctions.cpp b/Source/WebCore/xml/XPathFunctions.cpp
index d343a59..8336de9 100644
--- a/Source/WebCore/xml/XPathFunctions.cpp
+++ b/Source/WebCore/xml/XPathFunctions.cpp
@@ -38,6 +38,7 @@
#include "XPathUtil.h"
#include "XPathValue.h"
#include <wtf/MathExtras.h>
+#include <wtf/text/StringBuilder.h>
namespace WebCore {
namespace XPath {
@@ -318,26 +319,26 @@
Value FunId::evaluate() const
{
Value a = arg(0)->evaluate();
- Vector<UChar> idList; // A whitespace-separated list of IDs
+ StringBuilder idList; // A whitespace-separated list of IDs
if (a.isNodeSet()) {
const NodeSet& nodes = a.toNodeSet();
for (size_t i = 0; i < nodes.size(); ++i) {
String str = stringValue(nodes[i]);
- idList.append(str.characters(), str.length());
+ idList.append(str);
idList.append(' ');
}
} else {
String str = a.toString();
- idList.append(str.characters(), str.length());
+ idList.append(str);
}
TreeScope* contextScope = evaluationContext().node->treeScope();
NodeSet result;
HashSet<Node*> resultSet;
- size_t startPos = 0;
- size_t length = idList.size();
+ unsigned startPos = 0;
+ unsigned length = idList.length();
while (true) {
while (startPos < length && isWhitespace(idList[startPos]))
++startPos;
@@ -351,7 +352,7 @@
// If there are several nodes with the same id, id() should return the first one.
// In WebKit, getElementById behaves so, too, although its behavior in this case is formally undefined.
- Node* node = contextScope->getElementById(String(&idList[startPos], endPos - startPos));
+ Node* node = contextScope->getElementById(String(idList.characters() + startPos, endPos - startPos));
if (node && resultSet.add(node).second)
result.append(node);
@@ -436,15 +437,16 @@
Value FunConcat::evaluate() const
{
- Vector<UChar, 1024> result;
+ StringBuilder result;
+ result.reserveCapacity(1024);
unsigned count = argCount();
for (unsigned i = 0; i < count; ++i) {
String str(arg(i)->evaluate().toString());
- result.append(str.characters(), str.length());
+ result.append(str);
}
- return String(result.data(), result.size());
+ return result.toString();
}
Value FunStartsWith::evaluate() const