CascadedProperties should use a bitset to track property presence.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Dec 2013 12:15:44 +0000 (12:15 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 19 Dec 2013 12:15:44 +0000 (12:15 +0000)
<https://webkit.org/b/125991>

Avoid zeroing out a bunch of memory in the CascadedProperties ctor
by using a bitset to track whether each property is present in the
cascaded set.

Reviewed by Antti Koivisto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@160828 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/StyleResolver.cpp

index 6a01d2273680cf199cca08fbc3c978d2c2c2126d..37ce84bd062cb77935854de3a49330685ae600fd 100644 (file)
@@ -1,3 +1,14 @@
+2013-12-19  Andreas Kling  <akling@apple.com>
+
+        CascadedProperties should use a bitset to track property presence.
+        <https://webkit.org/b/125991>
+
+        Avoid zeroing out a bunch of memory in the CascadedProperties ctor
+        by using a bitset to track whether each property is present in the
+        cascaded set.
+
+        Reviewed by Antti Koivisto.
+
 2013-12-19  Seokju Kwon  <seokju@webkit.org>
 
         Web Inspector: Fix description of parameters in Page.setGeolocationOverride
index 15f45dc3a65252f60efe2d3bad1a8ebe324e6d82..8cf9f99ea07a9e15813db395d734136e978cfe02 100644 (file)
 #include "WebKitCSSTransformValue.h"
 #include "WebKitFontFamilyNames.h"
 #include "XMLNames.h"
+#include <bitset>
 #include <wtf/StdLibExtras.h>
 #include <wtf/Vector.h>
 
@@ -199,10 +200,10 @@ public:
         void apply(StyleResolver&);
 
         CSSPropertyID id;
-        bool isPresent;
         CSSValue* cssValue[3];
     };
 
+    bool hasProperty(CSSPropertyID id) const { return m_propertyIsPresent.test(id); }
     Property& property(CSSPropertyID);
     bool addMatches(const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly);
 
@@ -216,6 +217,8 @@ private:
     static void setPropertyInternal(Property&, CSSPropertyID, CSSValue&, unsigned linkMatchType);
 
     Property m_properties[numCSSProperties + 1];
+    std::bitset<numCSSProperties + 1> m_propertyIsPresent;
+
     Vector<Property> m_deferredProperties;
 
     TextDirection m_direction;
@@ -4196,7 +4199,6 @@ StyleResolver::CascadedProperties::CascadedProperties(TextDirection direction, W
     : m_direction(direction)
     , m_writingMode(writingMode)
 {
-    memset(&m_properties, 0, sizeof(m_properties));
 }
 
 inline StyleResolver::CascadedProperties::Property& StyleResolver::CascadedProperties::property(CSSPropertyID id)
@@ -4208,7 +4210,6 @@ void StyleResolver::CascadedProperties::setPropertyInternal(Property& property,
 {
     ASSERT(linkMatchType <= SelectorChecker::MatchAll);
     property.id = id;
-    property.isPresent = true;
     if (linkMatchType == SelectorChecker::MatchAll) {
         property.cssValue[0] = &cssValue;
         property.cssValue[SelectorChecker::MatchLink] = &cssValue;
@@ -4225,6 +4226,9 @@ void StyleResolver::CascadedProperties::set(CSSPropertyID id, CSSValue& cssValue
     ASSERT(!shouldApplyPropertyInParseOrder(id));
 
     auto& property = m_properties[id];
+    if (!m_propertyIsPresent.test(id))
+        memset(property.cssValue, 0, sizeof(property.cssValue));
+    m_propertyIsPresent.set(id);
     setPropertyInternal(property, id, cssValue, linkMatchType);
 }
 
@@ -4328,10 +4332,11 @@ void StyleResolver::CascadedProperties::Property::apply(StyleResolver& resolver)
 void StyleResolver::applyCascadedProperties(CascadedProperties& cascade, int firstProperty, int lastProperty)
 {
     for (int id = firstProperty; id <= lastProperty; ++id) {
-        auto& property = cascade.property(static_cast<CSSPropertyID>(id));
-        if (!property.isPresent)
+        CSSPropertyID propertyID = static_cast<CSSPropertyID>(id);
+        if (!cascade.hasProperty(propertyID))
             continue;
-        ASSERT(!shouldApplyPropertyInParseOrder(property.id));
+        auto& property = cascade.property(propertyID);
+        ASSERT(!shouldApplyPropertyInParseOrder(propertyID));
         property.apply(*this);
     }
 }