Changeset 86330 in webkit


Ignore:
Timestamp:
May 12, 2011 5:07:24 AM (13 years ago)
Author:
Nikolas Zimmermann
Message:

2011-05-12 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Darin Adler.

String operator+ reallocates unnecessarily when concatting > 2 strings
https://bugs.webkit.org/show_bug.cgi?id=58420

Provide a faster String append operator.
Up until now, "String operator+(const String& a, const String& b)" copied String a into a temporary
object, and used a.append(b), which reallocates a new buffer of aLength+bLength. When concatting
N strings using operator+, this leads to N-1 reallocations.

Replace this with a flexible operator+ implementation, that avoids these reallocations.
When concatting a 'String' with any string type (char*, UChar, Vector<char>, String, AtomicString, etc..)
a StringAppend<String, T> object is created, which holds the intermediate string objects, and delays
creation of the final string, until operator String() is invoked.

template<typename T>
StringAppend<String, T> operator+(const String& string1, T string2)
{

return StringAppend<String, T>(string1, string2);

}

template<typename U, typename V, typename W>
StringAppend<U, StringAppend<V, W> > operator+(U string1, const StringAppend<V, W>& string2)
{

return StringAppend<U, StringAppend<V, W> >(string1, string2);

}

When concatting three strings - "String a, b, c; String result = a + b + c;" following happens:
first a StringAppend<String, String> object is created by operator+(const String& string1, String string2).
Then operator+(String string1, const StringAppend<String, String>& string2) is invoked, which returns
a StringAppend<String, StringAppend<String, String> > object.
Then operator String() is invoked, which allocates a StringImpl object, once, large enough to hold the
final string - it uses tryMakeString provided by StringConcatenate.h under the hoods, which guards us
against too big string allocations, etc.

Note that the second template, defines a recursive way to concat an arbitary number of strings
into a single String with just one allocation.

  • GNUmakefile.list.am: Add StringOperators.h to build.
  • JavaScriptCore.exp: Export WTF::emptyString(). Remove no longer needed symbols.
  • JavaScriptCore.gypi: Add StringOperators.h to build.
  • JavaScriptCore.vcproj/WTF/WTF.vcproj: Ditto.
  • JavaScriptCore.xcodeproj/project.pbxproj: Ditto.
  • wtf/text/AtomicString.h: Pull in StringConcatenate.h at the end of the file.
  • wtf/text/StringConcatenate.h: Conditionally include AtomicString.h to avoid a cyclic dependency. Pull in StringOperators.h at the end of the file.
  • wtf/text/StringOperators.h: Added. This is never meant to be included directly, including either WTFString.h or AtomicString.h automatically pulls in this file. (WTF::StringAppend::StringAppend): (WTF::StringAppend::operator String): (WTF::StringAppend::operator AtomicString): (WTF::StringAppend::writeTo): (WTF::StringAppend::length): (WTF::operator+):
  • wtf/text/WTFString.cpp: Remove operator+ implementations that use String::append(). (WTF::emptyString): Add new shared empty string free function.
  • wtf/text/WTFString.h: Replace operator+ implementations by StringAppend template solution. Pull in AtomicString.h at the end of the file.

2011-05-12 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Darin Adler.

String operator+ reallocates unnecessary when concatting > 2 strings
https://bugs.webkit.org/show_bug.cgi?id=58420

Provide a faster String append operator. See Source/JavaScriptCore/ChangeLog for details.

  • dom/XMLDocumentParserLibxml2.cpp: (WebCore::handleElementAttributes):
  • editing/MarkupAccumulator.cpp: (WebCore::MarkupAccumulator::shouldAddNamespaceElement):
  • html/HTMLAnchorElement.cpp: (WebCore::HTMLAnchorElement::hash): (WebCore::HTMLAnchorElement::search):
  • html/ImageInputType.cpp: (WebCore::ImageInputType::appendFormData):
  • html/parser/HTMLTreeBuilder.cpp:
  • loader/CrossOriginAccessControl.cpp: (WebCore::passesAccessControlCheck):
  • page/Location.cpp: (WebCore::Location::search): (WebCore::Location::hash):
  • page/NavigatorBase.cpp: (WebCore::NavigatorBase::platform):
  • platform/chromium/ClipboardChromium.cpp: (WebCore::writeImageToDataObject):
  • platform/gtk/PasteboardHelper.cpp: (WebCore::PasteboardHelper::fillSelectionData):
  • platform/network/cf/ResourceHandleCFNet.cpp: (WebCore::encodeBasicAuthorization):
  • platform/network/cf/SocketStreamHandleCFNet.cpp: (WebCore::SocketStreamHandle::copyCFStreamDescription):
  • platform/network/mac/ResourceHandleMac.mm: (WebCore::encodeBasicAuthorization):
  • workers/WorkerLocation.cpp: (WebCore::WorkerLocation::search): (WebCore::WorkerLocation::hash):

2011-05-12 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Darin Adler.

String operator+ reallocates unnecessarily when concatting > 2 strings
https://bugs.webkit.org/show_bug.cgi?id=58420

Provide a faster String append operator. See Source/JavaScriptCore/ChangeLog for details.

  • src/WebAccessibilityObject.cpp: (WebKit::WebAccessibilityObject::keyboardShortcut): Cast to String first, before trying to convert to platform dependant type.
  • src/WebHTTPLoadInfo.cpp: (WebKit::addHeader): Don't pass WebString to makeString, explicit cast to String first.
  • tests/IDBLevelDBCodingTest.cpp: Cast to String first, to avoid conflicting with gtests global templatified operator+. (IDBLevelDBCoding::TEST):

2011-05-12 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Darin Adler.

String operator+ reallocates unnecessarily when concatting > 2 strings
https://bugs.webkit.org/show_bug.cgi?id=58420

Provide a faster String append operator. See Source/JavaScriptCore/ChangeLog for details.

  • WebView/WebFrame.mm: Explicitely cast to Strings first, so operator NSString*() can be invoked. (-[WebFrame _stringWithDocumentTypeStringAndMarkupString:]):

2011-05-12 Nikolas Zimmermann <nzimmermann@rim.com>

Reviewed by Darin Adler.

String operator+ reallocates unnecessarily when concatting > 2 strings
https://bugs.webkit.org/show_bug.cgi?id=58420

Provide a faster String append operator. See Source/JavaScriptCore/ChangeLog for details.

  • AccessibleBase.cpp: (AccessibleBase::get_accKeyboardShortcut): Explicitely cast to Strings first, so operator BString() can be invoked.
Location:
trunk/Source
Files:
1 added
33 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r86318 r86330  
     12011-05-12  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        String operator+ reallocates unnecessarily when concatting > 2 strings
     6        https://bugs.webkit.org/show_bug.cgi?id=58420
     7
     8        Provide a faster String append operator.
     9        Up until now, "String operator+(const String& a, const String& b)" copied String a into a temporary
     10        object, and used a.append(b), which reallocates a new buffer of aLength+bLength. When concatting
     11        N strings using operator+, this leads to N-1 reallocations.
     12
     13        Replace this with a flexible operator+ implementation, that avoids these reallocations.
     14        When concatting a 'String' with any string type (char*, UChar, Vector<char>, String, AtomicString, etc..)
     15        a StringAppend<String, T> object is created, which holds the intermediate string objects, and delays
     16        creation of the final string, until operator String() is invoked.
     17
     18        template<typename T>
     19        StringAppend<String, T> operator+(const String& string1, T string2)
     20        {
     21            return StringAppend<String, T>(string1, string2);
     22        }
     23
     24        template<typename U, typename V, typename W>
     25        StringAppend<U, StringAppend<V, W> > operator+(U string1, const StringAppend<V, W>& string2)
     26        {
     27            return StringAppend<U, StringAppend<V, W> >(string1, string2);
     28        }
     29
     30        When concatting three strings - "String a, b, c; String result = a + b + c;" following happens:
     31        first a StringAppend<String, String> object is created by operator+(const String& string1, String string2).
     32        Then operator+(String string1, const StringAppend<String, String>& string2) is invoked, which returns
     33        a StringAppend<String, StringAppend<String, String> > object.
     34        Then operator String() is invoked, which allocates a StringImpl object, once, large enough to hold the
     35        final string - it uses tryMakeString provided by StringConcatenate.h under the hoods, which guards us
     36        against too big string allocations, etc.
     37
     38        Note that the second template, defines a recursive way to concat an arbitary number of strings
     39        into a single String with just one allocation.
     40
     41        * GNUmakefile.list.am: Add StringOperators.h to build.
     42        * JavaScriptCore.exp: Export WTF::emptyString(). Remove no longer needed symbols.
     43        * JavaScriptCore.gypi: Add StringOperators.h to build.
     44        * JavaScriptCore.vcproj/WTF/WTF.vcproj: Ditto.
     45        * JavaScriptCore.xcodeproj/project.pbxproj: Ditto.
     46        * wtf/text/AtomicString.h: Pull in StringConcatenate.h at the end of the file.
     47        * wtf/text/StringConcatenate.h: Conditionally include AtomicString.h to avoid a cyclic dependency. Pull in StringOperators.h at the end of the file.
     48        * wtf/text/StringOperators.h: Added. This is never meant to be included directly, including either WTFString.h or AtomicString.h automatically pulls in this file.
     49        (WTF::StringAppend::StringAppend):
     50        (WTF::StringAppend::operator String):
     51        (WTF::StringAppend::operator AtomicString):
     52        (WTF::StringAppend::writeTo):
     53        (WTF::StringAppend::length):
     54        (WTF::operator+):
     55        * wtf/text/WTFString.cpp: Remove operator+ implementations that use String::append().
     56        (WTF::emptyString): Add new shared empty string free function.
     57        * wtf/text/WTFString.h: Replace operator+ implementations by StringAppend template solution. Pull in AtomicString.h at the end of the file.
     58
    1592011-05-12  Philippe Normand  <pnormand@igalia.com>
    260
  • trunk/Source/JavaScriptCore/GNUmakefile.list.am

    r86209 r86330  
    526526        Source/JavaScriptCore/wtf/text/StringImpl.cpp \
    527527        Source/JavaScriptCore/wtf/text/StringImpl.h \
     528        Source/JavaScriptCore/wtf/text/StringOperators.h \
    528529        Source/JavaScriptCore/wtf/text/StringStatics.cpp \
    529530        Source/JavaScriptCore/wtf/text/TextPosition.h \
  • trunk/Source/JavaScriptCore/JavaScriptCore.exp

    r86300 r86330  
    373373__ZN3WTF11OSAllocator18releaseDecommittedEPvm
    374374__ZN3WTF11commentAtomE
     375__ZN3WTF11emptyStringEv
    375376__ZN3WTF11currentTimeEv
    376377__ZN3WTF11dtoaRoundDPEPcdiRbRiRj
     
    511512__ZN3WTFeqERKNS_12AtomicStringERKNS_6VectorItLm0EEE
    512513__ZN3WTFeqERKNS_7CStringES2_
    513 __ZN3WTFplEPKcRKNS_6StringE
    514 __ZN3WTFplERKNS_6StringEPKc
    515 __ZN3WTFplERKNS_6StringES2_
    516514__ZNK3JSC10JSFunction23isHostFunctionNonInlineEv
    517515__ZNK3JSC11Interpreter14retrieveCallerEPNS_9ExecStateEPNS_10JSFunctionE
  • trunk/Source/JavaScriptCore/JavaScriptCore.gypi

    r86209 r86330  
    225225            'wtf/text/StringImpl.h',
    226226            'wtf/text/StringImplBase.h',
     227            'wtf/text/StringOperators.h',
    227228            'wtf/text/TextPosition.h',
    228229            'wtf/text/WTFString.h',
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj

    r85253 r86330  
    497497                        </File>
    498498                        <File
     499                                RelativePath="..\..\wtf\text\StringOperators.h"
     500                                >
     501                        </File>
     502                        <File
    499503                                RelativePath="..\..\wtf\text\StringStatics.cpp"
    500504                                >
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r86209 r86330  
    224224                65FDE49C0BDD1D4A00E80111 /* Assertions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65E217B808E7EECC0023E5F6 /* Assertions.cpp */; };
    225225                7186A6EC13100BA5004479E1 /* HexNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = 7186A6E813100B57004479E1 /* HexNumber.h */; settings = {ATTRIBUTES = (Private, ); }; };
     226                71DA9D82134F3F3D00B767E7 /* StringOperators.h in Headers */ = {isa = PBXBuildFile; fileRef = 718A8482134F3A1200B87529 /* StringOperators.h */; settings = {ATTRIBUTES = (Private, ); }; };
    226227                76FB9F0F12E851860051A2EB /* SHA1.h in Headers */ = {isa = PBXBuildFile; fileRef = 76FB9F0E12E851860051A2EB /* SHA1.h */; settings = {ATTRIBUTES = (Private, ); }; };
    227228                76FB9F1112E851960051A2EB /* SHA1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76FB9F1012E851960051A2EB /* SHA1.cpp */; };
     
    910911                704FD35305697E6D003DBED9 /* BooleanObject.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = BooleanObject.h; sourceTree = "<group>"; tabWidth = 8; };
    911912                7186A6E813100B57004479E1 /* HexNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HexNumber.h; sourceTree = "<group>"; };
     913                718A8482134F3A1200B87529 /* StringOperators.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StringOperators.h; path = text/StringOperators.h; sourceTree = "<group>"; };
    912914                76FB9F0E12E851860051A2EB /* SHA1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SHA1.h; sourceTree = "<group>"; };
    913915                76FB9F1012E851960051A2EB /* SHA1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SHA1.cpp; sourceTree = "<group>"; };
     
    20332035                                868BFA07117CEFD100B908B1 /* StringImpl.h */,
    20342036                                86B99AE2117E578100DF5A90 /* StringImplBase.h */,
     2037                                718A8482134F3A1200B87529 /* StringOperators.h */,
    20352038                                8626BECE11928E3900782FAB /* StringStatics.cpp */,
    20362039                                F3BD31D0126730180065467F /* TextPosition.h */,
     
    25302533                                868BFA0F117CEFD100B908B1 /* StringImpl.h in Headers */,
    25312534                                86B99AE4117E578100DF5A90 /* StringImplBase.h in Headers */,
     2535                                71DA9D82134F3F3D00B767E7 /* StringOperators.h in Headers */,
    25322536                                BC18C4680E16F5CD00B34460 /* StringObject.h in Headers */,
    25332537                                BC18C4690E16F5CD00B34460 /* StringObjectThatMasqueradesAsUndefined.h in Headers */,
  • trunk/Source/JavaScriptCore/wtf/text/AtomicString.h

    r83407 r86330  
    202202#endif
    203203
     204#include "StringConcatenate.h"
    204205#endif // AtomicString_h
  • trunk/Source/JavaScriptCore/wtf/text/StringConcatenate.h

    r82931 r86330  
    2727#define StringConcatenate_h
    2828
    29 #include <wtf/text/WTFString.h>
     29#ifndef WTFString_h
     30#include "AtomicString.h"
     31#endif
    3032
    3133namespace WTF {
     
    183185private:
    184186    const String& m_buffer;
     187};
     188
     189template<>
     190class StringTypeAdapter<AtomicString> {
     191public:
     192    StringTypeAdapter<AtomicString>(const AtomicString& string)
     193        : m_adapter(string.string())
     194    {
     195    }
     196
     197    unsigned length() { return m_adapter.length(); }
     198    void writeTo(UChar* destination) { m_adapter.writeTo(destination); }
     199
     200private:
     201    StringTypeAdapter<String> m_adapter;
    185202};
    186203
     
    581598using WTF::makeString;
    582599
     600#include "StringOperators.h"
    583601#endif
  • trunk/Source/JavaScriptCore/wtf/text/WTFString.cpp

    r80012 r86330  
    132132}
    133133
    134 String operator+(const String& a, const String& b)
    135 {
    136     if (a.isEmpty())
    137         return b;
    138     if (b.isEmpty())
    139         return a;
    140     String c = a;
    141     c += b;
    142     return c;
    143 }
    144 
    145 String operator+(const String& s, const char* cs)
    146 {
    147     return s + String(cs);
    148 }
    149 
    150 String operator+(const char* cs, const String& s)
    151 {
    152     return String(cs) + s;
    153 }
    154 
    155134int codePointCompare(const String& a, const String& b)
    156135{
     
    972951}
    973952
     953const String& emptyString()
     954{
     955    DEFINE_STATIC_LOCAL(String, emptyString, (StringImpl::empty()));
     956    return emptyString;
     957}
     958
    974959} // namespace WTF
    975960
  • trunk/Source/JavaScriptCore/wtf/text/WTFString.h

    r83637 r86330  
    357357#endif
    358358
    359 String operator+(const String&, const String&);
    360 String operator+(const String&, const char*);
    361 String operator+(const char*, const String&);
    362 
    363359inline String& operator+=(String& a, const String& b) { a.append(b); return a; }
    364360
     
    502498template <> struct VectorTraits<String> : SimpleClassVectorTraits { };
    503499
     500// Shared global empty string.
     501const String& emptyString();
     502
    504503}
    505504
    506505using WTF::CString;
    507506using WTF::String;
     507using WTF::emptyString;
    508508using WTF::append;
    509509using WTF::appendNumber;
     
    529529using WTF::reverseFind;
    530530
    531 #endif
     531#include "AtomicString.h"
     532#endif
  • trunk/Source/WebCore/ChangeLog

    r86327 r86330  
     12011-05-12  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        String operator+ reallocates unnecessary when concatting > 2 strings
     6        https://bugs.webkit.org/show_bug.cgi?id=58420
     7
     8        Provide a faster String append operator. See Source/JavaScriptCore/ChangeLog for details.
     9
     10        * dom/XMLDocumentParserLibxml2.cpp:
     11        (WebCore::handleElementAttributes):
     12        * editing/MarkupAccumulator.cpp:
     13        (WebCore::MarkupAccumulator::shouldAddNamespaceElement):
     14        * html/HTMLAnchorElement.cpp:
     15        (WebCore::HTMLAnchorElement::hash):
     16        (WebCore::HTMLAnchorElement::search):
     17        * html/ImageInputType.cpp:
     18        (WebCore::ImageInputType::appendFormData):
     19        * html/parser/HTMLTreeBuilder.cpp:
     20        * loader/CrossOriginAccessControl.cpp:
     21        (WebCore::passesAccessControlCheck):
     22        * page/Location.cpp:
     23        (WebCore::Location::search):
     24        (WebCore::Location::hash):
     25        * page/NavigatorBase.cpp:
     26        (WebCore::NavigatorBase::platform):
     27        * platform/chromium/ClipboardChromium.cpp:
     28        (WebCore::writeImageToDataObject):
     29        * platform/gtk/PasteboardHelper.cpp:
     30        (WebCore::PasteboardHelper::fillSelectionData):
     31        * platform/network/cf/ResourceHandleCFNet.cpp:
     32        (WebCore::encodeBasicAuthorization):
     33        * platform/network/cf/SocketStreamHandleCFNet.cpp:
     34        (WebCore::SocketStreamHandle::copyCFStreamDescription):
     35        * platform/network/mac/ResourceHandleMac.mm:
     36        (WebCore::encodeBasicAuthorization):
     37        * workers/WorkerLocation.cpp:
     38        (WebCore::WorkerLocation::search):
     39        (WebCore::WorkerLocation::hash):
     40
    1412011-05-06  Yury Semikhatsky  <yurys@chromium.org>
    242
  • trunk/Source/WebCore/dom/XMLDocumentParserLibxml2.cpp

    r85800 r86330  
    740740        String attrPrefix = toString(attributes[i].prefix);
    741741        AtomicString attrURI = attrPrefix.isEmpty() ? AtomicString() : toAtomicString(attributes[i].uri);
    742         AtomicString attrQName = attrPrefix.isEmpty() ? toAtomicString(attributes[i].localname) : AtomicString(attrPrefix + ":" + toString(attributes[i].localname));
     742        AtomicString attrQName = attrPrefix.isEmpty() ? toAtomicString(attributes[i].localname) : attrPrefix + ":" + toString(attributes[i].localname);
    743743
    744744        newElement->setAttributeNS(attrURI, attrQName, attrValue, ec, scriptingPermission);
  • trunk/Source/WebCore/editing/MarkupAccumulator.cpp

    r85244 r86330  
    211211    // Don't add namespace attribute if it is already defined for this elem.
    212212    const AtomicString& prefix = element->prefix();
    213     AtomicString attr = !prefix.isEmpty() ? "xmlns:" + prefix : "xmlns";
    214     return !element->hasAttribute(attr);
     213    if (prefix.isEmpty())
     214        return !element->hasAttribute(xmlnsAtom);
     215
     216    DEFINE_STATIC_LOCAL(String, xmlnsWithColon, ("xmlns:"));
     217    return !element->hasAttribute(xmlnsWithColon + prefix);
    215218}
    216219
  • trunk/Source/WebCore/html/HTMLAnchorElement.cpp

    r85484 r86330  
    306306{
    307307    String fragmentIdentifier = href().fragmentIdentifier();
    308     return fragmentIdentifier.isEmpty() ? "" : "#" + fragmentIdentifier;
     308    return fragmentIdentifier.isEmpty() ? emptyString() : "#" + fragmentIdentifier;
    309309}
    310310
     
    443443{
    444444    String query = href().query();
    445     return query.isEmpty() ? "" : "?" + query;
     445    return query.isEmpty() ? emptyString() : "?" + query;
    446446}
    447447
  • trunk/Source/WebCore/html/ImageInputType.cpp

    r74895 r86330  
    5858        return false;
    5959    const AtomicString& name = element()->name();
    60     encoding.appendData(name.isEmpty() ? "x" : (name + ".x"), m_clickLocation.x());
    61     encoding.appendData(name.isEmpty() ? "y" : (name + ".y"), m_clickLocation.y());
    62     if (!name.isEmpty() && !element()->value().isEmpty())
     60    if (name.isEmpty()) {
     61        encoding.appendData("x", m_clickLocation.x());
     62        encoding.appendData("y", m_clickLocation.y());
     63        return true;
     64    }
     65
     66    DEFINE_STATIC_LOCAL(String, dotXString, (".x"));
     67    DEFINE_STATIC_LOCAL(String, dotYString, (".y"));
     68    encoding.appendData(name + dotXString, m_clickLocation.x());
     69    encoding.appendData(name + dotYString, m_clickLocation.y());
     70
     71    if (!!element()->value().isEmpty())
    6372        encoding.appendData(name, element()->value());
    6473    return true;
  • trunk/Source/WebCore/html/parser/HTMLTreeBuilder.cpp

    r85903 r86330  
    670670        QualifiedName* name = names[i];
    671671        const AtomicString& localName = name->localName();
    672         AtomicString prefixColonLocalName(prefix + ":" + localName);
     672        AtomicString prefixColonLocalName = prefix + ':' + localName;
    673673        QualifiedName nameWithPrefix(prefix, localName, name->namespaceURI());
    674674        map->add(prefixColonLocalName, nameWithPrefix);
  • trunk/Source/WebCore/loader/CrossOriginAccessControl.cpp

    r73447 r86330  
    110110    RefPtr<SecurityOrigin> accessControlOrigin = SecurityOrigin::createFromString(accessControlOriginString);
    111111    if (!accessControlOrigin->isSameSchemeHostPort(securityOrigin)) {
    112         errorDescription = (accessControlOriginString == "*") ? "Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true."
    113             : "Origin " + securityOrigin->toString() + " is not allowed by Access-Control-Allow-Origin.";
     112        if (accessControlOriginString == "*")
     113            errorDescription = "Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.";
     114        else
     115            errorDescription =  "Origin " + securityOrigin->toString() + " is not allowed by Access-Control-Allow-Origin.";
    114116        return false;
    115117    }
  • trunk/Source/WebCore/page/Location.cpp

    r85484 r86330  
    121121
    122122    const KURL& url = this->url();
    123     return url.query().isEmpty() ? "" : "?" + url.query();
     123    return url.query().isEmpty() ? emptyString() : "?" + url.query();
    124124}
    125125
     
    137137
    138138    const String& fragmentIdentifier = url().fragmentIdentifier();
    139     return fragmentIdentifier.isEmpty() ? "" : "#" + fragmentIdentifier;
     139    return fragmentIdentifier.isEmpty() ? emptyString() : "#" + fragmentIdentifier;
    140140}
    141141
  • trunk/Source/WebCore/page/NavigatorBase.cpp

    r85300 r86330  
    8787{
    8888#if OS(LINUX)
    89     if (String("") != WEBCORE_NAVIGATOR_PLATFORM)
     89    if (!String(WEBCORE_NAVIGATOR_PLATFORM).isEmpty())
    9090        return WEBCORE_NAVIGATOR_PLATFORM;
    9191    struct utsname osname;
    92     DEFINE_STATIC_LOCAL(String, platformName, (uname(&osname) >= 0 ? String(osname.sysname) + String(" ") + String(osname.machine) : ""));
     92    DEFINE_STATIC_LOCAL(String, platformName, (uname(&osname) >= 0 ? String(osname.sysname) + String(" ") + String(osname.machine) : emptyString()));
    9393    return platformName;
    9494#else
  • trunk/Source/WebCore/platform/chromium/ClipboardChromium.cpp

    r85064 r86330  
    231231    String extension = MIMETypeRegistry::getPreferredExtensionForMIMEType(
    232232        cachedImage->response().mimeType());
    233     dataObject->setFileExtension(extension.isEmpty() ? "" : "." + extension);
     233    dataObject->setFileExtension(extension.isEmpty() ? emptyString() : "." + extension);
    234234    String title = element->getAttribute(altAttr);
    235235    if (title.isEmpty())
  • trunk/Source/WebCore/platform/gtk/PasteboardHelper.cpp

    r75009 r86330  
    163163        // Some Linux applications refuse to accept pasted markup unless it is
    164164        // prefixed by a content-type meta tag.
    165         CString markup = (gMarkupPrefix + dataObject->markup()).utf8();
     165        CString markup = String(gMarkupPrefix + dataObject->markup()).utf8();
    166166        gtk_selection_data_set(selectionData, markupAtom, 8,
    167167            reinterpret_cast<const guchar*>(markup.data()), markup.length() + 1);
  • trunk/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp

    r86285 r86330  
    127127static String encodeBasicAuthorization(const String& user, const String& password)
    128128{
    129     return base64Encode((user + ":" + password).utf8());
     129    return base64Encode(String(user + ":" + password).utf8());
    130130}
    131131
  • trunk/Source/WebCore/platform/network/cf/SocketStreamHandleCFNet.cpp

    r85036 r86330  
    373373{
    374374    SocketStreamHandle* handle = static_cast<SocketStreamHandle*>(info);
    375     return ("WebKit socket stream, " + handle->m_url.string()).createCFString();
     375    return String("WebKit socket stream, " + handle->m_url.string()).createCFString();
    376376}
    377377
  • trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm

    r86309 r86330  
    140140static String encodeBasicAuthorization(const String& user, const String& password)
    141141{
    142     return base64Encode((user + ":" + password).utf8());
     142    return base64Encode(String(user + ":" + password).utf8());
    143143}
    144144
  • trunk/Source/WebCore/workers/WorkerLocation.cpp

    r57101 r86330  
    6767String WorkerLocation::search() const
    6868{
    69     return m_url.query().isEmpty() ? "" : "?" + m_url.query();
     69    return m_url.query().isEmpty() ? emptyString() : "?" + m_url.query();
    7070}
    7171
    7272String WorkerLocation::hash() const
    7373{
    74     return m_url.fragmentIdentifier().isEmpty() ? "" : "#" + m_url.fragmentIdentifier();
     74    return m_url.fragmentIdentifier().isEmpty() ? emptyString() : "#" + m_url.fragmentIdentifier();
    7575}
    7676
  • trunk/Source/WebKit/chromium/ChangeLog

    r86325 r86330  
     12011-05-12  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        String operator+ reallocates unnecessarily when concatting > 2 strings
     6        https://bugs.webkit.org/show_bug.cgi?id=58420
     7
     8        Provide a faster String append operator. See Source/JavaScriptCore/ChangeLog for details.
     9
     10        * src/WebAccessibilityObject.cpp:
     11        (WebKit::WebAccessibilityObject::keyboardShortcut): Cast to String first, before trying to convert to platform dependant type.
     12        * src/WebHTTPLoadInfo.cpp:
     13        (WebKit::addHeader): Don't pass WebString to makeString, explicit cast to String first.
     14        * tests/IDBLevelDBCodingTest.cpp: Cast to String first, to avoid conflicting with gtests global templatified operator+.
     15        (IDBLevelDBCoding::TEST):
     16
    1172011-05-10  Tony Gentilcore  <tonyg@chromium.org>
    218
  • trunk/Source/WebKit/chromium/src/WebAccessibilityObject.cpp

    r80890 r86330  
    424424    }
    425425
    426     return modifierString + accessKey;
     426    return String(modifierString + accessKey);
    427427}
    428428
  • trunk/Source/WebKit/chromium/src/WebHTTPLoadInfo.cpp

    r83987 r86330  
    106106    pair<HTTPHeaderMap::iterator, bool> result = map->add(name, value);
    107107    if (!result.second)
    108         result.first->second += String("\n") + value;
     108        result.first->second += "\n" + String(value);
    109109}
    110110
  • trunk/Source/WebKit/chromium/tests/IDBLevelDBCodingTest.cpp

    r85844 r86330  
    181181
    182182    v = encodeString(String(testStringA));
    183     EXPECT_EQ(testStringA, decodeString(v.data(), v.data() + v.size()));
     183    EXPECT_EQ(String(testStringA), decodeString(v.data(), v.data() + v.size()));
    184184
    185185    v = encodeString(String(testStringB));
    186     EXPECT_EQ(testStringB, decodeString(v.data(), v.data() + v.size()));
     186    EXPECT_EQ(String(testStringB), decodeString(v.data(), v.data() + v.size()));
    187187}
    188188
  • trunk/Source/WebKit/mac/ChangeLog

    r86325 r86330  
     12011-05-12  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        String operator+ reallocates unnecessarily when concatting > 2 strings
     6        https://bugs.webkit.org/show_bug.cgi?id=58420
     7
     8        Provide a faster String append operator. See Source/JavaScriptCore/ChangeLog for details.
     9
     10        * WebView/WebFrame.mm: Explicitely cast to Strings first, so operator NSString*() can be invoked.
     11        (-[WebFrame _stringWithDocumentTypeStringAndMarkupString:]):
     12
    1132011-05-10  Tony Gentilcore  <tonyg@chromium.org>
    214
  • trunk/Source/WebKit/mac/WebView/WebFrame.mm

    r86325 r86330  
    494494- (NSString *)_stringWithDocumentTypeStringAndMarkupString:(NSString *)markupString
    495495{
    496     return _private->coreFrame->documentTypeString() + markupString;
     496    return String(_private->coreFrame->documentTypeString() + String(markupString));
    497497}
    498498
  • trunk/Source/WebKit/win/AccessibleBase.cpp

    r82120 r86330  
    376376            accessKeyModifiers += "Win+";
    377377    }
    378     *shortcut = BString(accessKeyModifiers + accessKey).release();
     378    *shortcut = BString(String(accessKeyModifiers + accessKey)).release();
    379379    return S_OK;
    380380}
  • trunk/Source/WebKit/win/ChangeLog

    r86287 r86330  
     12011-05-12  Nikolas Zimmermann  <nzimmermann@rim.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        String operator+ reallocates unnecessarily when concatting > 2 strings
     6        https://bugs.webkit.org/show_bug.cgi?id=58420
     7
     8        Provide a faster String append operator. See Source/JavaScriptCore/ChangeLog for details.
     9
     10        * AccessibleBase.cpp:
     11        (AccessibleBase::get_accKeyboardShortcut): Explicitely cast to Strings first, so operator BString() can be invoked.
     12
    1132011-05-11  Dmitry Lomov  <dslomov@google.com>
    214
Note: See TracChangeset for help on using the changeset viewer.