Bug 32151

Summary: String::append(const String& str) check whether str.length() != 0
Product: WebKit Reporter: Zoltan Herczeg <zherczeg>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Enhancement CC: commit-queue, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
(Platform) String append patch none

Description Zoltan Herczeg 2009-12-04 05:08:45 PST
In CachedScript.cpp:

const String& CachedScript::script()
{
    ASSERT(!isPurgeable());

    if (!m_script && m_data) {
        m_script = m_decoder->decode(m_data->data(), encodedSize());
        m_script += m_decoder->flush();
        setDecodedSize(m_script.length() * sizeof(UChar));
    }

    m_decodedDataDeletionTimer.startOneShot(0);
    return m_script;
}

m_decoder->flush() usually returns with an empty string. However, the append duplicates the original string even in this case. (The script can be half mbyte or more). This is an unnecessary allocation and copy.
Comment 1 Zoltan Herczeg 2009-12-04 05:37:07 PST
Created attachment 44309 [details]
(Platform) String append patch
Comment 2 WebKit Review Bot 2009-12-04 05:37:31 PST
style-queue ran check-webkit-style on attachment 44309 [details] without any errors.
Comment 3 WebKit Commit Bot 2009-12-04 12:01:27 PST
Comment on attachment 44309 [details]
(Platform) String append patch

Clearing flags on attachment: 44309

Committed r51705: <http://trac.webkit.org/changeset/51705>
Comment 4 WebKit Commit Bot 2009-12-04 12:01:36 PST
All reviewed patches have been landed.  Closing bug.