Diff
Modified: trunk/Source/WebCore/ChangeLog (99170 => 99171)
--- trunk/Source/WebCore/ChangeLog 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/ChangeLog 2011-11-03 12:14:49 UTC (rev 99171)
@@ -1,3 +1,46 @@
+2011-11-03 Andreas Kling <[email protected]>
+
+ Devirtualize CSSRule.
+ https://bugs.webkit.org/show_bug.cgi?id=71382
+
+ Reviewed by Antti Koivisto.
+
+ Remove the virtual destructor from CSSRule, and reimplement RefCounted's deref()
+ to invoke operator delete on the appropriate subclass type.
+
+ This removes the CSSRule vtable and shrinks each instance by one CPU word.
+
+ * css/CSSCharsetRule.h:
+ * css/CSSFontFaceRule.h:
+ * css/CSSMediaRule.h:
+ * css/CSSPageRule.h:
+ * css/CSSRegionStyleRule.h:
+ * css/CSSRule.cpp:
+ * css/CSSRule.h:
+ (WebCore::CSSRule::deref):
+ (WebCore::CSSRule::~CSSRule):
+ * css/CSSStyleRule.h:
+ * css/WebKitCSSKeyframeRule.h:
+
+ Devirtualize!
+
+ * css/CSSRule.cpp:
+ (WebCore::CSSRule::destroy):
+
+ Added, invokes operator delete on the right subclass type.
+
+ * css/CSSImportRule.cpp:
+ (WebCore::CSSImportRule::CSSImportRule):
+ (WebCore::CSSImportRule::~CSSImportRule):
+ (WebCore::CSSImportRule::requestStyleSheet):
+ * css/CSSImportRule.h:
+ (WebCore::CSSImportRule::ImportedStyleSheetClient::ImportedStyleSheetClient):
+ (WebCore::CSSImportRule::ImportedStyleSheetClient::~ImportedStyleSheetClient):
+ (WebCore::CSSImportRule::ImportedStyleSheetClient::setCSSStyleSheet):
+
+ Break out the inheritance from CachedStyleSheetClient into a member variable
+ that simply redirects the setCSSStyleSheet() callback to the CSSImportRule.
+
2011-10-31 Hans Wennborg <[email protected]>
IndexedDB: Recycle cursor objects when calling continue()
Modified: trunk/Source/WebCore/css/CSSCharsetRule.h (99170 => 99171)
--- trunk/Source/WebCore/css/CSSCharsetRule.h 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSCharsetRule.h 2011-11-03 12:14:49 UTC (rev 99171)
@@ -34,7 +34,7 @@
return adoptRef(new CSSCharsetRule(parent, encoding));
}
- virtual ~CSSCharsetRule();
+ ~CSSCharsetRule();
const String& encoding() const { return m_encoding; }
void setEncoding(const String& encoding, ExceptionCode&) { m_encoding = encoding; }
Modified: trunk/Source/WebCore/css/CSSFontFaceRule.h (99170 => 99171)
--- trunk/Source/WebCore/css/CSSFontFaceRule.h 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSFontFaceRule.h 2011-11-03 12:14:49 UTC (rev 99171)
@@ -41,7 +41,7 @@
return adoptRef(new CSSFontFaceRule(parent));
}
- virtual ~CSSFontFaceRule();
+ ~CSSFontFaceRule();
CSSMutableStyleDeclaration* style() const { return m_style.get(); }
Modified: trunk/Source/WebCore/css/CSSImportRule.cpp (99170 => 99171)
--- trunk/Source/WebCore/css/CSSImportRule.cpp 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSImportRule.cpp 2011-11-03 12:14:49 UTC (rev 99171)
@@ -33,6 +33,7 @@
CSSImportRule::CSSImportRule(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaList> media)
: CSSRule(parent, CSSRule::IMPORT_RULE)
+ , m_styleSheetClient(this)
, m_strHref(href)
, m_lstMedia(media)
, m_cachedSheet(0)
@@ -51,7 +52,7 @@
if (m_styleSheet)
m_styleSheet->setParentRule(0);
if (m_cachedSheet)
- m_cachedSheet->removeClient(this);
+ m_cachedSheet->removeClient(&m_styleSheetClient);
}
void CSSImportRule::setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet)
@@ -146,7 +147,7 @@
if (parentSheet && parentSheet->loadCompleted() && rootSheet == parentSheet)
parentSheet->startLoadingDynamicSheet();
m_loading = true;
- m_cachedSheet->addClient(this);
+ m_cachedSheet->addClient(&m_styleSheetClient);
}
}
Modified: trunk/Source/WebCore/css/CSSImportRule.h (99170 => 99171)
--- trunk/Source/WebCore/css/CSSImportRule.h 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSImportRule.h 2011-11-03 12:14:49 UTC (rev 99171)
@@ -33,7 +33,7 @@
class CachedCSSStyleSheet;
class MediaList;
-class CSSImportRule : public CSSRule, private CachedStyleSheetClient {
+class CSSImportRule : public CSSRule {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassRefPtr<CSSImportRule> create(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaList> media)
@@ -41,7 +41,7 @@
return adoptRef(new CSSImportRule(parent, href, media));
}
- virtual ~CSSImportRule();
+ ~CSSImportRule();
String href() const { return m_strHref; }
MediaList* media() const { return m_lstMedia.get(); }
@@ -57,11 +57,26 @@
void requestStyleSheet();
private:
+ // NOTE: We put the CachedStyleSheetClient in a member instead of inheriting from it
+ // to avoid adding a vptr to CSSImportRule.
+ class ImportedStyleSheetClient : public CachedStyleSheetClient {
+ public:
+ ImportedStyleSheetClient(CSSImportRule* ownerRule) : m_ownerRule(ownerRule) { }
+ virtual ~ImportedStyleSheetClient() { }
+ virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet* sheet)
+ {
+ m_ownerRule->setCSSStyleSheet(href, baseURL, charset, sheet);
+ }
+ private:
+ CSSImportRule* m_ownerRule;
+ };
+
+ void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet*);
+ friend class ImportedStyleSheetClient;
+
CSSImportRule(CSSStyleSheet* parent, const String& href, PassRefPtr<MediaList>);
- // from CachedResourceClient
- virtual void setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CachedCSSStyleSheet*);
-
+ ImportedStyleSheetClient m_styleSheetClient;
String m_strHref;
RefPtr<MediaList> m_lstMedia;
RefPtr<CSSStyleSheet> m_styleSheet;
Modified: trunk/Source/WebCore/css/CSSMediaRule.h (99170 => 99171)
--- trunk/Source/WebCore/css/CSSMediaRule.h 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSMediaRule.h 2011-11-03 12:14:49 UTC (rev 99171)
@@ -38,7 +38,7 @@
{
return adoptRef(new CSSMediaRule(parent, media, rules));
}
- virtual ~CSSMediaRule();
+ ~CSSMediaRule();
MediaList* media() const { return m_lstMedia.get(); }
CSSRuleList* cssRules() { return m_lstCSSRules.get(); }
Modified: trunk/Source/WebCore/css/CSSPageRule.h (99170 => 99171)
--- trunk/Source/WebCore/css/CSSPageRule.h 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSPageRule.h 2011-11-03 12:14:49 UTC (rev 99171)
@@ -39,7 +39,7 @@
return adoptRef(new CSSPageRule(parent, sourceLine));
}
- virtual ~CSSPageRule();
+ ~CSSPageRule();
String pageSelectorText() const;
Modified: trunk/Source/WebCore/css/CSSRegionStyleRule.h (99170 => 99171)
--- trunk/Source/WebCore/css/CSSRegionStyleRule.h 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSRegionStyleRule.h 2011-11-03 12:14:49 UTC (rev 99171)
@@ -49,7 +49,7 @@
return adoptRef(new CSSRegionStyleRule(parent, selectors, rules));
}
- virtual ~CSSRegionStyleRule();
+ ~CSSRegionStyleRule();
String cssText() const;
const CSSSelectorList& selectorList() const { return m_selectorList; }
Modified: trunk/Source/WebCore/css/CSSRule.cpp (99170 => 99171)
--- trunk/Source/WebCore/css/CSSRule.cpp 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSRule.cpp 2011-11-03 12:14:49 UTC (rev 99171)
@@ -29,6 +29,7 @@
#include "CSSPageRule.h"
#include "CSSRegionStyleRule.h"
#include "CSSStyleRule.h"
+#include "CSSUnknownRule.h"
#include "WebKitCSSKeyframeRule.h"
#include "WebKitCSSKeyframesRule.h"
#include "NotImplemented.h"
@@ -67,4 +68,41 @@
return String();
}
+void CSSRule::destroy()
+{
+ switch (type()) {
+ case UNKNOWN_RULE:
+ delete static_cast<CSSUnknownRule*>(this);
+ return;
+ case STYLE_RULE:
+ delete static_cast<CSSStyleRule*>(this);
+ return;
+ case PAGE_RULE:
+ delete static_cast<CSSPageRule*>(this);
+ return;
+ case CHARSET_RULE:
+ delete static_cast<CSSCharsetRule*>(this);
+ return;
+ case IMPORT_RULE:
+ delete static_cast<CSSImportRule*>(this);
+ return;
+ case MEDIA_RULE:
+ delete static_cast<CSSMediaRule*>(this);
+ return;
+ case FONT_FACE_RULE:
+ delete static_cast<CSSFontFaceRule*>(this);
+ return;
+ case WEBKIT_KEYFRAMES_RULE:
+ delete static_cast<WebKitCSSKeyframesRule*>(this);
+ return;
+ case WEBKIT_KEYFRAME_RULE:
+ delete static_cast<WebKitCSSKeyframeRule*>(this);
+ return;
+ case WEBKIT_REGION_STYLE_RULE:
+ delete static_cast<CSSRegionStyleRule*>(this);
+ return;
+ }
+ ASSERT_NOT_REACHED();
+}
+
} // namespace WebCore
Modified: trunk/Source/WebCore/css/CSSRule.h (99170 => 99171)
--- trunk/Source/WebCore/css/CSSRule.h 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSRule.h 2011-11-03 12:14:49 UTC (rev 99171)
@@ -33,7 +33,13 @@
class CSSRule : public RefCounted<CSSRule> {
public:
- virtual ~CSSRule() { }
+ // Override RefCounted's deref() to ensure operator delete is called on
+ // the appropriate subclass type.
+ void deref()
+ {
+ if (derefBase())
+ destroy();
+ }
enum Type {
UNKNOWN_RULE,
@@ -109,7 +115,14 @@
{
}
+ // NOTE: This class is non-virtual for memory and performance reasons.
+ // Don't go making it virtual again unless you know exactly what you're doing!
+
+ ~CSSRule() { }
+
private:
+ void destroy();
+
bool m_parentIsRule : 1;
unsigned m_type : 31; // Plenty of space for additional flags here.
union {
Modified: trunk/Source/WebCore/css/CSSStyleRule.h (99170 => 99171)
--- trunk/Source/WebCore/css/CSSStyleRule.h 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/CSSStyleRule.h 2011-11-03 12:14:49 UTC (rev 99171)
@@ -38,7 +38,7 @@
{
return adoptRef(new CSSStyleRule(parent, sourceLine));
}
- virtual ~CSSStyleRule();
+ ~CSSStyleRule();
String selectorText() const;
void setSelectorText(const String&);
Modified: trunk/Source/WebCore/css/WebKitCSSKeyframeRule.h (99170 => 99171)
--- trunk/Source/WebCore/css/WebKitCSSKeyframeRule.h 2011-11-03 12:09:47 UTC (rev 99170)
+++ trunk/Source/WebCore/css/WebKitCSSKeyframeRule.h 2011-11-03 12:14:49 UTC (rev 99171)
@@ -47,7 +47,7 @@
return adoptRef(new WebKitCSSKeyframeRule(parent));
}
- virtual ~WebKitCSSKeyframeRule();
+ ~WebKitCSSKeyframeRule();
String keyText() const { return m_key; }
void setKeyText(const String& s) { m_key = s; }