Commit d18be865 authored by rniwa@webkit.org's avatar rniwa@webkit.org

Devirtualize Document class type checking

https://bugs.webkit.org/show_bug.cgi?id=115755

Reviewed by Benjamin Poulain.

Merge https://chromium.googlesource.com/chromium/blink/+/dae5adc768d5ce6bff301df6515745da8ea24950

Document has a bunch of virtual bool is*Document() methods on it, but it also has
two bools for XHTML and HTML documents which is silly. We can merge them all
together into an enum of values and devirtualize the type checking methods.

* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::createElement):
* dom/Document.h:
(WebCore::Document::create):
(WebCore::Document::createXHTML):
(WebCore::Document::isHTMLDocument):
(WebCore::Document::isXHTMLDocument):
(WebCore::Document::isImageDocument):
(WebCore::Document::isSVGDocument):
(WebCore::Document::isPluginDocument):
(WebCore::Document::isMediaDocument):
(WebCore::Document):
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::HTMLDocument):
* html/HTMLDocument.h:
(WebCore::HTMLDocument):
* html/ImageDocument.cpp:
(WebCore::ImageDocument::ImageDocument):
* html/ImageDocument.h:
(WebCore::ImageDocument):
* html/MediaDocument.cpp:
(WebCore::MediaDocument::MediaDocument):
* html/MediaDocument.h:
(WebCore::MediaDocument):
* html/PluginDocument.cpp:
(WebCore::PluginDocument::PluginDocument):
* html/PluginDocument.h:
(WebCore::PluginDocument):
* loader/PlaceholderDocument.h:
(WebCore::PlaceholderDocument::PlaceholderDocument):
* svg/SVGDocument.cpp:
(WebCore::SVGDocument::SVGDocument):
* svg/SVGDocument.h:
(WebCore::SVGDocument):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@149705 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 632a93ca
2013-05-07 Ryosuke Niwa <rniwa@webkit.org>
Devirtualize Document class type checking
https://bugs.webkit.org/show_bug.cgi?id=115755
Reviewed by Benjamin Poulain.
Merge https://chromium.googlesource.com/chromium/blink/+/dae5adc768d5ce6bff301df6515745da8ea24950
Document has a bunch of virtual bool is*Document() methods on it, but it also has
two bools for XHTML and HTML documents which is silly. We can merge them all
together into an enum of values and devirtualize the type checking methods.
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::createElement):
* dom/Document.h:
(WebCore::Document::create):
(WebCore::Document::createXHTML):
(WebCore::Document::isHTMLDocument):
(WebCore::Document::isXHTMLDocument):
(WebCore::Document::isImageDocument):
(WebCore::Document::isSVGDocument):
(WebCore::Document::isPluginDocument):
(WebCore::Document::isMediaDocument):
(WebCore::Document):
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::HTMLDocument):
* html/HTMLDocument.h:
(WebCore::HTMLDocument):
* html/ImageDocument.cpp:
(WebCore::ImageDocument::ImageDocument):
* html/ImageDocument.h:
(WebCore::ImageDocument):
* html/MediaDocument.cpp:
(WebCore::MediaDocument::MediaDocument):
* html/MediaDocument.h:
(WebCore::MediaDocument):
* html/PluginDocument.cpp:
(WebCore::PluginDocument::PluginDocument):
* html/PluginDocument.h:
(WebCore::PluginDocument):
* loader/PlaceholderDocument.h:
(WebCore::PlaceholderDocument::PlaceholderDocument):
* svg/SVGDocument.cpp:
(WebCore::SVGDocument::SVGDocument):
* svg/SVGDocument.h:
(WebCore::SVGDocument):
2013-05-07 Anders Carlsson <andersca@apple.com>
Begin unraveling the mess that is QuotesData
......
......@@ -413,7 +413,7 @@ static HashSet<Document*>* documentsThatNeedStyleRecalc = 0;
uint64_t Document::s_globalTreeVersion = 0;
Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
Document::Document(Frame* frame, const KURL& url, unsigned documentClasses)
: ContainerNode(0, CreateDocument)
, TreeScope(this)
, m_styleResolverThrowawayTimer(this, &Document::styleResolverThrowawayTimerFired)
......@@ -451,8 +451,7 @@ Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
, m_createRenderers(true)
, m_inPageCache(false)
, m_accessKeyMapValid(false)
, m_isXHTML(isXHTML)
, m_isHTML(isHTML)
, m_documentClasses(documentClasses)
, m_isViewSource(false)
, m_sawElementsInKnownNamespaces(false)
, m_isSrcdocDocument(false)
......@@ -828,7 +827,7 @@ PassRefPtr<Element> Document::createElement(const AtomicString& name, ExceptionC
return 0;
}
if (m_isXHTML)
if (isXHTMLDocument())
return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, name, xhtmlNamespaceURI), this, 0, false);
return createElement(QualifiedName(nullAtom, name, nullAtom), false);
......
......@@ -220,15 +220,27 @@ const int numNodeListInvalidationTypes = InvalidateOnAnyAttrChange + 1;
typedef HashCountedSet<Node*> TouchEventTargetSet;
enum DocumentClass {
DefaultDocumentClass = 0,
HTMLDocumentClass = 1,
XHTMLDocumentClass = 1 << 1,
ImageDocumentClass = 1 << 2,
PluginDocumentClass = 1 << 3,
MediaDocumentClass = 1 << 4,
SVGDocumentClass = 1 << 5,
};
typedef unsigned char DocumentClassFlags;
class Document : public ContainerNode, public TreeScope, public ScriptExecutionContext {
public:
static PassRefPtr<Document> create(Frame* frame, const KURL& url)
{
return adoptRef(new Document(frame, url, false, false));
return adoptRef(new Document(frame, url));
}
static PassRefPtr<Document> createXHTML(Frame* frame, const KURL& url)
{
return adoptRef(new Document(frame, url, true, false));
return adoptRef(new Document(frame, url, XHTMLDocumentClass));
}
virtual ~Document();
......@@ -427,18 +439,17 @@ public:
PassRefPtr<HTMLCollection> documentNamedItems(const AtomicString& name);
// Other methods (not part of DOM)
bool isHTMLDocument() const { return m_isHTML; }
bool isXHTMLDocument() const { return m_isXHTML; }
virtual bool isImageDocument() const { return false; }
bool isHTMLDocument() const { return m_documentClasses & HTMLDocumentClass; }
bool isXHTMLDocument() const { return m_documentClasses & XHTMLDocumentClass; }
bool isImageDocument() const { return m_documentClasses & ImageDocumentClass; }
bool isSVGDocument() const { return m_documentClasses & SVGDocumentClass; }
bool isPluginDocument() const { return m_documentClasses & PluginDocumentClass; }
bool isMediaDocument() const { return m_documentClasses & MediaDocumentClass; }
#if ENABLE(SVG)
virtual bool isSVGDocument() const { return false; }
bool hasSVGRootNode() const;
#else
static bool isSVGDocument() { return false; }
static bool hasSVGRootNode() { return false; }
#endif
virtual bool isPluginDocument() const { return false; }
virtual bool isMediaDocument() const { return false; }
virtual bool isFrameSet() const { return false; }
bool isSrcdocDocument() const { return m_isSrcdocDocument; }
......@@ -1207,7 +1218,7 @@ public:
void ensurePlugInsInjectedScript(DOMWrapperWorld*);
protected:
Document(Frame*, const KURL&, bool isXHTML, bool isHTML);
Document(Frame*, const KURL&, unsigned = DefaultDocumentClass);
virtual void didUpdateSecurityOrigin() OVERRIDE;
......@@ -1474,8 +1485,7 @@ private:
OwnPtr<SelectorQueryCache> m_selectorQueryCache;
bool m_isXHTML;
bool m_isHTML;
DocumentClassFlags m_documentClasses;
bool m_isViewSource;
bool m_sawElementsInKnownNamespaces;
......
......@@ -81,8 +81,8 @@ namespace WebCore {
using namespace HTMLNames;
HTMLDocument::HTMLDocument(Frame* frame, const KURL& url)
: Document(frame, url, false, true)
HTMLDocument::HTMLDocument(Frame* frame, const KURL& url, DocumentClassFlags documentClasses)
: Document(frame, url, documentClasses | HTMLDocumentClass)
{
clearXMLVersion();
}
......
......@@ -75,7 +75,7 @@ public:
static bool isCaseSensitiveAttribute(const QualifiedName&);
protected:
HTMLDocument(Frame*, const KURL&);
HTMLDocument(Frame*, const KURL&, DocumentClassFlags = 0);
private:
virtual PassRefPtr<Element> createElement(const AtomicString& tagName, ExceptionCode&);
......
......@@ -177,7 +177,7 @@ void ImageDocumentParser::finish()
// --------
ImageDocument::ImageDocument(Frame* frame, const KURL& url)
: HTMLDocument(frame, url)
: HTMLDocument(frame, url, ImageDocumentClass)
, m_imageElement(0)
, m_imageSizeIsKnown(false)
, m_didShrinkImage(false)
......
......@@ -51,7 +51,6 @@ private:
ImageDocument(Frame*, const KURL&);
virtual PassRefPtr<DocumentParser> createParser();
virtual bool isImageDocument() const { return true; }
void createDocumentStructure();
void resizeImageToFit();
......
......@@ -118,7 +118,7 @@ void MediaDocumentParser::appendBytes(DocumentWriter*, const char*, size_t)
}
MediaDocument::MediaDocument(Frame* frame, const KURL& url)
: HTMLDocument(frame, url)
: HTMLDocument(frame, url, MediaDocumentClass)
, m_replaceMediaElementTimer(this, &MediaDocument::replaceMediaElementTimerFired)
{
setCompatibilityMode(QuirksMode);
......
......@@ -45,7 +45,6 @@ public:
private:
MediaDocument(Frame*, const KURL&);
virtual bool isMediaDocument() const { return true; }
virtual PassRefPtr<DocumentParser> createParser();
virtual void defaultEventHandler(Event*);
......
......@@ -136,7 +136,7 @@ void PluginDocumentParser::appendBytes(DocumentWriter*, const char*, size_t)
}
PluginDocument::PluginDocument(Frame* frame, const KURL& url)
: HTMLDocument(frame, url)
: HTMLDocument(frame, url, PluginDocumentClass)
, m_shouldLoadPluginManually(true)
{
setCompatibilityMode(QuirksMode);
......
......@@ -54,8 +54,7 @@ private:
PluginDocument(Frame*, const KURL&);
virtual PassRefPtr<DocumentParser> createParser() OVERRIDE;
virtual bool isPluginDocument() const OVERRIDE { return true; }
void setShouldLoadPluginManually(bool loadManually) { m_shouldLoadPluginManually = loadManually; }
bool m_shouldLoadPluginManually;
......
......@@ -40,7 +40,9 @@ public:
virtual void attach();
private:
PlaceholderDocument(Frame* frame, const KURL& url) : Document(frame, url, false, false) { }
PlaceholderDocument(Frame* frame, const KURL& url)
: Document(frame, url)
{ }
};
} // namespace WebCore
......
......@@ -37,7 +37,7 @@
namespace WebCore {
SVGDocument::SVGDocument(Frame* frame, const KURL& url)
: Document(frame, url, false, false)
: Document(frame, url, SVGDocumentClass)
{
}
......
......@@ -51,8 +51,6 @@ public:
private:
SVGDocument(Frame*, const KURL&);
virtual bool isSVGDocument() const { return true; }
virtual bool childShouldCreateRenderer(const NodeRenderingContext&) const;
FloatPoint m_translate;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment