Title: [131565] trunk/Source/WebCore
Revision
131565
Author
[email protected]
Date
2012-10-17 01:18:07 -0700 (Wed, 17 Oct 2012)

Log Message

Clean up ContentData operator overloads
https://bugs.webkit.org/show_bug.cgi?id=99556

Patch by Elliott Sprehn <[email protected]> on 2012-10-17
Reviewed by Eric Seidel.

Use virtual dispatch for checking ContentData equality instead
of a switch over the type. This the first step in getting rid
of the StyleContentType enum and all the switch statements over
the type().

No tests needed, this is just a refactor.

* rendering/style/ContentData.cpp:
* rendering/style/ContentData.h:
(ContentData):
(WebCore::operator==):
(WebCore):
(WebCore::operator!=):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (131564 => 131565)


--- trunk/Source/WebCore/ChangeLog	2012-10-17 08:15:47 UTC (rev 131564)
+++ trunk/Source/WebCore/ChangeLog	2012-10-17 08:18:07 UTC (rev 131565)
@@ -1,3 +1,24 @@
+2012-10-17  Elliott Sprehn  <[email protected]>
+
+        Clean up ContentData operator overloads
+        https://bugs.webkit.org/show_bug.cgi?id=99556
+
+        Reviewed by Eric Seidel.
+
+        Use virtual dispatch for checking ContentData equality instead
+        of a switch over the type. This the first step in getting rid
+        of the StyleContentType enum and all the switch statements over
+        the type().
+
+        No tests needed, this is just a refactor.        
+
+        * rendering/style/ContentData.cpp:
+        * rendering/style/ContentData.h:
+        (ContentData):
+        (WebCore::operator==):
+        (WebCore):
+        (WebCore::operator!=):
+
 2012-10-17  Gabor Rapcsanyi  <[email protected]>
 
         NEON intrinsics Gauss filter does not work properly

Modified: trunk/Source/WebCore/rendering/style/ContentData.cpp (131564 => 131565)


--- trunk/Source/WebCore/rendering/style/ContentData.cpp	2012-10-17 08:15:47 UTC (rev 131564)
+++ trunk/Source/WebCore/rendering/style/ContentData.cpp	2012-10-17 08:18:07 UTC (rev 131565)
@@ -22,8 +22,6 @@
 #include "config.h"
 #include "ContentData.h"
 
-#include "StyleImage.h"
-
 namespace WebCore {
 
 PassOwnPtr<ContentData> ContentData::create(PassRefPtr<StyleImage> image)
@@ -60,30 +58,4 @@
     return result.release();
 }
 
-bool operator==(const ContentData& a, const ContentData& b)
-{
-    if (a.type() != b.type())
-        return false;
-
-    switch (a.type()) {
-    case CONTENT_NONE:
-        return true;
-    case CONTENT_OBJECT:
-        return *static_cast<const ImageContentData*>(&a)->image() == *static_cast<const ImageContentData*>(&b)->image();
-    case CONTENT_TEXT:
-        return static_cast<const TextContentData*>(&a)->text() == static_cast<const TextContentData*>(&b)->text();
-    case CONTENT_COUNTER:
-        return *static_cast<const CounterContentData*>(&a)->counter() == *static_cast<const CounterContentData*>(&b)->counter();
-    case CONTENT_QUOTE:
-        return static_cast<const QuoteContentData*>(&a)->quote() == static_cast<const QuoteContentData*>(&b)->quote();
-    }
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool operator!=(const ContentData& a, const ContentData& b)
-{
-    return !(a == b);
-}
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/style/ContentData.h (131564 => 131565)


--- trunk/Source/WebCore/rendering/style/ContentData.h	2012-10-17 08:15:47 UTC (rev 131564)
+++ trunk/Source/WebCore/rendering/style/ContentData.h	2012-10-17 08:18:07 UTC (rev 131565)
@@ -26,6 +26,7 @@
 #define ContentData_h
 
 #include "CounterContent.h"
+#include "StyleImage.h"
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
 
@@ -49,15 +50,13 @@
     virtual bool isText() const { return false; }
 
     virtual StyleContentType type() const = 0;
-
-    friend bool operator==(const ContentData&, const ContentData&);
-    friend bool operator!=(const ContentData&, const ContentData&);
-
     virtual PassOwnPtr<ContentData> clone() const;
 
     ContentData* next() const { return m_next.get(); }
     void setNext(PassOwnPtr<ContentData> next) { m_next = next; }
 
+    virtual bool equals(const ContentData&) const = 0;
+
 private:
     virtual PassOwnPtr<ContentData> cloneInternal() const = 0;
 
@@ -71,6 +70,13 @@
     StyleImage* image() { return m_image.get(); }
     void setImage(PassRefPtr<StyleImage> image) { m_image = image; }
 
+    virtual bool equals(const ContentData& data) const OVERRIDE
+    {
+        if (!data.isImage())
+            return false;
+        return *static_cast<const ImageContentData&>(data).image() == *image();
+    }
+
 private:
     ImageContentData(PassRefPtr<StyleImage> image)
         : m_image(image)
@@ -94,6 +100,13 @@
     const String& text() const { return m_text; }
     void setText(const String& text) { m_text = text; }
 
+    virtual bool equals(const ContentData& data) const OVERRIDE
+    {
+        if (!data.isText())
+            return false;
+        return static_cast<const TextContentData&>(data).text() == text();
+    }
+
 private:
     TextContentData(const String& text)
         : m_text(text)
@@ -127,6 +140,13 @@
         return create(counterData.release());
     }
 
+    virtual bool equals(const ContentData& data) const OVERRIDE
+    {
+        if (!data.isCounter())
+            return false;
+        return *static_cast<const CounterContentData&>(data).counter() == *counter();
+    }
+
     OwnPtr<CounterContent> m_counter;
 };
 
@@ -136,6 +156,13 @@
     QuoteType quote() const { return m_quote; }
     void setQuote(QuoteType quote) { m_quote = quote; }
 
+    virtual bool equals(const ContentData& data) const OVERRIDE
+    {
+        if (!data.isQuote())
+            return false;
+        return static_cast<const QuoteContentData&>(data).quote() == quote();
+    }
+
 private:
     QuoteContentData(QuoteType quote)
         : m_quote(quote)
@@ -149,6 +176,16 @@
     QuoteType m_quote;
 };
 
+inline bool operator==(const ContentData& a, const ContentData& b)
+{
+    return a.equals(b);
+}
+
+inline bool operator!=(const ContentData& a, const ContentData& b)
+{
+    return !(a == b);
+}
+
 } // namespace WebCore
 
 #endif // ContentData_h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to