Title: [176933] trunk/Source
Revision
176933
Author
[email protected]
Date
2014-12-07 15:25:59 -0800 (Sun, 07 Dec 2014)

Log Message

Use more PassRef in AtomicString.
<https://webkit.org/b/139319>

Reviewed by Antti Koivisto.

Make a pass over AtomicString and convert functions that return PassRefPtr
into returning RefPtr (where it may be null) and PassRef otherwise.
This allows the compiler to skip null checks in many places.

* wtf/text/AtomicString.cpp:
(WTF::addToStringTable):
(WTF::AtomicString::add):
(WTF::AtomicString::addFromLiteralData):
(WTF::AtomicString::addSlowCase):
* wtf/text/AtomicString.h:
(WTF::AtomicString::add):
(WTF::AtomicString::addWithStringTableProvider):
* wtf/text/cf/AtomicStringCF.cpp:
(WTF::AtomicString::add):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (176932 => 176933)


--- trunk/Source/WTF/ChangeLog	2014-12-07 22:25:01 UTC (rev 176932)
+++ trunk/Source/WTF/ChangeLog	2014-12-07 23:25:59 UTC (rev 176933)
@@ -1,3 +1,25 @@
+2014-12-07  Andreas Kling  <[email protected]>
+
+        Use more PassRef in AtomicString.
+        <https://webkit.org/b/139319>
+
+        Reviewed by Antti Koivisto.
+
+        Make a pass over AtomicString and convert functions that return PassRefPtr
+        into returning RefPtr (where it may be null) and PassRef otherwise.
+        This allows the compiler to skip null checks in many places.
+
+        * wtf/text/AtomicString.cpp:
+        (WTF::addToStringTable):
+        (WTF::AtomicString::add):
+        (WTF::AtomicString::addFromLiteralData):
+        (WTF::AtomicString::addSlowCase):
+        * wtf/text/AtomicString.h:
+        (WTF::AtomicString::add):
+        (WTF::AtomicString::addWithStringTableProvider):
+        * wtf/text/cf/AtomicStringCF.cpp:
+        (WTF::AtomicString::add):
+
 2014-12-05  Roger Fong  <[email protected]>
 
         [Win] proj files copying over too many resources..

Modified: trunk/Source/WTF/wtf/text/AtomicString.cpp (176932 => 176933)


--- trunk/Source/WTF/wtf/text/AtomicString.cpp	2014-12-07 22:25:01 UTC (rev 176932)
+++ trunk/Source/WTF/wtf/text/AtomicString.cpp	2014-12-07 23:25:59 UTC (rev 176933)
@@ -73,7 +73,7 @@
 }
 
 template<typename T, typename HashTranslator>
-static inline PassRefPtr<StringImpl> addToStringTable(const T& value)
+static inline PassRef<StringImpl> addToStringTable(const T& value)
 {
     AtomicStringTableLocker locker;
 
@@ -81,7 +81,7 @@
 
     // If the string is newly-translated, then we need to adopt it.
     // The boolean in the pair tells us if that is so.
-    return addResult.isNewEntry ? adoptRef(*addResult.iterator) : *addResult.iterator;
+    return addResult.isNewEntry ? adoptRef(**addResult.iterator) : **addResult.iterator;
 }
 
 struct CStringTranslator {
@@ -103,10 +103,10 @@
     }
 };
 
-PassRefPtr<StringImpl> AtomicString::add(const LChar* c)
+RefPtr<StringImpl> AtomicString::add(const LChar* c)
 {
     if (!c)
-        return 0;
+        return nullptr;
     if (!*c)
         return StringImpl::empty();
 
@@ -235,10 +235,10 @@
     }
 };
 
-PassRefPtr<StringImpl> AtomicString::add(const UChar* s, unsigned length)
+RefPtr<StringImpl> AtomicString::add(const UChar* s, unsigned length)
 {
     if (!s)
-        return 0;
+        return nullptr;
 
     if (!length)
         return StringImpl::empty();
@@ -247,22 +247,22 @@
     return addToStringTable<UCharBuffer, UCharBufferTranslator>(buffer);
 }
 
-PassRefPtr<StringImpl> AtomicString::add(const UChar* s, unsigned length, unsigned existingHash)
+PassRef<StringImpl> AtomicString::add(const UChar* s, unsigned length, unsigned existingHash)
 {
     ASSERT(s);
     ASSERT(existingHash);
 
     if (!length)
-        return StringImpl::empty();
+        return *StringImpl::empty();
 
     HashAndCharacters<UChar> buffer = { existingHash, s, length };
     return addToStringTable<HashAndCharacters<UChar>, HashAndCharactersTranslator<UChar>>(buffer);
 }
 
-PassRefPtr<StringImpl> AtomicString::add(const UChar* s)
+RefPtr<StringImpl> AtomicString::add(const UChar* s)
 {
     if (!s)
-        return 0;
+        return nullptr;
 
     unsigned length = 0;
     while (s[length] != UChar(0))
@@ -314,7 +314,7 @@
     }
 };
 
-PassRefPtr<StringImpl> AtomicString::add(StringImpl* baseString, unsigned start, unsigned length)
+RefPtr<StringImpl> AtomicString::add(StringImpl* baseString, unsigned start, unsigned length)
 {
     if (!baseString)
         return nullptr;
@@ -375,10 +375,10 @@
     }
 };
 
-PassRefPtr<StringImpl> AtomicString::add(const LChar* s, unsigned length)
+RefPtr<StringImpl> AtomicString::add(const LChar* s, unsigned length)
 {
     if (!s)
-        return 0;
+        return nullptr;
 
     if (!length)
         return StringImpl::empty();
@@ -387,7 +387,7 @@
     return addToStringTable<LCharBuffer, LCharBufferTranslator>(buffer);
 }
 
-PassRefPtr<StringImpl> AtomicString::addFromLiteralData(const char* characters, unsigned length)
+PassRef<StringImpl> AtomicString::addFromLiteralData(const char* characters, unsigned length)
 {
     ASSERT(characters);
     ASSERT(length);
@@ -396,10 +396,10 @@
     return addToStringTable<CharBuffer, CharBufferFromLiteralDataTranslator>(buffer);
 }
 
-PassRefPtr<StringImpl> AtomicString::addSlowCase(StringImpl& string)
+PassRef<StringImpl> AtomicString::addSlowCase(StringImpl& string)
 {
     if (!string.length())
-        return StringImpl::empty();
+        return *StringImpl::empty();
 
     ASSERT_WITH_MESSAGE(!string.isAtomic(), "AtomicString should not hit the slow case if the string is already atomic.");
 
@@ -411,13 +411,13 @@
         string.setIsAtomic(true);
     }
 
-    return *addResult.iterator;
+    return **addResult.iterator;
 }
 
-PassRefPtr<StringImpl> AtomicString::addSlowCase(AtomicStringTable& stringTable, StringImpl& string)
+PassRef<StringImpl> AtomicString::addSlowCase(AtomicStringTable& stringTable, StringImpl& string)
 {
     if (!string.length())
-        return StringImpl::empty();
+        return *StringImpl::empty();
 
     ASSERT_WITH_MESSAGE(!string.isAtomic(), "AtomicString should not hit the slow case if the string is already atomic.");
 
@@ -429,7 +429,7 @@
         string.setIsAtomic(true);
     }
 
-    return *addResult.iterator;
+    return **addResult.iterator;
 }
 
 void AtomicString::remove(StringImpl* string)

Modified: trunk/Source/WTF/wtf/text/AtomicString.h (176932 => 176933)


--- trunk/Source/WTF/wtf/text/AtomicString.h	2014-12-07 22:25:01 UTC (rev 176932)
+++ trunk/Source/WTF/wtf/text/AtomicString.h	2014-12-07 23:25:59 UTC (rev 176933)
@@ -173,15 +173,15 @@
     void show() const;
 #endif
 
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const LChar*);
-    ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s) { return add(reinterpret_cast<const LChar*>(s)); };
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const LChar*, unsigned length);
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const UChar*, unsigned length);
-    ALWAYS_INLINE static PassRefPtr<StringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const LChar*>(s), length); };
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const UChar*, unsigned length, unsigned existingHash);
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(const UChar*);
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(StringImpl*, unsigned offset, unsigned length);
-    ALWAYS_INLINE static PassRefPtr<StringImpl> add(StringImpl* string)
+    WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(const LChar*);
+    ALWAYS_INLINE static RefPtr<StringImpl> add(const char* s) { return add(reinterpret_cast<const LChar*>(s)); };
+    WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(const LChar*, unsigned length);
+    WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(const UChar*, unsigned length);
+    ALWAYS_INLINE static RefPtr<StringImpl> add(const char* s, unsigned length) { return add(reinterpret_cast<const LChar*>(s), length); };
+    WTF_EXPORT_STRING_API static PassRef<StringImpl> add(const UChar*, unsigned length, unsigned existingHash);
+    WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(const UChar*);
+    WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(StringImpl*, unsigned offset, unsigned length);
+    ALWAYS_INLINE static RefPtr<StringImpl> add(StringImpl* string)
     {
         if (!string || string->isAtomic()) {
             ASSERT_WITH_MESSAGE(!string || !string->length() || isInAtomicStringTable(string), "The atomic string comes from an other thread!");
@@ -189,13 +189,13 @@
         }
         return addSlowCase(*string);
     }
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> addFromLiteralData(const char* characters, unsigned length);
+    WTF_EXPORT_STRING_API static PassRef<StringImpl> addFromLiteralData(const char* characters, unsigned length);
 #if USE(CF)
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> add(CFStringRef);
+    WTF_EXPORT_STRING_API static RefPtr<StringImpl> add(CFStringRef);
 #endif
 
     template<typename StringTableProvider>
-    ALWAYS_INLINE static PassRefPtr<StringImpl> addWithStringTableProvider(StringTableProvider& stringTableProvider, StringImpl* string)
+    ALWAYS_INLINE static RefPtr<StringImpl> addWithStringTableProvider(StringTableProvider& stringTableProvider, StringImpl* string)
     {
         if (!string || string->isAtomic()) {
             ASSERT_WITH_MESSAGE(!string || !string->length() || isInAtomicStringTable(string), "The atomic string comes from an other thread!");
@@ -214,8 +214,8 @@
 
     String m_string;
     
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> addSlowCase(StringImpl&);
-    WTF_EXPORT_STRING_API static PassRefPtr<StringImpl> addSlowCase(AtomicStringTable&, StringImpl&);
+    WTF_EXPORT_STRING_API static PassRef<StringImpl> addSlowCase(StringImpl&);
+    WTF_EXPORT_STRING_API static PassRef<StringImpl> addSlowCase(AtomicStringTable&, StringImpl&);
 
     WTF_EXPORT_STRING_API static AtomicStringImpl* findSlowCase(StringImpl&);
     WTF_EXPORT_STRING_API static AtomicString fromUTF8Internal(const char*, const char*);

Modified: trunk/Source/WTF/wtf/text/cf/AtomicStringCF.cpp (176932 => 176933)


--- trunk/Source/WTF/wtf/text/cf/AtomicStringCF.cpp	2014-12-07 22:25:01 UTC (rev 176932)
+++ trunk/Source/WTF/wtf/text/cf/AtomicStringCF.cpp	2014-12-07 23:25:59 UTC (rev 176933)
@@ -33,10 +33,10 @@
 
 namespace WTF {
 
-PassRefPtr<StringImpl> AtomicString::add(CFStringRef string)
+RefPtr<StringImpl> AtomicString::add(CFStringRef string)
 {
     if (!string)
-        return 0;
+        return nullptr;
 
     CFIndex length = CFStringGetLength(string);
 

Modified: trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in (176932 => 176933)


--- trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in	2014-12-07 22:25:01 UTC (rev 176932)
+++ trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in	2014-12-07 23:25:59 UTC (rev 176933)
@@ -166,7 +166,7 @@
         symbolWithPointer(?absoluteBoundingBoxRect@RenderObject@WebCore@@QBE?AVIntRect@2@_N@Z, ?absoluteBoundingBoxRect@RenderObject@WebCore@@QEBA?AVIntRect@2@_N@Z)
         symbolWithPointer(?absoluteBoundingBoxRectIgnoringTransforms@RenderObject@WebCore@@QBE?AVIntRect@2@XZ, ?absoluteBoundingBoxRectIgnoringTransforms@RenderObject@WebCore@@QEBA?AVIntRect@2@XZ)
         symbolWithPointer(?description@DocumentMarker@WebCore@@QBEABVString@WTF@@XZ, ?description@DocumentMarker@WebCore@@QEBAAEBVString@WTF@@XZ)
-        symbolWithPointer(?addSlowCase@AtomicString@WTF@@CA?AV?$PassRefPtr@VStringImpl@WTF@@@2@AAVStringImpl@2@@Z, ?addSlowCase@AtomicString@WTF@@CA?AV?$PassRefPtr@VStringImpl@WTF@@@2@AEAVStringImpl@2@@Z)
+        symbolWithPointer(?addSlowCase@AtomicString@WTF@@CA?AV?$PassRef@VStringImpl@WTF@@@2@AAVStringImpl@2@@Z, ?addSlowCase@AtomicString@WTF@@CA?AV?$PassRef@VStringImpl@WTF@@@2@AEAVStringImpl@2@@Z)
         symbolWithPointer(?cacheDOMStructure@WebCore@@YAPAVStructure@JSC@@PAVJSDOMGlobalObject@1@PAV23@PBUClassInfo@3@@Z, ?cacheDOMStructure@WebCore@@YAPEAVStructure@JSC@@PEAVJSDOMGlobalObject@1@PEAV23@PEBUClassInfo@3@@Z)
         symbolWithPointer(?childItemWithTarget@HistoryItem@WebCore@@QBEPAV12@ABVString@WTF@@@Z, ?childItemWithTarget@HistoryItem@WebCore@@QEBAPEAV12@AEBVString@WTF@@@Z)
         symbolWithPointer(?create@Range@WebCore@@SA?AV?$PassRefPtr@VRange@WebCore@@@WTF@@AAVDocument@2@V?$PassRefPtr@VNode@WebCore@@@4@H1H@Z, ?create@Range@WebCore@@SA?AV?$PassRefPtr@VRange@WebCore@@@WTF@@AEAVDocument@2@V?$PassRefPtr@VNode@WebCore@@@4@H1H@Z)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to