Changeset 144544 in webkit


Ignore:
Timestamp:
Mar 2, 2013 1:06:57 PM (11 years ago)
Author:
eric@webkit.org
Message:

Remove two unnecessary mallocs from the main-thread-parser code path
https://bugs.webkit.org/show_bug.cgi?id=111249

Reviewed by Adam Barth.

I noticed these while fixing up our Vector -> String conversions
but never went back to fix the FIXME.

AtomicString(Vector<UChar, capacity>) is smart enough to avoid mallocing
if the represented string is already in the AtomicString table. It
also handles 8bit vs. 16bit and empty() just like nameString() does.

I also removed a 3rd caller to nameString() in the XSSAuditor which
was causing an unnecessary malloc in both the main and background
thread parser paths.

  • html/parser/AtomicHTMLToken.h:

(WebCore::AtomicHTMLToken::AtomicHTMLToken):

  • html/parser/HTMLToken.h:
  • html/parser/XSSAuditor.cpp:

(WebCore):
(WebCore::threadSafeMatch):
(WebCore::hasName):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r144543 r144544  
     12013-03-02  Eric Seidel  <eric@webkit.org>
     2
     3        Remove two unnecessary mallocs from the main-thread-parser code path
     4        https://bugs.webkit.org/show_bug.cgi?id=111249
     5
     6        Reviewed by Adam Barth.
     7
     8        I noticed these while fixing up our Vector -> String conversions
     9        but never went back to fix the FIXME.
     10
     11        AtomicString(Vector<UChar, capacity>) is smart enough to avoid mallocing
     12        if the represented string is already in the AtomicString table.  It
     13        also handles 8bit vs. 16bit and empty() just like nameString() does.
     14
     15        I also removed a 3rd caller to nameString() in the XSSAuditor which
     16        was causing an unnecessary malloc in both the main and background
     17        thread parser paths.
     18
     19        * html/parser/AtomicHTMLToken.h:
     20        (WebCore::AtomicHTMLToken::AtomicHTMLToken):
     21        * html/parser/HTMLToken.h:
     22        * html/parser/XSSAuditor.cpp:
     23        (WebCore):
     24        (WebCore::threadSafeMatch):
     25        (WebCore::hasName):
     26
    1272013-03-02  Eric Seidel  <eric@webkit.org>
    228
  • trunk/Source/WebCore/html/parser/AtomicHTMLToken.h

    r143673 r144544  
    154154            break;
    155155        case HTMLToken::DOCTYPE:
    156             m_name = AtomicString(token.nameString()); // FIXME: Should be AtomicString(token.name()) to avoid mallocing every time.
     156            m_name = AtomicString(token.name());
    157157            m_doctypeData = token.releaseDoctypeData();
    158158            break;
     
    162162        case HTMLToken::EndTag: {
    163163            m_selfClosing = token.selfClosing();
    164             m_name = AtomicString(token.nameString()); // FIXME: Should be AtomicString(token.name()) to avoid mallocing every time.
     164            m_name = AtomicString(token.name());
    165165            initializeAttributes(token.attributes());
    166166            break;
  • trunk/Source/WebCore/html/parser/HTMLToken.h

    r143415 r144544  
    152152    }
    153153
    154     // FIXME: Rename this to copyNameAsString().
    155     String nameString() const
    156     {
    157         if (!m_data.size())
    158             return emptyString();
    159         if (isAll8BitData())
    160             return String::make8BitFrom16BitSource(m_data.data(), m_data.size());
    161         return String(m_data);
    162     }
    163 
    164154    /* DOCTYPE Tokens */
    165155
  • trunk/Source/WebCore/html/parser/XSSAuditor.cpp

    r144530 r144544  
    114114}
    115115
     116// If other files need this, we should move this to HTMLParserIdioms.h
     117template<size_t inlineCapacity>
     118bool threadSafeMatch(const Vector<UChar, inlineCapacity>& vector, const QualifiedName& qname)
     119{
     120    return equalIgnoringNullity(vector, qname.localName().impl());
     121}
     122
    116123static bool hasName(const HTMLToken& token, const QualifiedName& name)
    117124{
    118     return threadSafeMatch(token.nameString(), name);
     125    return threadSafeMatch(token.name(), name);
    119126}
    120127
Note: See TracChangeset for help on using the changeset viewer.