Changeset 140453 in webkit


Ignore:
Timestamp:
Jan 22, 2013 1:01:42 PM (11 years ago)
Author:
eric@webkit.org
Message:

Make CompactHTMLToken a little more compact
https://bugs.webkit.org/show_bug.cgi?id=107317

Reviewed by Darin Adler.

Reduce the size of CompactHTMLToken by two pointers.
The abuse of the attribute vector to store the DOCTYPE strings
is kinda lame, but makes a lot of sense given how rare DOCTYPE tokens are.

The resulting CompactHTMLToken vector should be a smaller malloc and thus faster.
However I saw no perf change on html-parser-srcdoc.html.

  • html/parser/CompactHTMLToken.cpp:

(SameSizeAsCompactHTMLToken):
(WebCore):
(WebCore::CompactHTMLToken::CompactHTMLToken):
(WebCore::CompactHTMLToken::isSafeToSendToAnotherThread):

  • html/parser/CompactHTMLToken.h:

(WebCore::CompactHTMLToken::type):
(CompactHTMLToken):
(WebCore::CompactHTMLToken::publicIdentifier):
(WebCore::CompactHTMLToken::systemIdentifier):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r140452 r140453  
     12013-01-22  Eric Seidel  <eric@webkit.org>
     2
     3        Make CompactHTMLToken a little more compact
     4        https://bugs.webkit.org/show_bug.cgi?id=107317
     5
     6        Reviewed by Darin Adler.
     7
     8        Reduce the size of CompactHTMLToken by two pointers.
     9        The abuse of the attribute vector to store the DOCTYPE strings
     10        is kinda lame, but makes a lot of sense given how rare DOCTYPE tokens are.
     11
     12        The resulting CompactHTMLToken vector should be a smaller malloc and thus faster.
     13        However I saw no perf change on html-parser-srcdoc.html.
     14
     15        * html/parser/CompactHTMLToken.cpp:
     16        (SameSizeAsCompactHTMLToken):
     17        (WebCore):
     18        (WebCore::CompactHTMLToken::CompactHTMLToken):
     19        (WebCore::CompactHTMLToken::isSafeToSendToAnotherThread):
     20        * html/parser/CompactHTMLToken.h:
     21        (WebCore::CompactHTMLToken::type):
     22        (CompactHTMLToken):
     23        (WebCore::CompactHTMLToken::publicIdentifier):
     24        (WebCore::CompactHTMLToken::systemIdentifier):
     25
    1262013-01-22  Elliott Sprehn  <esprehn@chromium.org>
    227
  • trunk/Source/WebCore/html/parser/CompactHTMLToken.cpp

    r139945 r140453  
    3434namespace WebCore {
    3535
     36struct SameSizeAsCompactHTMLToken  {
     37    unsigned bitfields;
     38    String name;
     39    Vector<CompactAttribute> vector;
     40};
     41
     42COMPILE_ASSERT(sizeof(CompactHTMLToken) == sizeof(SameSizeAsCompactHTMLToken), CompactHTMLToken_should_stay_small);
     43
    3644CompactHTMLToken::CompactHTMLToken(const HTMLToken& token)
    3745    : m_type(token.type())
     
    4149        ASSERT_NOT_REACHED();
    4250        break;
    43     case HTMLTokenTypes::DOCTYPE:
     51    case HTMLTokenTypes::DOCTYPE: {
    4452        m_data = String(token.name().data(), token.name().size());
    45         m_publicIdentifier = String(token.publicIdentifier().data(), token.publicIdentifier().size());
    46         m_systemIdentifier = String(token.systemIdentifier().data(), token.systemIdentifier().size());
     53        // There is only 1 DOCTYPE token per document, so to avoid increasing the
     54        // size of CompactHTMLToken, we just use the m_attributes vector.
     55        String publicIdentifier(token.publicIdentifier().data(), token.publicIdentifier().size());
     56        String systemIdentifier(token.systemIdentifier().data(), token.systemIdentifier().size());
     57        m_attributes.append(CompactAttribute(publicIdentifier, systemIdentifier));
    4758        break;
     59    }
    4860    case HTMLTokenTypes::EndOfFile:
    4961        break;
     
    89101            return false;
    90102    }
    91 
    92     return isStringSafeToSendToAnotherThread(m_data)
    93         && isStringSafeToSendToAnotherThread(m_publicIdentifier)
    94         && isStringSafeToSendToAnotherThread(m_systemIdentifier);
     103    return isStringSafeToSendToAnotherThread(m_data);
    95104}
    96105
  • trunk/Source/WebCore/html/parser/CompactHTMLToken.h

    r139945 r140453  
    6161    bool isSafeToSendToAnotherThread() const;
    6262
    63     HTMLTokenTypes::Type type() const { return m_type; }
     63    HTMLTokenTypes::Type type() const { return static_cast<HTMLTokenTypes::Type>(m_type); }
    6464    const String& data() const { return m_data; }
    6565    bool selfClosing() const { return m_selfClosing; }
    6666    const Vector<CompactAttribute>& attributes() const { return m_attributes; }
    6767
    68     const String& publicIdentifier() const { return m_publicIdentifier; }
    69     const String& systemIdentifier() const { return m_systemIdentifier; }
     68    // There is only 1 DOCTYPE token per document, so to avoid increasing the
     69    // size of CompactHTMLToken, we just use the m_attributes vector.
     70    const String& publicIdentifier() const { return m_attributes[0].name(); }
     71    const String& systemIdentifier() const { return m_attributes[0].value(); }
    7072
    7173private:
    72     HTMLTokenTypes::Type m_type;
     74    unsigned m_type : 4;
     75    bool m_selfClosing : 1;
     76
    7377    String m_data; // "name", "characters", or "data" depending on m_type
    74     bool m_selfClosing;
    7578    Vector<CompactAttribute> m_attributes;
    76 
    77     // For doctype only.
    78     String m_publicIdentifier;
    79     String m_systemIdentifier;
    8079};
    8180
Note: See TracChangeset for help on using the changeset viewer.