Title: [149528] trunk/Source/WebCore
Revision
149528
Author
[email protected]
Date
2013-05-03 12:11:28 -0700 (Fri, 03 May 2013)

Log Message

Simplify CSSSelectorList creation/adoption.
<http://webkit.org/b/106649>

Reviewed by Antti Koivisto.

Remove the optimization that special-cased construction of CSSSelectorLists with a single entry.
This is in preparation for changing the way we store the selector lists on style rules.

* css/CSSParser.h:
* css/CSSSelector.h:

    Remove move(PassOwnPtr<CSSSelector> from, CSSSelector* to), inlining it into
    CSSSelectorList::adoptSelectorVector instead.

* css/CSSSelectorList.cpp:
(WebCore::CSSSelectorList::CSSSelectorList):
(WebCore::CSSSelectorList::deleteSelectors):

    Handle all selector list lengths the same way.

(WebCore::CSSSelectorList::adoptSelectorVector):

    Merge move() from CSSSelector.h into this code since it was the only call site.
    Also some minor readability cleanups.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149527 => 149528)


--- trunk/Source/WebCore/ChangeLog	2013-05-03 18:46:45 UTC (rev 149527)
+++ trunk/Source/WebCore/ChangeLog	2013-05-03 19:11:28 UTC (rev 149528)
@@ -1,3 +1,30 @@
+2013-01-11  Andreas Kling  <[email protected]>
+
+        Simplify CSSSelectorList creation/adoption.
+        <http://webkit.org/b/106649>
+
+        Reviewed by Antti Koivisto.
+
+        Remove the optimization that special-cased construction of CSSSelectorLists with a single entry.
+        This is in preparation for changing the way we store the selector lists on style rules.
+
+        * css/CSSParser.h:
+        * css/CSSSelector.h:
+
+            Remove move(PassOwnPtr<CSSSelector> from, CSSSelector* to), inlining it into
+            CSSSelectorList::adoptSelectorVector instead.
+
+        * css/CSSSelectorList.cpp:
+        (WebCore::CSSSelectorList::CSSSelectorList):
+        (WebCore::CSSSelectorList::deleteSelectors):
+
+            Handle all selector list lengths the same way.
+
+        (WebCore::CSSSelectorList::adoptSelectorVector):
+
+            Merge move() from CSSSelector.h into this code since it was the only call site.
+            Also some minor readability cleanups.
+
 2013-05-03  Antti Koivisto  <[email protected]>
 
         Remove HTMLShadowElement

Modified: trunk/Source/WebCore/css/CSSParser.h (149527 => 149528)


--- trunk/Source/WebCore/css/CSSParser.h	2013-05-03 18:46:45 UTC (rev 149527)
+++ trunk/Source/WebCore/css/CSSParser.h	2013-05-03 19:11:28 UTC (rev 149528)
@@ -30,7 +30,6 @@
 #include "CSSProperty.h"
 #include "CSSPropertyNames.h"
 #include "CSSPropertySourceData.h"
-#include "CSSSelector.h"
 #include "Color.h"
 #include "MediaQuery.h"
 #include <wtf/HashMap.h>

Modified: trunk/Source/WebCore/css/CSSSelector.h (149527 => 149528)


--- trunk/Source/WebCore/css/CSSSelector.h	2013-05-03 18:46:45 UTC (rev 149527)
+++ trunk/Source/WebCore/css/CSSSelector.h	2013-05-03 19:11:28 UTC (rev 149528)
@@ -373,14 +373,6 @@
     m_data.m_value->ref();
 }
 
-inline void move(PassOwnPtr<CSSSelector> from, CSSSelector* to)
-{
-    memcpy(to, from.get(), sizeof(CSSSelector));
-    // We want to free the memory (which was allocated with fastNew), but we
-    // don't want the destructor to run since it will affect the copy we've just made.
-    fastDeleteSkippingDestructor(from.leakPtr());
-}
-
 inline CSSSelector::CSSSelector()
     : m_relation(Descendant)
     , m_match(Unknown)

Modified: trunk/Source/WebCore/css/CSSSelectorList.cpp (149527 => 149528)


--- trunk/Source/WebCore/css/CSSSelectorList.cpp	2013-05-03 18:46:45 UTC (rev 149527)
+++ trunk/Source/WebCore/css/CSSSelectorList.cpp	2013-05-03 19:11:28 UTC (rev 149528)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2012, 2013 Apple Inc. All rights reserved.
  * Copyright (C) 2009 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -37,17 +37,12 @@
     deleteSelectors();
 }
 
-CSSSelectorList::CSSSelectorList(const CSSSelectorList& o)
+CSSSelectorList::CSSSelectorList(const CSSSelectorList& other)
 {
-    unsigned length = o.length();
-    if (length == 1) {
-        // Destructor expects a single selector to be allocated by new, multiple with fastMalloc.
-        m_selectorArray = new CSSSelector(o.m_selectorArray[0]);
-        return;
-    }
-    m_selectorArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * length));
-    for (unsigned i = 0; i < length; ++i)
-        new (&m_selectorArray[i]) CSSSelector(o.m_selectorArray[i]);
+    unsigned otherLength = other.length();
+    m_selectorArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * otherLength));
+    for (unsigned i = 0; i < otherLength; ++i)
+        new (NotNull, &m_selectorArray[i]) CSSSelector(other.m_selectorArray[i]);
 }
 
 void CSSSelectorList::adopt(CSSSelectorList& list)
@@ -60,28 +55,24 @@
 void CSSSelectorList::adoptSelectorVector(Vector<OwnPtr<CSSParserSelector> >& selectorVector)
 {
     deleteSelectors();
-    const size_t vectorSize = selectorVector.size();
     size_t flattenedSize = 0;
-    for (size_t i = 0; i < vectorSize; ++i) {
+    for (size_t i = 0; i < selectorVector.size(); ++i) {
         for (CSSParserSelector* selector = selectorVector[i].get(); selector; selector = selector->tagHistory())
             ++flattenedSize;
     }
     ASSERT(flattenedSize);
-    if (flattenedSize == 1) {
-        m_selectorArray = selectorVector[0]->releaseSelector().leakPtr();
-        m_selectorArray->setLastInSelectorList();
-        ASSERT(m_selectorArray->isLastInTagHistory());
-        selectorVector.shrink(0);
-        return;
-    }
     m_selectorArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * flattenedSize));
     size_t arrayIndex = 0;
-    for (size_t i = 0; i < vectorSize; ++i) {
+    for (size_t i = 0; i < selectorVector.size(); ++i) {
         CSSParserSelector* current = selectorVector[i].get();
         while (current) {
-            OwnPtr<CSSSelector> selector = current->releaseSelector();
+            {
+                // Move item from the parser selector vector into m_selectorArray without invoking destructor (Ugh.)
+                CSSSelector* currentSelector = current->releaseSelector().leakPtr();
+                memcpy(&m_selectorArray[arrayIndex], currentSelector, sizeof(CSSSelector));
+                fastDeleteSkippingDestructor(currentSelector);
+            }
             current = current->tagHistory();
-            move(selector.release(), &m_selectorArray[arrayIndex]);
             ASSERT(!m_selectorArray[arrayIndex].isLastInSelectorList());
             if (current)
                 m_selectorArray[arrayIndex].setNotLastInTagHistory();
@@ -91,7 +82,7 @@
     }
     ASSERT(flattenedSize == arrayIndex);
     m_selectorArray[arrayIndex - 1].setLastInSelectorList();
-    selectorVector.shrink(0);
+    selectorVector.clear();
 }
 
 unsigned CSSSelectorList::length() const
@@ -109,24 +100,9 @@
     if (!m_selectorArray)
         return;
 
-    // We had two cases in adoptSelectVector. The fast case of a 1 element
-    // vector took the CSSSelector directly, which was allocated with new.
-    // The second case we allocated a new fastMalloc buffer, which should be
-    // freed with fastFree, and the destructors called manually.
-    CSSSelector* s = m_selectorArray;
-    bool done = s->isLastInSelectorList();
-    if (done)
-        delete s;
-    else {
-        while (1) {
-            s->~CSSSelector();
-            if (done)
-                break;
-            ++s;
-            done = s->isLastInSelectorList();
-        }
-        fastFree(m_selectorArray);
-    }
+    for (CSSSelector* s = m_selectorArray; !s->isLastInSelectorList(); ++s)
+        s->~CSSSelector();
+    fastFree(m_selectorArray);
 }
 
 String CSSSelectorList::selectorsText() const
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to