Changeset 117809 in webkit


Ignore:
Timestamp:
May 21, 2012 12:36:39 PM (12 years ago)
Author:
kling@webkit.org
Message:

CSS: Move duplicate property elimination to parser.
<http://webkit.org/b/86948>

Reviewed by Antti Koivisto.

Source/WebCore:

Remove the StylePropertySet constructor that handled elimination of duplicate
properties and move that to a new parser method, CSSParser::filteredProperties().
Call sites are converted to using StylePropertySet(const Vector<CSSProperty>&).

Instead of building a hashmap of seen properties, use the new WTF::BitArray class
to track whether a given property ID has been seen, and whether we have an
!important entry for a given ID.

  • css/CSSParser.cpp:

(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseDeclaration):
(WebCore::CSSParser::filteredProperties):
(WebCore::CSSParser::createStyleRule):
(WebCore::CSSParser::createFontFaceRule):
(WebCore::CSSParser::createPageRule):
(WebCore::CSSParser::createKeyframe):

  • css/CSSParser.h:
  • css/StylePropertySet.cpp:

(WebCore::StylePropertySet::StylePropertySet):
(WebCore::StylePropertySet::addParsedProperties):

  • css/StylePropertySet.h:

(WebCore::StylePropertySet::create):
(StylePropertySet):

  • svg/SVGFontFaceElement.cpp:

(WebCore::SVGFontFaceElement::rebuildFontFace):

Source/WTF:

Add WTF::BitArray, a simple, malloc free, fixed-size bit array class.

  • GNUmakefile.list.am:
  • WTF.gypi:
  • WTF.pro:
  • WTF.vcproj/WTF.vcproj:
  • WTF.xcodeproj/project.pbxproj:
  • wtf/BitArray.h: Added.

(WTF):
(BitArray):
(WTF::BitArray::BitArray):
(WTF::BitArray::set):
(WTF::BitArray::get):

  • wtf/CMakeLists.txt:
Location:
trunk/Source
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r117779 r117809  
     12012-05-21  Andreas Kling  <kling@webkit.org>
     2
     3        CSS: Move duplicate property elimination to parser.
     4        <http://webkit.org/b/86948>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Add WTF::BitArray, a simple, malloc free, fixed-size bit array class.
     9
     10        * GNUmakefile.list.am:
     11        * WTF.gypi:
     12        * WTF.pro:
     13        * WTF.vcproj/WTF.vcproj:
     14        * WTF.xcodeproj/project.pbxproj:
     15        * wtf/BitArray.h: Added.
     16        (WTF):
     17        (BitArray):
     18        (WTF::BitArray::BitArray):
     19        (WTF::BitArray::set):
     20        (WTF::BitArray::get):
     21        * wtf/CMakeLists.txt:
     22
    1232012-05-21  Allan Sandfeld Jensen  <allan.jensen@nokia.com>
    224
  • trunk/Source/WTF/GNUmakefile.list.am

    r115248 r117809  
    1313    Source/WTF/wtf/Assertions.h \
    1414    Source/WTF/wtf/Atomics.h \
     15    Source/WTF/wtf/BitArray.h \
    1516    Source/WTF/wtf/BitVector.cpp \
    1617    Source/WTF/wtf/BitVector.h \
  • trunk/Source/WTF/WTF.gypi

    r115248 r117809  
    99            'wtf/Assertions.h',
    1010            'wtf/Atomics.h',
     11            'wtf/BitArray.h',
    1112            'wtf/BitVector.h',
    1213            'wtf/Bitmap.h',
  • trunk/Source/WTF/WTF.pro

    r115248 r117809  
    2323    AVLTree.h \
    2424    Bitmap.h \
     25    BitArray.h \
    2526    BitVector.h \
    2627    BloomFilter.h \
  • trunk/Source/WTF/WTF.vcproj/WTF.vcproj

    r115248 r117809  
    606606                </File>
    607607                <File
     608                        RelativePath="..\wtf\BitArray.h"
     609                        >
     610                </File>
     611                <File
    608612                        RelativePath="..\wtf\BitVector.cpp"
    609613                        >
  • trunk/Source/WTF/WTF.xcodeproj/project.pbxproj

    r117008 r117809  
    88
    99/* Begin PBXBuildFile section */
     10                4F0321BC156AA8D1006EBAF6 /* BitArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 4F0321BB156AA8D1006EBAF6 /* BitArray.h */; };
    1011                A876DBD8151816E500DADB95 /* Platform.h in Headers */ = {isa = PBXBuildFile; fileRef = A876DBD7151816E500DADB95 /* Platform.h */; };
    1112                A8A4737F151A825B004123FF /* Alignment.h in Headers */ = {isa = PBXBuildFile; fileRef = A8A47254151A825A004123FF /* Alignment.h */; };
     
    241242
    242243/* Begin PBXFileReference section */
     244                4F0321BB156AA8D1006EBAF6 /* BitArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BitArray.h; sourceTree = "<group>"; };
    243245                5D247B6214689B8600E78B76 /* libWTF.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWTF.a; sourceTree = BUILT_PRODUCTS_DIR; };
    244246                5D247B6E14689C4700E78B76 /* Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
     
    547549                                A8A4725E151A825A004123FF /* AVLTree.h */,
    548550                                A8A4725F151A825A004123FF /* Bitmap.h */,
     551                                4F0321BB156AA8D1006EBAF6 /* BitArray.h */,
    549552                                A8A47260151A825A004123FF /* BitVector.cpp */,
    550553                                A8A47261151A825A004123FF /* BitVector.h */,
     
    861864                                A8A47389151A825B004123FF /* AVLTree.h in Headers */,
    862865                                A8A4738A151A825B004123FF /* Bitmap.h in Headers */,
     866                                4F0321BC156AA8D1006EBAF6 /* BitArray.h in Headers */,
    863867                                A8A4738C151A825B004123FF /* BitVector.h in Headers */,
    864868                                A8A4738E151A825B004123FF /* BlockStack.h in Headers */,
  • trunk/Source/WTF/wtf/CMakeLists.txt

    r115248 r117809  
    66    Assertions.h
    77    Atomics.h
     8    BitArray.h
    89    BitVector.h
    910    Bitmap.h
  • trunk/Source/WebCore/ChangeLog

    r117808 r117809  
     12012-05-21  Andreas Kling  <kling@webkit.org>
     2
     3        CSS: Move duplicate property elimination to parser.
     4        <http://webkit.org/b/86948>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Remove the StylePropertySet constructor that handled elimination of duplicate
     9        properties and move that to a new parser method, CSSParser::filteredProperties().
     10        Call sites are converted to using StylePropertySet(const Vector<CSSProperty>&).
     11
     12        Instead of building a hashmap of seen properties, use the new WTF::BitArray class
     13        to track whether a given property ID has been seen, and whether we have an
     14        !important entry for a given ID.
     15
     16        * css/CSSParser.cpp:
     17        (WebCore::CSSParser::parseValue):
     18        (WebCore::CSSParser::parseDeclaration):
     19        (WebCore::CSSParser::filteredProperties):
     20        (WebCore::CSSParser::createStyleRule):
     21        (WebCore::CSSParser::createFontFaceRule):
     22        (WebCore::CSSParser::createPageRule):
     23        (WebCore::CSSParser::createKeyframe):
     24        * css/CSSParser.h:
     25        * css/StylePropertySet.cpp:
     26        (WebCore::StylePropertySet::StylePropertySet):
     27        (WebCore::StylePropertySet::addParsedProperties):
     28        * css/StylePropertySet.h:
     29        (WebCore::StylePropertySet::create):
     30        (StylePropertySet):
     31        * svg/SVGFontFaceElement.cpp:
     32        (WebCore::SVGFontFaceElement::rebuildFontFace):
     33
    1342012-05-21  Joshua Bell  <jsbell@chromium.org>
    235
  • trunk/Source/WebCore/css/CSSParser.cpp

    r117622 r117809  
    9090#endif
    9191#include <limits.h>
     92#include <wtf/BitArray.h>
    9293#include <wtf/HexNumber.h>
    9394#include <wtf/dtoa.h>
     
    978979    if (!m_parsedProperties.isEmpty()) {
    979980        ok = true;
    980         declaration->addParsedProperties(m_parsedProperties.data(), m_parsedProperties.size());
     981        declaration->addParsedProperties(m_parsedProperties);
    981982        clearProperties();
    982983    }
     
    10741075    if (!m_parsedProperties.isEmpty()) {
    10751076        ok = true;
    1076         declaration->addParsedProperties(m_parsedProperties.data(), m_parsedProperties.size());
     1077        declaration->addParsedProperties(m_parsedProperties);
    10771078        clearProperties();
    10781079    }
     
    11081109
    11091110    return m_mediaQuery.release();
     1111}
     1112
     1113Vector<CSSProperty> CSSParser::filteredProperties() const
     1114{
     1115    BitArray<numCSSProperties> seenProperties;
     1116    BitArray<numCSSProperties> seenImportantProperties;
     1117
     1118    Vector<CSSProperty> results;
     1119    results.reserveInitialCapacity(m_parsedProperties.size());
     1120
     1121    for (unsigned i = 0; i < m_parsedProperties.size(); ++i) {
     1122        const CSSProperty& property = m_parsedProperties[i];
     1123        const unsigned propertyIDIndex = property.id() - firstCSSProperty;
     1124
     1125        // Ignore non-important properties if we already have an important property with the same ID.
     1126        if (!property.isImportant() && seenImportantProperties.get(propertyIDIndex))
     1127            continue;
     1128
     1129        // If we already had this property, this new one takes precedence, so wipe out the old one.
     1130        if (seenProperties.get(propertyIDIndex)) {
     1131            for (unsigned i = 0; i < results.size(); ++i) {
     1132                if (results[i].id() == property.id()) {
     1133                    results.remove(i);
     1134                    break;
     1135                }
     1136            }
     1137        }
     1138
     1139        if (property.isImportant())
     1140            seenImportantProperties.set(propertyIDIndex);
     1141        seenProperties.set(propertyIDIndex);
     1142
     1143        results.append(property);
     1144    }
     1145
     1146    return results;
    11101147}
    11111148
     
    90429079        if (m_hasFontFaceOnlyValues)
    90439080            deleteFontFaceOnlyValues();
    9044         rule->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_context.mode));
     9081        rule->setProperties(StylePropertySet::create(filteredProperties(), m_context.mode));
    90459082        result = rule.get();
    90469083        m_parsedRules.append(rule.release());
     
    90789115    }
    90799116    RefPtr<StyleRuleFontFace> rule = StyleRuleFontFace::create();
    9080     rule->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_context.mode));
     9117    rule->setProperties(StylePropertySet::create(filteredProperties(), m_context.mode));
    90819118    clearProperties();
    90829119    StyleRuleFontFace* result = rule.get();
     
    91519188        selectorVector.append(pageSelector);
    91529189        rule->parserAdoptSelectorVector(selectorVector);
    9153         rule->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_context.mode));
     9190        rule->setProperties(StylePropertySet::create(filteredProperties(), m_context.mode));
    91549191        pageRule = rule.get();
    91559192        m_parsedRules.append(rule.release());
     
    92299266    RefPtr<StyleKeyframe> keyframe = StyleKeyframe::create();
    92309267    keyframe->setKeyText(keyString);
    9231     keyframe->setProperties(StylePropertySet::create(m_parsedProperties.data(), m_parsedProperties.size(), m_context.mode));
     9268    keyframe->setProperties(StylePropertySet::create(filteredProperties(), m_context.mode));
    92329269
    92339270    clearProperties();
  • trunk/Source/WebCore/css/CSSParser.h

    r117613 r117809  
    283283    void clearProperties();
    284284
     285    Vector<CSSProperty> filteredProperties() const;
     286
    285287    CSSParserContext m_context;
    286288
  • trunk/Source/WebCore/css/StylePropertySet.cpp

    r117369 r117809  
    5757}
    5858
    59 StylePropertySet::StylePropertySet(const Vector<CSSProperty>& properties)
     59StylePropertySet::StylePropertySet(const Vector<CSSProperty>& properties, CSSParserMode cssParserMode)
    6060    : m_properties(properties)
    61     , m_cssParserMode(CSSStrictMode)
     61    , m_cssParserMode(cssParserMode)
    6262    , m_ownsCSSOMWrapper(false)
    6363{
    6464    m_properties.shrinkToFit();
    65 }
    66 
    67 StylePropertySet::StylePropertySet(const CSSProperty* properties, int numProperties, CSSParserMode cssParserMode)
    68     : m_cssParserMode(cssParserMode)
    69     , m_ownsCSSOMWrapper(false)
    70 {
    71     // FIXME: This logic belongs in CSSParser.
    72 
    73     m_properties.reserveInitialCapacity(numProperties);
    74     HashMap<int, bool> candidates;
    75     for (int i = 0; i < numProperties; ++i) {
    76         const CSSProperty& property = properties[i];
    77         bool important = property.isImportant();
    78 
    79         HashMap<int, bool>::iterator it = candidates.find(property.id());
    80         if (it != candidates.end()) {
    81             if (!important && it->second)
    82                 continue;
    83             removeProperty(property.id());
    84         }
    85 
    86         m_properties.append(property);
    87         candidates.set(property.id(), important);
    88     }
    8965}
    9066
     
    593569}
    594570
    595 void StylePropertySet::addParsedProperties(const CSSProperty* properties, int numProperties)
    596 {
    597     m_properties.reserveCapacity(numProperties);
    598     for (int i = 0; i < numProperties; ++i)
     571void StylePropertySet::addParsedProperties(const Vector<CSSProperty>& properties)
     572{
     573    m_properties.reserveCapacity(m_properties.size() + properties.size());
     574    for (unsigned i = 0; i < properties.size(); ++i)
    599575        addParsedProperty(properties[i]);
    600576}
  • trunk/Source/WebCore/css/StylePropertySet.h

    r117369 r117809  
    4848        return adoptRef(new StylePropertySet(cssParserMode));
    4949    }
    50     static PassRefPtr<StylePropertySet> create(const CSSProperty* properties, int numProperties, CSSParserMode cssParserMode)
     50    static PassRefPtr<StylePropertySet> create(const Vector<CSSProperty>& properties, CSSParserMode cssParserMode = CSSStrictMode)
    5151    {
    52         return adoptRef(new StylePropertySet(properties, numProperties, cssParserMode));
    53     }
    54     static PassRefPtr<StylePropertySet> create(const Vector<CSSProperty>& properties)
    55     {
    56         return adoptRef(new StylePropertySet(properties));
     52        return adoptRef(new StylePropertySet(properties, cssParserMode));
    5753    }
    5854
     
    8177    void parseDeclaration(const String& styleDeclaration, StyleSheetInternal* contextStyleSheet);
    8278
    83     void addParsedProperties(const CSSProperty*, int numProperties);
     79    void addParsedProperties(const Vector<CSSProperty>&);
    8480    void addParsedProperty(const CSSProperty&);
    8581
     
    122118private:
    123119    StylePropertySet(CSSParserMode);
    124     StylePropertySet(const Vector<CSSProperty>&);
     120    StylePropertySet(const Vector<CSSProperty>&, CSSParserMode);
    125121    StylePropertySet(const StylePropertySet&);
    126     StylePropertySet(const CSSProperty*, int numProperties, CSSParserMode);
    127122
    128123    void setNeedsStyleRecalc();
  • trunk/Source/WebCore/svg/SVGFontFaceElement.cpp

    r117195 r117809  
    298298
    299299    // Parse in-memory CSS rules
    300     CSSProperty srcProperty(CSSPropertySrc, list);
    301     m_fontFaceRule->properties()->addParsedProperties(&srcProperty, 1);
     300    m_fontFaceRule->properties()->addParsedProperty(CSSProperty(CSSPropertySrc, list));
    302301
    303302    if (describesParentFont) {   
Note: See TracChangeset for help on using the changeset viewer.