Changeset 102770 in webkit


Ignore:
Timestamp:
Dec 14, 2011 5:51:58 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Add different salt to different types of selectors. So the CSS fast
path can tell the different between tags and class attributes with
otherwise identical values.
https://bugs.webkit.org/show_bug.cgi?id=74284

Patch by Allan Sandfeld Jensen <allan.jensen@nokia.com> on 2011-12-14
Reviewed by Antti Koivisto.

  • css/SelectorChecker.cpp:

(WebCore::collectElementIdentifierHashes):
(WebCore::collectDescendantSelectorIdentifierHashes):

  • css/SelectorChecker.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r102768 r102770  
     12011-12-14  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
     2
     3        Add different salt to different types of selectors. So the CSS fast
     4        path can tell the different between tags and class attributes with
     5        otherwise identical values.
     6        https://bugs.webkit.org/show_bug.cgi?id=74284
     7
     8        Reviewed by Antti Koivisto.
     9
     10        * css/SelectorChecker.cpp:
     11        (WebCore::collectElementIdentifierHashes):
     12        (WebCore::collectDescendantSelectorIdentifierHashes):
     13        * css/SelectorChecker.h:
     14
    1152011-12-14  Pierre Rossi  <pierre.rossi@gmail.com>
    216
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r102606 r102770  
    7979}
    8080
     81// Salt to separate otherwise identical string hashes so a class-selector like .article won't match <article> elements.
     82enum { TagNameSalt = 13, IdAttributeSalt = 17, ClassAttributeSalt = 19 };
     83
    8184static inline void collectElementIdentifierHashes(const Element* element, Vector<unsigned, 4>& identifierHashes)
    8285{
    83     identifierHashes.append(element->localName().impl()->existingHash());
     86    identifierHashes.append(element->localName().impl()->existingHash() * TagNameSalt);
    8487    if (element->hasID())
    85         identifierHashes.append(element->idForStyleResolution().impl()->existingHash());
     88        identifierHashes.append(element->idForStyleResolution().impl()->existingHash() * IdAttributeSalt);
    8689    const StyledElement* styledElement = element->isStyledElement() ? static_cast<const StyledElement*>(element) : 0;
    8790    if (styledElement && styledElement->hasClass()) {
     
    8992        size_t count = classNames.size();
    9093        for (size_t i = 0; i < count; ++i)
    91             identifierHashes.append(classNames[i].impl()->existingHash());
     94            identifierHashes.append(classNames[i].impl()->existingHash() * ClassAttributeSalt);
    9295    }
    9396}
     
    163166static inline void collectDescendantSelectorIdentifierHashes(const CSSSelector* selector, unsigned*& hash, const unsigned* end)
    164167{
    165     if ((selector->m_match == CSSSelector::Id || selector->m_match == CSSSelector::Class) && !selector->value().isEmpty())
    166         (*hash++) = selector->value().impl()->existingHash();
     168    switch (selector->m_match) {
     169    case CSSSelector::Id:
     170        if (!selector->value().isEmpty())
     171            (*hash++) = selector->value().impl()->existingHash() * IdAttributeSalt;
     172        break;
     173    case CSSSelector::Class:
     174        if (!selector->value().isEmpty())
     175            (*hash++) = selector->value().impl()->existingHash() * ClassAttributeSalt;
     176        break;
     177    default:
     178        break;
     179    }
    167180    if (hash == end)
    168181        return;
    169182    const AtomicString& localName = selector->tag().localName();
    170183    if (localName != starAtom)
    171         (*hash++) = localName.impl()->existingHash();
     184        (*hash++) = localName.impl()->existingHash() * TagNameSalt;
    172185}
    173186
  • trunk/Source/WebCore/css/SelectorChecker.h

    r97854 r102770  
    119119    };
    120120    Vector<ParentStackFrame> m_parentStack;
    121 
     121   
    122122    // With 100 unique strings in the filter, 2^12 slot table has false positive rate of ~0.2%.
    123123    static const unsigned bloomFilterKeyBits = 12;
Note: See TracChangeset for help on using the changeset viewer.