Title: [167877] trunk/Source/WebCore
Revision
167877
Author
[email protected]
Date
2014-04-28 01:12:08 -0700 (Mon, 28 Apr 2014)

Log Message

std::bitset<>::test() does unnecessary bounds checks on CSSPropertyID bitsets
https://bugs.webkit.org/show_bug.cgi?id=131685

Reviewed by Darin Adler.

Use std::bitset<>::operator[]() instead of std::bitset<>::test() to avoid
bounds checks which are not necessary as long as a CSSPropertyID value is used.

* css/CSSParser.cpp:
(WebCore::filterProperties):
* css/StyleProperties.cpp:
(WebCore::StyleProperties::asText):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::CascadedProperties::hasProperty):
(WebCore::StyleResolver::CascadedProperties::set):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (167876 => 167877)


--- trunk/Source/WebCore/ChangeLog	2014-04-28 08:06:54 UTC (rev 167876)
+++ trunk/Source/WebCore/ChangeLog	2014-04-28 08:12:08 UTC (rev 167877)
@@ -1,3 +1,21 @@
+2014-04-28  Zan Dobersek  <[email protected]>
+
+        std::bitset<>::test() does unnecessary bounds checks on CSSPropertyID bitsets
+        https://bugs.webkit.org/show_bug.cgi?id=131685
+
+        Reviewed by Darin Adler.
+
+        Use std::bitset<>::operator[]() instead of std::bitset<>::test() to avoid
+        bounds checks which are not necessary as long as a CSSPropertyID value is used.
+
+        * css/CSSParser.cpp:
+        (WebCore::filterProperties):
+        * css/StyleProperties.cpp:
+        (WebCore::StyleProperties::asText):
+        * css/StyleResolver.cpp:
+        (WebCore::StyleResolver::CascadedProperties::hasProperty):
+        (WebCore::StyleResolver::CascadedProperties::set):
+
 2014-04-28  Carlos Garcia Campos  <[email protected]>
 
         [GTK] TextTrack kind and mode attributes are enums since r166180

Modified: trunk/Source/WebCore/css/CSSParser.cpp (167876 => 167877)


--- trunk/Source/WebCore/css/CSSParser.cpp	2014-04-28 08:06:54 UTC (rev 167876)
+++ trunk/Source/WebCore/css/CSSParser.cpp	2014-04-28 08:12:08 UTC (rev 167877)
@@ -1474,7 +1474,8 @@
         if (property.isImportant() != important)
             continue;
         const unsigned propertyIDIndex = property.id() - firstCSSProperty;
-        if (seenProperties.test(propertyIDIndex))
+        ASSERT(propertyIDIndex < seenProperties.size());
+        if (seenProperties[propertyIDIndex])
             continue;
         seenProperties.set(propertyIDIndex);
         output[--unusedEntries] = property;

Modified: trunk/Source/WebCore/css/StyleProperties.cpp (167876 => 167877)


--- trunk/Source/WebCore/css/StyleProperties.cpp	2014-04-28 08:06:54 UTC (rev 167876)
+++ trunk/Source/WebCore/css/StyleProperties.cpp	2014-04-28 08:12:08 UTC (rev 167877)
@@ -826,13 +826,14 @@
                 borderFallbackShorthandProperty = CSSPropertyBorderColor;
 
             // FIXME: Deal with cases where only some of border-(top|right|bottom|left) are specified.
-            if (!shorthandPropertyAppeared.test(CSSPropertyBorder - firstCSSProperty)) {
+            ASSERT(CSSPropertyBorder - firstCSSProperty < shorthandPropertyAppeared.size());
+            if (!shorthandPropertyAppeared[CSSPropertyBorder - firstCSSProperty]) {
                 value = borderPropertyValue(ReturnNullOnUncommonValues);
                 if (value.isNull())
                     shorthandPropertyAppeared.set(CSSPropertyBorder - firstCSSProperty);
                 else
                     shorthandPropertyID = CSSPropertyBorder;
-            } else if (shorthandPropertyUsed.test(CSSPropertyBorder - firstCSSProperty))
+            } else if (shorthandPropertyUsed[CSSPropertyBorder - firstCSSProperty])
                 shorthandPropertyID = CSSPropertyBorder;
             if (!shorthandPropertyID)
                 shorthandPropertyID = borderFallbackShorthandProperty;
@@ -927,9 +928,10 @@
 
         unsigned shortPropertyIndex = shorthandPropertyID - firstCSSProperty;
         if (shorthandPropertyID) {
-            if (shorthandPropertyUsed.test(shortPropertyIndex))
+            ASSERT(shortPropertyIndex < shorthandPropertyUsed.size());
+            if (shorthandPropertyUsed[shortPropertyIndex])
                 continue;
-            if (!shorthandPropertyAppeared.test(shortPropertyIndex) && value.isNull())
+            if (!shorthandPropertyAppeared[shortPropertyIndex] && value.isNull())
                 value = getPropertyValue(shorthandPropertyID);
             shorthandPropertyAppeared.set(shortPropertyIndex);
         }

Modified: trunk/Source/WebCore/css/StyleResolver.cpp (167876 => 167877)


--- trunk/Source/WebCore/css/StyleResolver.cpp	2014-04-28 08:06:54 UTC (rev 167876)
+++ trunk/Source/WebCore/css/StyleResolver.cpp	2014-04-28 08:12:08 UTC (rev 167877)
@@ -184,7 +184,7 @@
         CSSValue* cssValue[3];
     };
 
-    bool hasProperty(CSSPropertyID id) const { return m_propertyIsPresent.test(id); }
+    bool hasProperty(CSSPropertyID id) const;
     Property& property(CSSPropertyID);
     bool addMatches(const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly = false);
 
@@ -3665,6 +3665,12 @@
 {
 }
 
+inline bool StyleResolver::CascadedProperties::hasProperty(CSSPropertyID id) const
+{
+    ASSERT(id < m_propertyIsPresent.size());
+    return m_propertyIsPresent[id];
+}
+
 inline StyleResolver::CascadedProperties::Property& StyleResolver::CascadedProperties::property(CSSPropertyID id)
 {
     return m_properties[id];
@@ -3690,7 +3696,8 @@
     ASSERT(!shouldApplyPropertyInParseOrder(id));
 
     auto& property = m_properties[id];
-    if (!m_propertyIsPresent.test(id))
+    ASSERT(id < m_propertyIsPresent.size());
+    if (!m_propertyIsPresent[id])
         memset(property.cssValue, 0, sizeof(property.cssValue));
     m_propertyIsPresent.set(id);
     setPropertyInternal(property, id, cssValue, linkMatchType);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to