Changeset 69683 in webkit


Ignore:
Timestamp:
Oct 13, 2010 12:29:14 PM (13 years ago)
Author:
barraclough@apple.com
Message:

JavaScriptCore: Bug 43987 - Downloading using XHR is much slower than before
Change StringBuilder to use overcapacity in a StringImpl, rather than a Vector.
Fundamentally this should be the same (copies current contents to expand capacity,
rather than using a rope), but this approach allows the intermadiate state of the
String to be inspected in the buffer without copying to resolve.

Reviewed by Oliver Hunt.

  • runtime/JSONObject.cpp:

(JSC::Stringifier::appendQuotedString):
(JSC::Stringifier::Holder::appendNextProperty):

Renamed StringBuilder::size() -> length() (to match other String types).

  • runtime/UStringBuilder.h:

(JSC::UStringBuilder::append):
(JSC::UStringBuilder::toUString):

Update for changes in parent class, can just 'using' the append methods.

  • wtf/text/StringBuilder.cpp: Added.

(WTF::StringBuilder::reifyString):
(WTF::StringBuilder::resize):
(WTF::StringBuilder::reserveCapacity):
(WTF::StringBuilder::allocateBuffer):
(WTF::StringBuilder::appendUninitialized):
(WTF::StringBuilder::append):
(WTF::StringBuilder::shrinkToFit):

  • wtf/text/StringBuilder.h:

(WTF::StringBuilder::StringBuilder):
(WTF::StringBuilder::append):
(WTF::StringBuilder::toString):
(WTF::StringBuilder::toStringPreserveCapacity):
(WTF::StringBuilder::length):
(WTF::StringBuilder::isEmpty):
(WTF::StringBuilder::operator[]):
(WTF::StringBuilder::clear):

Class updated to use overcapacity in a StringImpl, rather than a Vector.

WebCore: Bug 43987 - Downloading using XHR is much slower than before

Reviewed by Oliver Hunt.

  • svg/SVGPathStringBuilder.cpp:

(WebCore::SVGPathStringBuilder::result):

StringBuilder::size() -> StringBuilder::length().

WebKit/chromium: Bug 43987 - Downloading using XHR is much slower than before

Reviewed by Oliver Hunt.

  • src/WebPageSerializerImpl.cpp:

(WebKit::WebPageSerializerImpl::encodeAndFlushBuffer):

Location:
trunk
Files:
1 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/Android.mk

    r64943 r69683  
    178178        wtf/text/AtomicString.cpp \
    179179        wtf/text/CString.cpp \
     180        wtf/text/StringBuilder.cpp \
    180181        wtf/text/StringImpl.cpp \
    181182        wtf/text/WTFString.cpp \
  • trunk/JavaScriptCore/Android.v8.wtf.mk

    r57904 r69683  
    5555        wtf/text/AtomicString.cpp \
    5656        wtf/text/CString.cpp \
     57        wtf/text/StringBuidler.cpp \
    5758        wtf/text/StringImpl.cpp \
    5859        wtf/text/WTFString.cpp \
  • trunk/JavaScriptCore/ChangeLog

    r69678 r69683  
     12010-10-13  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Bug 43987 - Downloading using XHR is much slower than before
     6        Change StringBuilder to use overcapacity in a StringImpl, rather than a Vector.
     7        Fundamentally this should be the same (copies current contents to expand capacity,
     8        rather than using a rope), but this approach allows the intermadiate state of the
     9        String to be inspected in the buffer without copying to resolve.
     10
     11        * runtime/JSONObject.cpp:
     12        (JSC::Stringifier::appendQuotedString):
     13        (JSC::Stringifier::Holder::appendNextProperty):
     14            Renamed StringBuilder::size() -> length() (to match other String types).
     15
     16        * runtime/UStringBuilder.h:
     17        (JSC::UStringBuilder::append):
     18        (JSC::UStringBuilder::toUString):
     19            Update for changes in parent class, can just 'using' the append methods.
     20
     21        * wtf/text/StringBuilder.cpp: Added.
     22        (WTF::StringBuilder::reifyString):
     23        (WTF::StringBuilder::resize):
     24        (WTF::StringBuilder::reserveCapacity):
     25        (WTF::StringBuilder::allocateBuffer):
     26        (WTF::StringBuilder::appendUninitialized):
     27        (WTF::StringBuilder::append):
     28        (WTF::StringBuilder::shrinkToFit):
     29        * wtf/text/StringBuilder.h:
     30        (WTF::StringBuilder::StringBuilder):
     31        (WTF::StringBuilder::append):
     32        (WTF::StringBuilder::toString):
     33        (WTF::StringBuilder::toStringPreserveCapacity):
     34        (WTF::StringBuilder::length):
     35        (WTF::StringBuilder::isEmpty):
     36        (WTF::StringBuilder::operator[]):
     37        (WTF::StringBuilder::clear):
     38            Class updated to use overcapacity in a StringImpl, rather than a Vector.
     39
     40        * Android.mk:
     41        * Android.v8.wtf.mk:
     42        * GNUmakefile.am:
     43        * JavaScriptCore.exp:
     44        * JavaScriptCore.gypi:
     45        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreCommon.vsprops:
     46        * JavaScriptCore.vcproj/WTF/WTF.vcproj:
     47        * JavaScriptCore.vcproj/jsc/jsc.vcproj:
     48        * JavaScriptCore.xcodeproj/project.pbxproj:
     49        * wtf/CMakeLists.txt:
     50        * wtf/wtf.pri:
     51
    1522010-10-13  Adam Roben  <aroben@apple.com>
    253
  • trunk/JavaScriptCore/GNUmakefile.am

    r69663 r69683  
    509509        JavaScriptCore/wtf/text/CString.h \
    510510        JavaScriptCore/wtf/text/StringBuffer.h \
     511        JavaScriptCore/wtf/text/StringBuilder.cpp \
    511512        JavaScriptCore/wtf/text/StringBuilder.h \
    512513        JavaScriptCore/wtf/text/StringConcatenate.h \
  • trunk/JavaScriptCore/JavaScriptCore.exp

    r69516 r69683  
    133133__ZN3JSC12JSGlobalData6createENS_15ThreadStackTypeE
    134134__ZN3JSC12JSGlobalDataD1Ev
     135__ZN3JSC12RegExpObject4infoE
     136__ZN3JSC12RegExpObjectC1EPNS_14JSGlobalObjectEN3WTF17NonNullPassRefPtrINS_9StructureEEENS4_INS_6RegExpEEE
    135137__ZN3JSC12SamplingTool5setupEv
    136138__ZN3JSC12SmallStrings17createEmptyStringEPNS_12JSGlobalDataE
     
    151153__ZN3JSC13SamplingFlags7s_flagsE
    152154__ZN3JSC13StatementNode6setLocEii
    153 __ZN3JSC14heapStatisticsEPNS_12JSGlobalDataE
    154155__ZN3JSC14JSGlobalObject10globalExecEv
    155156__ZN3JSC14JSGlobalObject12defineGetterEPNS_9ExecStateERKNS_10IdentifierEPNS_8JSObjectEj
     
    166167__ZN3JSC14TimeoutChecker10didTimeOutEPNS_9ExecStateE
    167168__ZN3JSC14TimeoutChecker5resetEv
     169__ZN3JSC14heapStatisticsEPNS_12JSGlobalDataE
    168170__ZN3JSC14throwTypeErrorEPNS_9ExecStateE
    169171__ZN3JSC15JSWrapperObject12markChildrenERNS_9MarkStackE
     
    240242__ZN3JSC6JSLock9lockCountEv
    241243__ZN3JSC6JSLockC1EPNS_9ExecStateE
     244__ZN3JSC6RegExp6createEPNS_12JSGlobalDataERKNS_7UStringES5_
     245__ZN3JSC6RegExpD1Ev
    242246__ZN3JSC7JSArray12markChildrenERNS_9MarkStackE
    243247__ZN3JSC7JSArray15setSubclassDataEPv
     
    373377__ZN3WTF12isMainThreadEv
    374378__ZN3WTF12randomNumberEv
     379__ZN3WTF13StringBuilder11reifyStringEv
     380__ZN3WTF13StringBuilder11shrinkToFitEv
     381__ZN3WTF13StringBuilder6appendEPKcj
     382__ZN3WTF13StringBuilder6appendEPKtj
     383__ZN3WTF13StringBuilder6resizeEj
    375384__ZN3WTF13WTFThreadData10staticDataE
    376385__ZN3WTF13WTFThreadDataC1Ev
     
    485494__ZNK3JSC11Interpreter18retrieveLastCallerEPNS_9ExecStateERiRlRNS_7UStringERNS_7JSValueE
    486495__ZNK3JSC12PropertySlot14functionGetterEPNS_9ExecStateE
    487 __ZN3JSC12RegExpObject4infoE
    488 __ZN3JSC12RegExpObjectC1EPNS_14JSGlobalObjectEN3WTF17NonNullPassRefPtrINS_9StructureEEENS4_INS_6RegExpEEE
    489496__ZNK3JSC14JSGlobalObject14isDynamicScopeERb
    490497__ZNK3JSC16InternalFunction9classInfoEv
     
    517524__ZNK3JSC6JSCell9getUInt32ERj
    518525__ZNK3JSC6JSCell9toBooleanEPNS_9ExecStateE
    519 __ZN3JSC6RegExp6createEPNS_12JSGlobalDataERKNS_7UStringES5_
    520 __ZN3JSC6RegExpD1Ev
    521526__ZNK3JSC7ArgList8getSliceEiRS0_
    522527__ZNK3JSC7JSArray12subclassDataEv
  • trunk/JavaScriptCore/JavaScriptCore.gypi

    r69663 r69683  
    454454            'wtf/text/CString.h',
    455455            'wtf/text/StringBuffer.h',
     456            'wtf/text/StringBuilder.cpp',
    456457            'wtf/text/StringBuilder.h',
    457458            'wtf/text/StringConcatenate.h',
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCoreCommon.vsprops

    r63833 r69683  
    2020        <Tool
    2121                Name="VCPostBuildEventTool"
    22                 CommandLine="mkdir 2&gt;NUL &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\text\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\unicode\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\unicode\icu\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\parser\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\runtime\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\VM\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\bytecode\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\interpreter\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\assembler\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\jit\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\debugger\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\profiler\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\create_hash_table&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\pcre\pcre.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\text\AtomicString.cpp&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\text\StringImpl.cpp&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\text\WTFString.cpp&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;&#x0D;&#x0A;&#x0D;&#x0A;mkdir 2&gt;NUL &quot;$(OutDir)\JavaScriptCore.resources&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)..\$(ProjectName).resources\*&quot; &quot;$(OutDir)\$(ProjectName).resources&quot;&#x0D;&#x0A;&#x0D;&#x0A;if exist &quot;$(WebKitOutputDir)\buildfailed&quot; del &quot;$(WebKitOutputDir)\buildfailed&quot;&#x0D;&#x0A;"
     22                CommandLine="mkdir 2&gt;NUL &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\text\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\unicode\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\unicode\icu\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\parser\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\runtime\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\VM\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\bytecode\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\interpreter\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\assembler\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\jit\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\debugger\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\profiler\*.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\create_hash_table&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\pcre\pcre.h&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\text\AtomicString.cpp&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\text\StringBuilder.cpp&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\text\StringImpl.cpp&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)\..\..\wtf\text\WTFString.cpp&quot; &quot;$(WebKitOutputDir)\include\private\JavaScriptCore&quot;&#x0D;&#x0A;&#x0D;&#x0A;&#x0D;&#x0A;mkdir 2&gt;NUL &quot;$(OutDir)\JavaScriptCore.resources&quot;&#x0D;&#x0A;xcopy /y /d &quot;$(ProjectDir)..\$(ProjectName).resources\*&quot; &quot;$(OutDir)\$(ProjectName).resources&quot;&#x0D;&#x0A;&#x0D;&#x0A;if exist &quot;$(WebKitOutputDir)\buildfailed&quot; del &quot;$(WebKitOutputDir)\buildfailed&quot;&#x0D;&#x0A;"
    2323        />
    2424        <Tool
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/WTF/WTF.vcproj

    r69663 r69683  
    614614                </File>
    615615                <File
     616                        RelativePath="..\..\wtf\text\StringBuilder.cpp"
     617                        >
     618                </File>
     619                <File
    616620                        RelativePath="..\..\wtf\text\StringBuilder.h"
    617621                        >
  • trunk/JavaScriptCore/JavaScriptCore.vcproj/jsc/jsc.vcproj

    r59187 r69683  
    335335                </File>
    336336                <File
     337                        RelativePath="$(WebKitOutputDir)\include\private\JavaScriptCore\StringBuilder.cpp"
     338                        >
     339                </File>
     340                <File
    337341                        RelativePath="$(WebKitOutputDir)\include\private\JavaScriptCore\StringImpl.cpp"
    338342                        >
  • trunk/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r69669 r69683  
    207207                862AF4B612239C7B0024E5B8 /* DecimalNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = 862AF4B512239C7B0024E5B8 /* DecimalNumber.h */; };
    208208                863B23E00FC6118900703AA4 /* MacroAssemblerCodeRef.h in Headers */ = {isa = PBXBuildFile; fileRef = 863B23DF0FC60E6200703AA4 /* MacroAssemblerCodeRef.h */; settings = {ATTRIBUTES = (Private, ); }; };
     209                86438FC41265503E00E0DFCA /* StringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86438FC31265503E00E0DFCA /* StringBuilder.cpp */; };
    209210                86565742115BE3DA00291F40 /* CString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86565740115BE3DA00291F40 /* CString.cpp */; };
    210211                86565743115BE3DA00291F40 /* CString.h in Headers */ = {isa = PBXBuildFile; fileRef = 86565741115BE3DA00291F40 /* CString.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    812813                862AF4B512239C7B0024E5B8 /* DecimalNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DecimalNumber.h; sourceTree = "<group>"; };
    813814                863B23DF0FC60E6200703AA4 /* MacroAssemblerCodeRef.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MacroAssemblerCodeRef.h; sourceTree = "<group>"; };
     815                86438FC31265503E00E0DFCA /* StringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StringBuilder.cpp; path = text/StringBuilder.cpp; sourceTree = "<group>"; };
    814816                86565740115BE3DA00291F40 /* CString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CString.cpp; path = text/CString.cpp; sourceTree = "<group>"; };
    815817                86565741115BE3DA00291F40 /* CString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CString.h; path = text/CString.h; sourceTree = "<group>"; };
     
    18411843                                86565741115BE3DA00291F40 /* CString.h */,
    18421844                                86B99AE1117E578100DF5A90 /* StringBuffer.h */,
     1845                                86438FC31265503E00E0DFCA /* StringBuilder.cpp */,
    18431846                                081469481264375E00DFF935 /* StringBuilder.h */,
    18441847                                0896C29E1265AB0900B1CDD3 /* StringConcatenate.h */,
     
    27882791                                90213E3D123A40C200D422F3 /* MemoryStatistics.cpp in Sources */,
    27892792                                A730B6131250068F009D25B1 /* StrictEvalActivation.cpp in Sources */,
     2793                                86438FC41265503E00E0DFCA /* StringBuilder.cpp in Sources */,
    27902794                        );
    27912795                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/JavaScriptCore/runtime/JSONObject.cpp

    r69663 r69683  
    285285
    286286    // String length plus 2 for quote marks plus 8 so we can accomodate a few escaped characters.
    287     builder.reserveCapacity(builder.size() + length + 2 + 8);
     287    builder.reserveCapacity(builder.length() + length + 2 + 8);
    288288
    289289    builder.append('"');
     
    522522    if (m_index == m_size) {
    523523        stringifier.unindent();
    524         if (m_size && builder[builder.size() - 1] != '{')
     524        if (m_size && builder[builder.length() - 1] != '{')
    525525            stringifier.startNewLine(builder);
    526526        builder.append(m_isArray ? ']' : '}');
     
    563563            return false;
    564564
    565         rollBackPoint = builder.size();
     565        rollBackPoint = builder.length();
    566566
    567567        // Append the separator string.
  • trunk/JavaScriptCore/runtime/UStringBuilder.h

    r69594 r69683  
    3333class UStringBuilder : public StringBuilder {
    3434public:
    35     // Forward declare these methods, otherwhise append() is ambigious.
    36     void append(const UChar u) { StringBuilder::append(u); }
    37     void append(const char* str) { StringBuilder::append(str); }
    38     void append(const char* str, size_t len) { StringBuilder::append(str, len); }
    39     void append(const UChar* str, size_t len) { StringBuilder::append(str, len); }
     35    using StringBuilder::append;
     36    void append(const UString& str) { append(String(str.impl())); }
    4037
    41     void append(const UString& str)
    42     {
    43         m_buffer.append(str.characters(), str.length());
    44     }
    45 
    46     UString toUString()
    47     {
    48         m_buffer.shrinkToFit();
    49         ASSERT(m_buffer.data() || !m_buffer.size());
    50         return UString::adopt(m_buffer);
    51     }
     38    UString toUString() { return toString().impl(); }
    5239};
    5340
  • trunk/JavaScriptCore/wtf/CMakeLists.txt

    r65437 r69683  
    1717    text/AtomicString.cpp
    1818    text/CString.cpp
     19    text/StringBuilder.cpp
    1920    text/StringImpl.cpp
    2021    text/StringStatics.cpp
  • trunk/JavaScriptCore/wtf/text/StringBuilder.h

    r69608 r69683  
    11/*
    2  * Copyright (C) 2009 Apple Inc. All rights reserved.
     2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434class StringBuilder {
    3535public:
    36     void append(const UChar u)
     36    StringBuilder()
     37        : m_length(0)
    3738    {
    38         m_buffer.append(u);
    3939    }
    4040
    41     void append(const char* str)
     41    void append(const UChar*, unsigned);
     42    void append(const char*, unsigned);
     43
     44    void append(const String& string)
    4245    {
    43         append(str, strlen(str));
     46        // If we're appending to an empty string, and there is not buffer
     47        // (in case reserveCapacity has been called) then just retain the
     48        // string.
     49        if (!m_length && !m_buffer) {
     50            m_string = string;
     51            m_length = string.length();
     52            return;
     53        }
     54        append(string.characters(), string.length());
    4455    }
    4556
    46     void append(const char* str, size_t len)
     57    void append(const char* characters)
    4758    {
    48         reserveCapacity(m_buffer.size() + len);
    49         for (size_t i = 0; i < len; i++)
    50             m_buffer.append(static_cast<unsigned char>(str[i]));
     59        if (characters)
     60            append(characters, strlen(characters));
    5161    }
    5262
    53     void append(const UChar* str, size_t len)
     63    void append(UChar c)
    5464    {
    55         m_buffer.append(str, len);
     65        if (m_buffer && m_length < m_buffer->length() && m_string.isNull())
     66            m_bufferCharacters[m_length++] = c;
     67        else
     68            append(&c, 1);
    5669    }
    5770
    58     void append(const String& str)
     71    void append(char c)
    5972    {
    60         m_buffer.append(str.characters(), str.length());
     73        if (m_buffer && m_length < m_buffer->length() && m_string.isNull())
     74            m_bufferCharacters[m_length++] = (unsigned char)c;
     75        else
     76            append(&c, 1);
    6177    }
    62 
    63     bool isEmpty() const { return m_buffer.isEmpty(); }
    64     void reserveCapacity(size_t newCapacity)
    65     {
    66         if (newCapacity < m_buffer.capacity())
    67             return;
    68         m_buffer.reserveCapacity(std::max(newCapacity, m_buffer.capacity() + m_buffer.capacity() / 4 + 1));
    69     }
    70     void resize(size_t size) { m_buffer.resize(size); }
    71     size_t size() const { return m_buffer.size(); }
    72     // FIXME: remove size(), above (strings have a length, not a size).
    73     // also, should return an unsigned, not a size_t.
    74     size_t length() const { return size(); }
    75 
    76     UChar operator[](size_t i) const { return m_buffer.at(i); }
    7778
    7879    String toString()
    7980    {
    80         m_buffer.shrinkToFit();
    81         ASSERT(m_buffer.data() || !m_buffer.size());
    82         return String::adopt(m_buffer);
     81        if (m_string.isNull()) {
     82            shrinkToFit();
     83            reifyString();
     84        }
     85        return m_string;
    8386    }
    8487
    85 protected:
    86     Vector<UChar, 64> m_buffer;
     88    String toStringPreserveCapacity()
     89    {
     90        if (m_string.isNull())
     91            reifyString();
     92        return m_string;
     93    }
     94
     95    unsigned length() const
     96    {
     97        return m_length;
     98    }
     99
     100    bool isEmpty() const { return !length(); }
     101
     102    void reserveCapacity(unsigned newCapacity);
     103
     104    void resize(unsigned newSize);
     105
     106    void shrinkToFit();
     107
     108    UChar operator[](unsigned i) const
     109    {
     110        ASSERT(i < m_length);
     111        if (!m_string.isNull())
     112            return m_string[i];
     113        ASSERT(m_buffer);
     114        return m_buffer->characters()[i];
     115    }
     116
     117    void clear()
     118    {
     119        m_length = 0;
     120        m_string = String();
     121        m_buffer = 0;
     122    }
     123
     124private:
     125    void allocateBuffer(const UChar* currentCharacters, unsigned requiredLength);
     126    UChar* appendUninitialized(unsigned length);
     127    void reifyString();
     128
     129    unsigned m_length;
     130    String m_string;
     131    RefPtr<StringImpl> m_buffer;
     132    UChar* m_bufferCharacters;
    87133};
    88134
  • trunk/JavaScriptCore/wtf/wtf.pri

    r67306 r69683  
    2323    wtf/text/AtomicString.cpp \
    2424    wtf/text/CString.cpp \
     25    wtf/text/StringBuilder.cpp \
    2526    wtf/text/StringImpl.cpp \
    2627    wtf/text/StringStatics.cpp \
  • trunk/WebCore/ChangeLog

    r69682 r69683  
     12010-10-13  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Bug 43987 - Downloading using XHR is much slower than before
     6
     7        * svg/SVGPathStringBuilder.cpp:
     8        (WebCore::SVGPathStringBuilder::result):
     9            StringBuilder::size() -> StringBuilder::length().
     10
    1112010-10-13  Yong Li  <yoli@rim.com>
    212
  • trunk/WebCore/svg/SVGPathStringBuilder.cpp

    r69594 r69683  
    2727String SVGPathStringBuilder::result()
    2828{
    29     unsigned size = m_stringBuilder.size();
     29    unsigned size = m_stringBuilder.length();
    3030    if (!size)
    3131        return String();
  • trunk/WebKit/chromium/ChangeLog

    r69675 r69683  
     12010-10-13  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Reviewed by Oliver Hunt.
     4
     5        Bug 43987 - Downloading using XHR is much slower than before
     6
     7        * src/WebPageSerializerImpl.cpp:
     8        (WebKit::WebPageSerializerImpl::encodeAndFlushBuffer):
     9
    1102010-10-13  Adam Barth  <abarth@webkit.org>
    211
  • trunk/WebKit/chromium/src/WebPageSerializerImpl.cpp

    r69675 r69683  
    279279{
    280280    // Data buffer is not full nor do we want to force flush.
    281     if (flushOption != ForceFlush && m_dataBuffer.size() <= dataBufferCapacity)
     281    if (flushOption != ForceFlush && m_dataBuffer.length() <= dataBufferCapacity)
    282282        return;
    283283
Note: See TracChangeset for help on using the changeset viewer.