Allow constructing a PassRef from a Ref
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Nov 2014 00:16:27 +0000 (00:16 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Nov 2014 00:16:27 +0000 (00:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138389

Reviewed by Andreas Kling.

Source/WebCore:

Remove calls to Ref::get() now that a PassRef can be directly
constructed from a Ref.

No new tests, no behavior change.

* css/CSSValuePool.cpp:
(WebCore::CSSValuePool::createColorValue):
* css/CSSValuePool.h:
(WebCore::CSSValuePool::createInheritedValue):
(WebCore::CSSValuePool::createImplicitInitialValue):
(WebCore::CSSValuePool::createExplicitInitialValue):
* html/HTMLLinkElement.cpp:
(WebCore::HTMLLinkElement::setCSSStyleSheet):

Source/WTF:

Allow constructing a PassRef from a Ref, similarly to PassRefPtr that
can be constructed from a RefPtr already. This avoids having to call
Ref::get() and simplifies the code a bit.

* wtf/PassRef.h:
(WTF::PassRef<T>::PassRef):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175648 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/PassRef.h
Source/WebCore/ChangeLog
Source/WebCore/css/CSSValuePool.cpp
Source/WebCore/css/CSSValuePool.h
Source/WebCore/html/HTMLLinkElement.cpp

index 0bedf62..061f28f 100644 (file)
@@ -1,3 +1,17 @@
+2014-11-05  Chris Dumez  <cdumez@apple.com>
+
+        Allow constructing a PassRef from a Ref
+        https://bugs.webkit.org/show_bug.cgi?id=138389
+
+        Reviewed by Andreas Kling.
+
+        Allow constructing a PassRef from a Ref, similarly to PassRefPtr that
+        can be constructed from a RefPtr already. This avoids having to call
+        Ref::get() and simplifies the code a bit.
+
+        * wtf/PassRef.h:
+        (WTF::PassRef<T>::PassRef):
+
 2014-11-05  Dan Bernstein  <mitz@apple.com>
 
         Remove the unused deletion UI feature
index d374ae5..883651e 100644 (file)
@@ -40,6 +40,7 @@ template<typename T> class PassRef {
 public:
     PassRef(T&);
     PassRef(PassRef&&);
+    template<typename U> PassRef(const Ref<U>&);
     template<typename U> PassRef(PassRef<U>);
 
     const T& get() const;
@@ -98,6 +99,15 @@ template<typename T> template<typename U> inline PassRef<T>::PassRef(PassRef<U>
 {
 }
 
+template<typename T> template<typename U> inline PassRef<T>::PassRef(const Ref<U>& other)
+    : m_reference(const_cast<T&>(other.get()))
+#ifndef NDEBUG
+    , m_gaveUpReference(false)
+#endif
+{
+    m_reference.ref();
+}
+
 #ifndef NDEBUG
 
 template<typename T> PassRef<T>::~PassRef()
index 86036c4..067be78 100644 (file)
@@ -1,3 +1,24 @@
+2014-11-05  Chris Dumez  <cdumez@apple.com>
+
+        Allow constructing a PassRef from a Ref
+        https://bugs.webkit.org/show_bug.cgi?id=138389
+
+        Reviewed by Andreas Kling.
+
+        Remove calls to Ref::get() now that a PassRef can be directly
+        constructed from a Ref.
+
+        No new tests, no behavior change.
+
+        * css/CSSValuePool.cpp:
+        (WebCore::CSSValuePool::createColorValue):
+        * css/CSSValuePool.h:
+        (WebCore::CSSValuePool::createInheritedValue):
+        (WebCore::CSSValuePool::createImplicitInitialValue):
+        (WebCore::CSSValuePool::createExplicitInitialValue):
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::setCSSStyleSheet):
+
 2014-11-05  Dan Bernstein  <mitz@apple.com>
 
         Remove the unused deletion UI feature
index dda8f2a..be99434 100644 (file)
@@ -69,12 +69,12 @@ PassRef<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue)
 {
     // These are the empty and deleted values of the hash table.
     if (rgbValue == Color::transparent)
-        return m_colorTransparent.get();
+        return m_colorTransparent;
     if (rgbValue == Color::white)
-        return m_colorWhite.get();
+        return m_colorWhite;
     // Just because it is common.
     if (rgbValue == Color::black)
-        return m_colorBlack.get();
+        return m_colorBlack;
 
     // Remove one entry at random if the cache grows too large.
     const int maximumColorCacheSize = 512;
index 7750fdc..3396453 100644 (file)
@@ -45,9 +45,9 @@ class CSSValuePool {
 public:
     PassRefPtr<CSSValueList> createFontFaceValue(const AtomicString&);
     PassRef<CSSPrimitiveValue> createFontFamilyValue(const String&);
-    PassRef<CSSInheritedValue> createInheritedValue() { return m_inheritedValue.get(); }
-    PassRef<CSSInitialValue> createImplicitInitialValue() { return m_implicitInitialValue.get(); }
-    PassRef<CSSInitialValue> createExplicitInitialValue() { return m_explicitInitialValue.get(); }
+    PassRef<CSSInheritedValue> createInheritedValue() { return m_inheritedValue; }
+    PassRef<CSSInitialValue> createImplicitInitialValue() { return m_implicitInitialValue; }
+    PassRef<CSSInitialValue> createExplicitInitialValue() { return m_explicitInitialValue; }
     PassRef<CSSPrimitiveValue> createIdentifierValue(CSSValueID identifier);
     PassRef<CSSPrimitiveValue> createIdentifierValue(CSSPropertyID identifier);
     PassRef<CSSPrimitiveValue> createColorValue(unsigned rgbValue);
index 2b45eee..69641f1 100644 (file)
@@ -328,7 +328,7 @@ void HTMLLinkElement::setCSSStyleSheet(const String& href, const URL& baseURL, c
     }
 
     Ref<StyleSheetContents> styleSheet(StyleSheetContents::create(href, parserContext));
-    m_sheet = CSSStyleSheet::create(styleSheet.get(), this);
+    m_sheet = CSSStyleSheet::create(styleSheet, this);
     m_sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(m_media));
     m_sheet->setTitle(title());
 
@@ -339,7 +339,7 @@ void HTMLLinkElement::setCSSStyleSheet(const String& href, const URL& baseURL, c
     styleSheet.get().checkLoaded();
 
     if (styleSheet.get().isCacheable())
-        const_cast<CachedCSSStyleSheet*>(cachedStyleSheet)->saveParsedStyleSheet(styleSheet.get());
+        const_cast<CachedCSSStyleSheet*>(cachedStyleSheet)->saveParsedStyleSheet(styleSheet);
 }
 
 bool HTMLLinkElement::styleSheetIsLoading() const