Changeset 144801 in webkit


Ignore:
Timestamp:
Mar 5, 2013 12:44:37 PM (11 years ago)
Author:
tonyg@chromium.org
Message:

CompactHTMLToken does not need an XSSInfo pointer
https://bugs.webkit.org/show_bug.cgi?id=111423

Reviewed by Eric Seidel.

The CompactHTMLToken should remain as small as possible because it is copied. This shrinks the size by one pointer
by moving a relatively uncommon attribute out to its own Vector.

No new tests because no new functionality.

  • html/parser/BackgroundHTMLParser.cpp:

(WebCore::checkThatXSSInfosAreSafeToSendToAnotherThread):
(WebCore):
(WebCore::BackgroundHTMLParser::pumpTokenizer):
(WebCore::BackgroundHTMLParser::sendTokensToMainThread):

  • html/parser/BackgroundHTMLParser.h:

(BackgroundHTMLParser):

  • html/parser/CompactHTMLToken.cpp:

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

  • html/parser/CompactHTMLToken.h:

(WebCore):
(CompactHTMLToken):

  • html/parser/HTMLDocumentParser.cpp:

(WebCore::HTMLDocumentParser::processParsedChunkFromBackgroundParser):

  • html/parser/HTMLDocumentParser.h:

(ParsedChunk):

  • html/parser/XSSAuditorDelegate.h:

(XSSInfo):
(WebCore):

Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r144800 r144801  
     12013-03-05  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        CompactHTMLToken does not need an XSSInfo pointer
     4        https://bugs.webkit.org/show_bug.cgi?id=111423
     5
     6        Reviewed by Eric Seidel.
     7
     8        The CompactHTMLToken should remain as small as possible because it is copied. This shrinks the size by one pointer
     9        by moving a relatively uncommon attribute out to its own Vector.
     10
     11        No new tests because no new functionality.
     12
     13        * html/parser/BackgroundHTMLParser.cpp:
     14        (WebCore::checkThatXSSInfosAreSafeToSendToAnotherThread):
     15        (WebCore):
     16        (WebCore::BackgroundHTMLParser::pumpTokenizer):
     17        (WebCore::BackgroundHTMLParser::sendTokensToMainThread):
     18        * html/parser/BackgroundHTMLParser.h:
     19        (BackgroundHTMLParser):
     20        * html/parser/CompactHTMLToken.cpp:
     21        (SameSizeAsCompactHTMLToken):
     22        (WebCore::CompactHTMLToken::isSafeToSendToAnotherThread):
     23        * html/parser/CompactHTMLToken.h:
     24        (WebCore):
     25        (CompactHTMLToken):
     26        * html/parser/HTMLDocumentParser.cpp:
     27        (WebCore::HTMLDocumentParser::processParsedChunkFromBackgroundParser):
     28        * html/parser/HTMLDocumentParser.h:
     29        (ParsedChunk):
     30        * html/parser/XSSAuditorDelegate.h:
     31        (XSSInfo):
     32        (WebCore):
     33
    1342013-03-05  Anders Carlsson  <andersca@apple.com>
    235
  • trunk/Source/WebCore/html/parser/BackgroundHTMLParser.cpp

    r144714 r144801  
    5858    for (size_t i = 0; i < preloads.size(); ++i)
    5959        ASSERT(preloads[i]->isSafeToSendToAnotherThread());
     60}
     61
     62static void checkThatXSSInfosAreSafeToSendToAnotherThread(const XSSInfoStream& xssInfos)
     63{
     64    for (size_t i = 0; i < xssInfos.size(); ++i)
     65        ASSERT(xssInfos[i]->isSafeToSendToAnotherThread());
    6066}
    6167
     
    248254
    249255        {
    250             OwnPtr<XSSInfo> xssInfo = m_xssAuditor->filterToken(FilterTokenRequest(*m_token, m_sourceTracker, m_tokenizer->shouldAllowCDATA()));
     256            TextPosition position = TextPosition(m_input.current().currentLine(), m_input.current().currentColumn());
     257
     258            if (OwnPtr<XSSInfo> xssInfo = m_xssAuditor->filterToken(FilterTokenRequest(*m_token, m_sourceTracker, m_tokenizer->shouldAllowCDATA()))) {
     259                xssInfo->m_textPosition = position;
     260                m_pendingXSSInfos.append(xssInfo.release());
     261            }
     262
    251263            CompactHTMLToken token(m_token.get(), TextPosition(m_input.current().currentLine(), m_input.current().currentColumn()));
    252 
    253             if (xssInfo)
    254                 token.setXSSInfo(xssInfo.release());
    255264
    256265            m_preloadScanner->scan(token, m_pendingPreloads);
     
    276285    checkThatTokensAreSafeToSendToAnotherThread(m_pendingTokens.get());
    277286    checkThatPreloadsAreSafeToSendToAnotherThread(m_pendingPreloads);
     287    checkThatXSSInfosAreSafeToSendToAnotherThread(m_pendingXSSInfos);
    278288#endif
    279289
     
    281291    chunk->tokens = m_pendingTokens.release();
    282292    chunk->preloads.swap(m_pendingPreloads);
     293    chunk->xssInfos.swap(m_pendingXSSInfos);
    283294    chunk->tokenizerState = m_tokenizer->state();
    284295    chunk->inputCheckpoint = m_input.createCheckpoint();
  • trunk/Source/WebCore/html/parser/BackgroundHTMLParser.h

    r143661 r144801  
    3636#include "HTMLToken.h"
    3737#include "HTMLTokenizer.h"
     38#include "XSSAuditorDelegate.h"
    3839#include <wtf/PassOwnPtr.h>
    3940#include <wtf/RefPtr.h>
     
    106107    OwnPtr<CompactHTMLTokenStream> m_pendingTokens;
    107108    PreloadRequestStream m_pendingPreloads;
     109    XSSInfoStream m_pendingXSSInfos;
    108110
    109111    OwnPtr<XSSAuditor> m_xssAuditor;
  • trunk/Source/WebCore/html/parser/CompactHTMLToken.cpp

    r143415 r144801  
    4242    Vector<Attribute> vector;
    4343    TextPosition textPosition;
    44     OwnPtr<XSSInfo> xssInfo;
    4544};
    4645
     
    9089}
    9190
    92 CompactHTMLToken::CompactHTMLToken(const CompactHTMLToken& other)
    93     : m_type(other.m_type)
    94     , m_selfClosing(other.m_selfClosing)
    95     , m_isAll8BitData(other.m_isAll8BitData)
    96     , m_doctypeForcesQuirks(other.m_doctypeForcesQuirks)
    97     , m_data(other.m_data)
    98     , m_attributes(other.m_attributes)
    99     , m_textPosition(other.m_textPosition)
    100 {
    101     if (other.m_xssInfo)
    102         m_xssInfo = adoptPtr(new XSSInfo(*other.m_xssInfo));
    103 }
    104 
    10591const CompactHTMLToken::Attribute* CompactHTMLToken::getAttributeItem(const QualifiedName& name) const
    10692{
     
    120106            return false;
    121107    }
    122     if (m_xssInfo && !m_xssInfo->isSafeToSendToAnotherThread())
    123         return false;
    124108    return m_data.isSafeToSendToAnotherThread();
    125 }
    126 
    127 XSSInfo* CompactHTMLToken::xssInfo() const
    128 {
    129     return m_xssInfo.get();
    130 }
    131 
    132 void CompactHTMLToken::setXSSInfo(PassOwnPtr<XSSInfo> xssInfo)
    133 {
    134     m_xssInfo = xssInfo;
    135109}
    136110
  • trunk/Source/WebCore/html/parser/CompactHTMLToken.h

    r143415 r144801  
    4141
    4242class QualifiedName;
    43 class XSSInfo;
    4443
    4544class CompactHTMLToken {
     
    5756
    5857    CompactHTMLToken(const HTMLToken*, const TextPosition&);
    59     CompactHTMLToken(const CompactHTMLToken&);
    6058
    6159    bool isSafeToSendToAnotherThread() const;
     
    7472    const String& systemIdentifier() const { return m_attributes[0].value; }
    7573    bool doctypeForcesQuirks() const { return m_doctypeForcesQuirks; }
    76     XSSInfo* xssInfo() const;
    77     void setXSSInfo(PassOwnPtr<XSSInfo>);
    7874
    7975private:
     
    8682    Vector<Attribute> m_attributes;
    8783    TextPosition m_textPosition;
    88     OwnPtr<XSSInfo> m_xssInfo;
    8984};
    9085
     
    9388}
    9489
    95 namespace WTF {
    96 // This is required for a struct with OwnPtr. We know CompactHTMLToken is simple enough that
    97 // initializing to 0 and moving with memcpy (and then not destructing the original) will work.
    98 template<> struct VectorTraits<WebCore::CompactHTMLToken> : SimpleClassVectorTraits { };
    99 }
    100 
    10190#endif // ENABLE(THREADED_HTML_PARSER)
    10291
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.cpp

    r144756 r144801  
    394394    OwnPtr<CompactHTMLTokenStream> tokens = m_currentChunk->tokens.release();
    395395
     396    for (XSSInfoStream::const_iterator it = m_currentChunk->xssInfos.begin(); it != m_currentChunk->xssInfos.end(); ++it) {
     397        m_textPosition = (*it)->m_textPosition;
     398        m_xssAuditorDelegate.didBlockScript(**it);
     399        if (isStopped())
     400            break;
     401    }
     402
    396403    for (Vector<CompactHTMLToken>::const_iterator it = tokens->begin(); it != tokens->end(); ++it) {
    397404        ASSERT(!isWaitingForScripts());
    398405
    399406        m_textPosition = it->textPosition();
    400 
    401         if (XSSInfo* xssInfo = it->xssInfo())
    402             m_xssAuditorDelegate.didBlockScript(*xssInfo);
    403407
    404408        constructTreeFromCompactHTMLToken(*it);
  • trunk/Source/WebCore/html/parser/HTMLDocumentParser.h

    r144714 r144801  
    9090        OwnPtr<CompactHTMLTokenStream> tokens;
    9191        PreloadRequestStream preloads;
     92        XSSInfoStream xssInfos;
    9293        HTMLTokenizer::State tokenizerState;
    9394        HTMLInputCheckpoint inputCheckpoint;
  • trunk/Source/WebCore/html/parser/XSSAuditorDelegate.h

    r142004 r144801  
    2828
    2929#include "KURL.h"
     30#include <wtf/OwnPtr.h>
    3031#include <wtf/PassOwnPtr.h>
     32#include <wtf/Vector.h>
     33#include <wtf/text/TextPosition.h>
    3134#include <wtf/text/WTFString.h>
    3235
     
    4851    String m_originalHTTPBody;
    4952    bool m_didBlockEntirePage;
     53    TextPosition m_textPosition;
    5054
    5155private:
     
    7074};
    7175
     76typedef Vector<OwnPtr<XSSInfo> > XSSInfoStream;
     77
    7278}
    7379
Note: See TracChangeset for help on using the changeset viewer.