- Revision
- 128331
- Author
- morr...@google.com
- Date
- 2012-09-12 09:54:55 -0700 (Wed, 12 Sep 2012)
Log Message
[Scoped Style] NodeRareData::m_numberOfScopedHTMLStyleChildren could be replaced with a node flag.
https://bugs.webkit.org/show_bug.cgi?id=96450
Reviewed by Dimitri Glazkov.
This change gets rid of NodeRareData::m_numberOfScopedHTMLStyleChildren
by replacing it with a Node flag called HasScopedHTMLStyleChildFlag.
Instead of tracking the number of certain node, this chagne compute the number
when necessary.
Now we no longer need to hit rareData() for each hasScopedHTMLStyleChild() call.
Note that because such a re-counting occurs only when the scoped <style> elements
leave the tree, the performance impact is negligible.
No new tests. Covered by existing tests.
* dom/Node.cpp:
(WebCore):
* dom/Node.h:
(WebCore::Node::hasScopedHTMLStyleChild):
(WebCore::Node::setHasScopedHTMLStyleChild):
(Node):
* dom/NodeRareData.h:
(WebCore::NodeRareData::NodeRareData):
(NodeRareData):
* html/HTMLStyleElement.cpp:
(WebCore::HTMLStyleElement::isRegisteredAsScoped):
(WebCore):
(WebCore::Node::registerScopedHTMLStyleChild):
(WebCore::Node::unregisterScopedHTMLStyleChild):
(WebCore::Node::numberOfScopedHTMLStyleChildren):
(WebCore::HTMLStyleElement::unregisterWithScopingNode):
* html/HTMLStyleElement.h:
(HTMLStyleElement):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (128330 => 128331)
--- trunk/Source/WebCore/ChangeLog 2012-09-12 16:51:43 UTC (rev 128330)
+++ trunk/Source/WebCore/ChangeLog 2012-09-12 16:54:55 UTC (rev 128331)
@@ -1,3 +1,40 @@
+2012-09-11 MORITA Hajime <morr...@google.com>
+
+ [Scoped Style] NodeRareData::m_numberOfScopedHTMLStyleChildren could be replaced with a node flag.
+ https://bugs.webkit.org/show_bug.cgi?id=96450
+
+ Reviewed by Dimitri Glazkov.
+
+ This change gets rid of NodeRareData::m_numberOfScopedHTMLStyleChildren
+ by replacing it with a Node flag called HasScopedHTMLStyleChildFlag.
+ Instead of tracking the number of certain node, this chagne compute the number
+ when necessary.
+
+ Now we no longer need to hit rareData() for each hasScopedHTMLStyleChild() call.
+ Note that because such a re-counting occurs only when the scoped <style> elements
+ leave the tree, the performance impact is negligible.
+
+ No new tests. Covered by existing tests.
+
+ * dom/Node.cpp:
+ (WebCore):
+ * dom/Node.h:
+ (WebCore::Node::hasScopedHTMLStyleChild):
+ (WebCore::Node::setHasScopedHTMLStyleChild):
+ (Node):
+ * dom/NodeRareData.h:
+ (WebCore::NodeRareData::NodeRareData):
+ (NodeRareData):
+ * html/HTMLStyleElement.cpp:
+ (WebCore::HTMLStyleElement::isRegisteredAsScoped):
+ (WebCore):
+ (WebCore::Node::registerScopedHTMLStyleChild):
+ (WebCore::Node::unregisterScopedHTMLStyleChild):
+ (WebCore::Node::numberOfScopedHTMLStyleChildren):
+ (WebCore::HTMLStyleElement::unregisterWithScopingNode):
+ * html/HTMLStyleElement.h:
+ (HTMLStyleElement):
+
2012-09-12 Dimitri Glazkov <dglaz...@chromium.org>
Remove transient state regarding uknown pseudoelements from SelectorChecker.
Modified: trunk/Source/WebCore/dom/Node.cpp (128330 => 128331)
--- trunk/Source/WebCore/dom/Node.cpp 2012-09-12 16:51:43 UTC (rev 128330)
+++ trunk/Source/WebCore/dom/Node.cpp 2012-09-12 16:54:55 UTC (rev 128331)
@@ -2535,40 +2535,6 @@
}
#endif // ENABLE(MUTATION_OBSERVERS)
-#if ENABLE(STYLE_SCOPED)
-bool Node::hasScopedHTMLStyleChild() const
-{
- return hasRareData() && rareData()->hasScopedHTMLStyleChild();
-}
-
-size_t Node::numberOfScopedHTMLStyleChildren() const
-{
- return hasRareData() ? rareData()->numberOfScopedHTMLStyleChildren() : 0;
-}
-
-void Node::registerScopedHTMLStyleChild()
-{
- ensureRareData()->registerScopedHTMLStyleChild();
-}
-
-void Node::unregisterScopedHTMLStyleChild()
-{
- ASSERT(hasRareData());
- if (hasRareData())
- rareData()->unregisterScopedHTMLStyleChild();
-}
-#else
-bool Node::hasScopedHTMLStyleChild() const
-{
- return 0;
-}
-
-size_t Node::numberOfScopedHTMLStyleChildren() const
-{
- return 0;
-}
-#endif
-
void Node::handleLocalEvents(Event* event)
{
if (!hasRareData() || !rareData()->eventTargetData())
Modified: trunk/Source/WebCore/dom/Node.h (128330 => 128331)
--- trunk/Source/WebCore/dom/Node.h 2012-09-12 16:51:43 UTC (rev 128330)
+++ trunk/Source/WebCore/dom/Node.h 2012-09-12 16:54:55 UTC (rev 128331)
@@ -349,6 +349,9 @@
void setHasAttrList() { setFlag(HasAttrListFlag); }
void clearHasAttrList() { clearFlag(HasAttrListFlag); }
+ bool hasScopedHTMLStyleChild() const { return getFlag(HasScopedHTMLStyleChildFlag); }
+ void setHasScopedHTMLStyleChild(bool flag) { setFlag(flag, HasScopedHTMLStyleChildFlag); }
+
enum ShouldSetAttached {
SetAttached,
DoNotSetAttached
@@ -658,11 +661,8 @@
void notifyMutationObserversNodeWillDetach();
#endif // ENABLE(MUTATION_OBSERVERS)
-#if ENABLE(STYLE_SCOPED)
void registerScopedHTMLStyleChild();
void unregisterScopedHTMLStyleChild();
-#endif
- bool hasScopedHTMLStyleChild() const;
size_t numberOfScopedHTMLStyleChildren() const;
virtual void reportMemoryUsage(MemoryObjectInfo*) const;
@@ -710,10 +710,11 @@
#endif
InNamedFlowFlag = 1 << 26,
HasAttrListFlag = 1 << 27,
- HasCustomCallbacksFlag = 1 << 28
+ HasCustomCallbacksFlag = 1 << 28,
+ HasScopedHTMLStyleChildFlag = 1 << 29
};
- // 4 bits remaining
+ // 3 bits remaining
bool getFlag(NodeFlags mask) const { return m_nodeFlags & mask; }
void setFlag(bool f, NodeFlags mask) const { m_nodeFlags = (m_nodeFlags & ~mask) | (-(int32_t)f & mask); }
Modified: trunk/Source/WebCore/dom/NodeRareData.h (128330 => 128331)
--- trunk/Source/WebCore/dom/NodeRareData.h 2012-09-12 16:51:43 UTC (rev 128330)
+++ trunk/Source/WebCore/dom/NodeRareData.h 2012-09-12 16:54:55 UTC (rev 128331)
@@ -186,9 +186,6 @@
, m_tabIndexWasSetExplicitly(false)
, m_isFocused(false)
, m_needsFocusAppearanceUpdateSoonAfterAttach(false)
-#if ENABLE(STYLE_SCOPED)
- , m_numberOfScopedHTMLStyleChildren(0)
-#endif
{
}
@@ -311,30 +308,6 @@
}
#endif
-#if ENABLE(STYLE_SCOPED)
- void registerScopedHTMLStyleChild()
- {
- ++m_numberOfScopedHTMLStyleChildren;
- }
-
- void unregisterScopedHTMLStyleChild()
- {
- ASSERT(m_numberOfScopedHTMLStyleChildren > 0);
- if (m_numberOfScopedHTMLStyleChildren > 0)
- --m_numberOfScopedHTMLStyleChildren;
- }
-
- bool hasScopedHTMLStyleChild() const
- {
- return m_numberOfScopedHTMLStyleChildren;
- }
-
- size_t numberOfScopedHTMLStyleChildren() const
- {
- return m_numberOfScopedHTMLStyleChildren;
- }
-#endif
-
bool isFocused() const { return m_isFocused; }
void setFocused(bool focused) { m_isFocused = focused; }
@@ -364,10 +337,6 @@
mutable RefPtr<DOMSettableTokenList> m_itemRef;
mutable RefPtr<DOMSettableTokenList> m_itemType;
#endif
-
-#if ENABLE(STYLE_SCOPED)
- size_t m_numberOfScopedHTMLStyleChildren;
-#endif
};
} // namespace WebCore
Modified: trunk/Source/WebCore/html/HTMLStyleElement.cpp (128330 => 128331)
--- trunk/Source/WebCore/html/HTMLStyleElement.cpp 2012-09-12 16:51:43 UTC (rev 128330)
+++ trunk/Source/WebCore/html/HTMLStyleElement.cpp 2012-09-12 16:54:55 UTC (rev 128331)
@@ -123,6 +123,42 @@
}
#if ENABLE(STYLE_SCOPED)
+inline bool HTMLStyleElement::isRegisteredAsScoped() const
+{
+ // Note: We cannot rely on the 'scoped' attribute still being present when this method is invoked.
+ // Therefore we cannot rely on scoped()!
+ if (m_scopedStyleRegistrationState == NotRegistered)
+ return false;
+ if (!ContextFeatures::styleScopedEnabled(document()))
+ return false;
+ return true;
+}
+
+// These three Node methods are placed here to
+// make the header inclusion dependency sane.
+
+inline void Node::registerScopedHTMLStyleChild()
+{
+ setHasScopedHTMLStyleChild(true);
+}
+
+inline void Node::unregisterScopedHTMLStyleChild()
+{
+ ASSERT(hasScopedHTMLStyleChild());
+ setHasScopedHTMLStyleChild(numberOfScopedHTMLStyleChildren());
+}
+
+size_t Node::numberOfScopedHTMLStyleChildren() const
+{
+ size_t count = 0;
+ for (Node* child = firstChild(); child; child = child->nextSibling()) {
+ if (child->hasTagName(styleTag) && static_cast<HTMLStyleElement*>(child)->isRegisteredAsScoped())
+ count++;
+ }
+
+ return count;
+}
+
void HTMLStyleElement::registerWithScopingNode(bool scoped)
{
// Note: We cannot rely on the 'scoped' element already being present when this method is invoked.
@@ -154,13 +190,9 @@
void HTMLStyleElement::unregisterWithScopingNode(ContainerNode* scope)
{
- // Note: We cannot rely on the 'scoped' element still being present when this method is invoked.
- // Therefore we cannot rely on scoped()!
ASSERT(m_scopedStyleRegistrationState != NotRegistered || !ContextFeatures::styleScopedEnabled(document()));
- if (m_scopedStyleRegistrationState == NotRegistered)
+ if (!isRegisteredAsScoped())
return;
- if (!ContextFeatures::styleScopedEnabled(document()))
- return;
ASSERT(scope);
if (scope) {
@@ -173,6 +205,11 @@
m_scopedStyleRegistrationState = NotRegistered;
}
+#else
+size_t Node::numberOfScopedHTMLStyleChildren() const
+{
+ return 0;
+}
#endif
Node::InsertionNotificationRequest HTMLStyleElement::insertedInto(ContainerNode* insertionPoint)
Modified: trunk/Source/WebCore/html/HTMLStyleElement.h (128330 => 128331)
--- trunk/Source/WebCore/html/HTMLStyleElement.h 2012-09-12 16:51:43 UTC (rev 128330)
+++ trunk/Source/WebCore/html/HTMLStyleElement.h 2012-09-12 16:54:55 UTC (rev 128331)
@@ -45,6 +45,7 @@
bool scoped() const;
void setScoped(bool);
Element* scopingElement() const;
+ bool isRegisteredAsScoped() const;
#endif
using StyleElement::sheet;