Changeset 90813 in webkit


Ignore:
Timestamp:
Jul 12, 2011 6:35:57 AM (13 years ago)
Author:
Adam Roben
Message:

Ensure no intermediate WTF::Strings are created when concatenating with string literals

Fixes <http://webkit.org/b/63330> Concatenating string literals and WTF::Strings using
operator+ is suboptimal

Reviewed by Darin Adler.

Source/JavaScriptCore:

  • wtf/text/StringConcatenate.h:

(WTF::StringTypeAdapter<String>::writeTo): Added a macro that can be used for testing how
many WTF::Strings get copied while evaluating an operator+ expression.

  • wtf/text/StringOperators.h:

(WTF::operator+): Changed the overload that takes a StringAppend to take it on the left-hand
side, since operator+ is left-associative. Having the StringAppend on the right-hand side
was causing us to make intermediate WTF::Strings when evaluating expressions that contained
multiple calls to operator+. Added some more overloads for that take a left-hand side of
const char* to resolve overload ambiguity for certain expressions. Added overloads that take
a left-hand side of const UChar* (matching the const char* overloads) so that wide string
literals don't first have to be converted to a WTF::String in operator+ expressions.

Source/WebKit2:

Export some symbols needed by TestWebKitAPI

  • win/WebKit2.def:

Tools:

Test that no intermediate WTF::Strings are created when concatenating with string literals

  • TestWebKitAPI/Tests/WTF/StringOperators.cpp: Added.

(TestWebKitAPI::TEST): Test that a bunch of different string concatenation expressions don't
create any intermediate WTF::Strings while they're being evaluated.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/win/TestWebKitAPI.vcproj:

Added new file.

Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r90812 r90813  
     12011-07-12  Adam Roben  <aroben@apple.com>
     2
     3        Ensure no intermediate WTF::Strings are created when concatenating with string literals
     4
     5        Fixes <http://webkit.org/b/63330> Concatenating string literals and WTF::Strings using
     6        operator+ is suboptimal
     7
     8        Reviewed by Darin Adler.
     9
     10        * wtf/text/StringConcatenate.h:
     11        (WTF::StringTypeAdapter<String>::writeTo): Added a macro that can be used for testing how
     12        many WTF::Strings get copied while evaluating an operator+ expression.
     13
     14        * wtf/text/StringOperators.h:
     15        (WTF::operator+): Changed the overload that takes a StringAppend to take it on the left-hand
     16        side, since operator+ is left-associative. Having the StringAppend on the right-hand side
     17        was causing us to make intermediate WTF::Strings when evaluating expressions that contained
     18        multiple calls to operator+. Added some more overloads for that take a left-hand side of
     19        const char* to resolve overload ambiguity for certain expressions. Added overloads that take
     20        a left-hand side of const UChar* (matching the const char* overloads) so that wide string
     21        literals don't first have to be converted to a WTF::String in operator+ expressions.
     22
    1232011-07-12  Adam Roben  <aroben@apple.com>
    224
  • trunk/Source/JavaScriptCore/wtf/text/StringConcatenate.h

    r86330 r90813  
    3131#endif
    3232
     33// This macro is helpful for testing how many intermediate Strings are created while evaluating an
     34// expression containing operator+.
     35#ifndef WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING
     36#define WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING() ((void)0)
     37#endif
     38
    3339namespace WTF {
    3440
     
    181187        for (unsigned i = 0; i < length; ++i)
    182188            destination[i] = data[i];
     189
     190        WTF_STRINGTYPEADAPTER_COPIED_WTF_STRING();
    183191    }
    184192
  • trunk/Source/JavaScriptCore/wtf/text/StringOperators.h

    r86330 r90813  
    9292}
    9393
     94template<typename U, typename V>
     95StringAppend<const char*, StringAppend<U, V> > operator+(const char* string1, const StringAppend<U, V>& string2)
     96{
     97    return StringAppend<const char*, StringAppend<U, V> >(string1, string2);
     98}
     99
     100inline StringAppend<const UChar*, String> operator+(const UChar* string1, const String& string2)
     101{
     102    return StringAppend<const UChar*, String>(string1, string2);
     103}
     104
     105inline StringAppend<const UChar*, AtomicString> operator+(const UChar* string1, const AtomicString& string2)
     106{
     107    return StringAppend<const UChar*, AtomicString>(string1, string2);
     108}
     109
     110template<typename U, typename V>
     111StringAppend<const UChar*, StringAppend<U, V> > operator+(const UChar* string1, const StringAppend<U, V>& string2)
     112{
     113    return StringAppend<const UChar*, StringAppend<U, V> >(string1, string2);
     114}
     115
    94116template<typename T>
    95117StringAppend<String, T> operator+(const String& string1, T string2)
     
    99121
    100122template<typename U, typename V, typename W>
    101 StringAppend<U, StringAppend<V, W> > operator+(U string1, const StringAppend<V, W>& string2)
     123StringAppend<StringAppend<U, V>, W> operator+(const StringAppend<U, V>& string1, W string2)
    102124{
    103     return StringAppend<U, StringAppend<V, W> >(string1, string2);
     125    return StringAppend<StringAppend<U, V>, W>(string1, string2);
    104126}
    105127
  • trunk/Source/WebKit2/ChangeLog

    r90806 r90813  
     12011-07-12  Adam Roben  <aroben@apple.com>
     2
     3        Export some symbols needed by TestWebKitAPI
     4
     5        Part of <http://webkit.org/b/63330> Concatenating string literals and WTF::Strings using
     6        operator+ is suboptimal
     7
     8        Reviewed by Darin Adler.
     9
     10        * win/WebKit2.def:
     11
    1122011-07-11  Hironori Bono  <hbono@chromium.org>
    213
  • trunk/Source/WebKit2/win/WebKit2.def

    r90389 r90813  
    135135        ?createThread@WTF@@YAIP6APAXPAX@Z0@Z
    136136
    137         ; Re-exports from WebCore for WebCoreTestSupport
     137        ; Re-exports from WebCore for test harnesses
     138        ??0String@WTF@@QAE@PBD@Z
     139        ??0String@WTF@@QAE@PB_W@Z
     140        ?add@AtomicString@WTF@@CA?AV?$PassRefPtr@VStringImpl@WTF@@@2@PBD@Z
    138141        ?addSlowCase@AtomicString@WTF@@CA?AV?$PassRefPtr@VStringImpl@WTF@@@2@PAVStringImpl@2@@Z
    139142        ?cacheDOMStructure@WebCore@@YAPAVStructure@JSC@@PAVJSDOMGlobalObject@1@PAV23@PBUClassInfo@3@@Z
  • trunk/Tools/ChangeLog

    r90810 r90813  
     12011-07-12  Adam Roben  <aroben@apple.com>
     2
     3        Test that no intermediate WTF::Strings are created when concatenating with string literals
     4
     5        Test for <http://webkit.org/b/63330> Concatenating string literals and WTF::Strings using
     6        operator+ is suboptimal
     7
     8        Reviewed by Darin Adler.
     9
     10        * TestWebKitAPI/Tests/WTF/StringOperators.cpp: Added.
     11        (TestWebKitAPI::TEST): Test that a bunch of different string concatenation expressions don't
     12        create any intermediate WTF::Strings while they're being evaluated.
     13
     14        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     15        * TestWebKitAPI/win/TestWebKitAPI.vcproj:
     16        Added new file.
     17
    1182011-07-12  Eric Seidel  <eric@webkit.org>
    219
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r89515 r90813  
    5454                BCBD3761125ABCFE00D2C29F /* FrameMIMETypePNG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCBD3760125ABCFE00D2C29F /* FrameMIMETypePNG.cpp */; };
    5555                BCC8B95B12611F4700DE46A4 /* FailedLoad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCC8B95A12611F4700DE46A4 /* FailedLoad.cpp */; };
     56                C01363C813C3997300EF3964 /* StringOperators.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C01363C713C3997300EF3964 /* StringOperators.cpp */; };
    5657                C01A23F21266156700C9ED55 /* spacebar-scrolling.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C02B7882126615410026BF0F /* spacebar-scrolling.html */; };
    5758                C02B77F2126612140026BF0F /* SpacebarScrolling.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */; };
     
    164165                BCC8B95A12611F4700DE46A4 /* FailedLoad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FailedLoad.cpp; sourceTree = "<group>"; };
    165166                BCF0F9391381C25B008361AC /* CompilerVersion.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = CompilerVersion.xcconfig; sourceTree = "<group>"; };
     167                C01363C713C3997300EF3964 /* StringOperators.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringOperators.cpp; path = WTF/StringOperators.cpp; sourceTree = "<group>"; };
    166168                C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpacebarScrolling.cpp; sourceTree = "<group>"; };
    167169                C02B7853126613AE0026BF0F /* Carbon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Carbon.framework; sourceTree = SDKROOT; };
     
    320322                        isa = PBXGroup;
    321323                        children = (
     324                                C01363C713C3997300EF3964 /* StringOperators.cpp */,
    322325                                BC90964B125561BF00083756 /* VectorBasic.cpp */,
    323326                                37200B9113A16230007A4FAD /* VectorReverse.cpp */,
     
    472475                                C045F9451385C2EA00C0F3CD /* DownloadDecideDestinationCrash.cpp in Sources */,
    473476                                37200B9213A16230007A4FAD /* VectorReverse.cpp in Sources */,
     477                                C01363C813C3997300EF3964 /* StringOperators.cpp in Sources */,
    474478                        );
    475479                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj

    r88477 r90813  
    589589                                >
    590590                                <File
     591                                        RelativePath="..\Tests\WTF\StringOperators.cpp"
     592                                        >
     593                                </File>
     594                                <File
    591595                                        RelativePath="..\Tests\WTF\VectorBasic.cpp"
    592596                                        >
Note: See TracChangeset for help on using the changeset viewer.