WebCore:
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Feb 2008 21:23:08 +0000 (21:23 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Feb 2008 21:23:08 +0000 (21:23 +0000)
        Reviewed by Sam.

        Make more classes start out with a refcount of 1.

        * dom/QualifiedName.cpp:
        (WebCore::QNameComponentsTranslator::translate):
        (WebCore::QualifiedName::QualifiedName):
        * dom/QualifiedName.h:
        (WebCore::QualifiedName::QualifiedNameImpl::create):
        (WebCore::QualifiedName::QualifiedNameImpl::QualifiedNameImpl):
        * history/BackForwardList.cpp:
        (WebCore::BackForwardList::BackForwardList):
        * history/BackForwardList.h:
        (WebCore::BackForwardList::create):
        * page/Page.cpp:
        (WebCore::Page::Page):
        * platform/text/CString.cpp:
        (WebCore::CString::init):
        (WebCore::CString::newUninitialized):
        (WebCore::CString::copyBufferIfNeeded):
        * platform/text/CString.h:
        (WebCore::CStringBuffer::create):
        (WebCore::CStringBuffer::CStringBuffer):

WebKit/mac:

        Reviewed by Sam.

        Use BackForwardList::create instead.

        * History/WebBackForwardList.mm:
        (-[WebBackForwardList init]):

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

WebCore/ChangeLog
WebCore/dom/QualifiedName.cpp
WebCore/dom/QualifiedName.h
WebCore/history/BackForwardList.cpp
WebCore/history/BackForwardList.h
WebCore/page/Page.cpp
WebCore/platform/text/CString.cpp
WebCore/platform/text/CString.h
WebKit/mac/ChangeLog
WebKit/mac/History/WebBackForwardList.mm

index 35e0810..a6f7f16 100644 (file)
@@ -1,3 +1,29 @@
+2008-02-21  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam.
+
+        Make more classes start out with a refcount of 1.
+
+        * dom/QualifiedName.cpp:
+        (WebCore::QNameComponentsTranslator::translate):
+        (WebCore::QualifiedName::QualifiedName):
+        * dom/QualifiedName.h:
+        (WebCore::QualifiedName::QualifiedNameImpl::create):
+        (WebCore::QualifiedName::QualifiedNameImpl::QualifiedNameImpl):
+        * history/BackForwardList.cpp:
+        (WebCore::BackForwardList::BackForwardList):
+        * history/BackForwardList.h:
+        (WebCore::BackForwardList::create):
+        * page/Page.cpp:
+        (WebCore::Page::Page):
+        * platform/text/CString.cpp:
+        (WebCore::CString::init):
+        (WebCore::CString::newUninitialized):
+        (WebCore::CString::copyBufferIfNeeded):
+        * platform/text/CString.h:
+        (WebCore::CStringBuffer::create):
+        (WebCore::CStringBuffer::CStringBuffer):
+
 2008-02-21  Kevin Ollivier  <kevino@theolliviers.com>
 
         wx build fix for the domString() -> string() rename in r30443.
index ebc63a2..c9d7e28 100644 (file)
@@ -97,7 +97,7 @@ struct QNameComponentsTranslator {
         return c.m_prefix == name->m_prefix.impl() && c.m_localName == name->m_localName.impl() && c.m_namespace == name->m_namespace.impl();
     }
     static void translate(QualifiedName::QualifiedNameImpl*& location, const QualifiedNameComponents& components, unsigned hash) {
-        location = new QualifiedName::QualifiedNameImpl(components.m_prefix, components.m_localName, components.m_namespace);
+        location = QualifiedName::QualifiedNameImpl::create(components.m_prefix, components.m_localName, components.m_namespace).releaseRef();
     }
 };
 
@@ -109,8 +109,10 @@ QualifiedName::QualifiedName(const AtomicString& p, const AtomicString& l, const
     if (!gNameCache)
         gNameCache = new QNameSet;
     QualifiedNameComponents components = { p.impl(), l.impl(), n.impl() };
-    m_impl = *gNameCache->add<QualifiedNameComponents, QNameComponentsTranslator>(components).first;    
-    ref();
+    pair<QNameSet::iterator, bool> addResult = gNameCache->add<QualifiedNameComponents, QNameComponentsTranslator>(components);
+    m_impl = *addResult.first;    
+    if (!addResult.second)
+        m_impl->ref();
 }
 
 QualifiedName::~QualifiedName()
index 1078b1a..5aa8abf 100644 (file)
@@ -30,16 +30,22 @@ class QualifiedName {
 public:
     class QualifiedNameImpl : public RefCounted<QualifiedNameImpl> {
     public:
-        QualifiedNameImpl(const AtomicString& p, const AtomicString& l, const AtomicString& n)
-            : RefCounted<QualifiedNameImpl>(0)
-            , m_prefix(p)
-            , m_localName(l)
-            , m_namespace(n)
+        static PassRefPtr<QualifiedNameImpl> create(const AtomicString& p, const AtomicString& l, const AtomicString& n)
         {
+            return adoptRef(new QualifiedNameImpl(p, l, n));
         }
+        
         AtomicString m_prefix;
         AtomicString m_localName;
         AtomicString m_namespace;
+
+    private:
+        QualifiedNameImpl(const AtomicString& p, const AtomicString& l, const AtomicString& n)
+            : m_prefix(p)
+            , m_localName(l)
+            , m_namespace(n)
+        {
+        }        
     };
 
     QualifiedName(const AtomicString& prefix, const AtomicString& localName, const AtomicString& namespaceURI);
index 89ac72e..f912239 100644 (file)
@@ -38,8 +38,7 @@ static const unsigned DefaultCapacity = 100;
 static const unsigned NoCurrentItemIndex = UINT_MAX;
 
 BackForwardList::BackForwardList(Page* page)
-    : RefCounted<BackForwardList>(0)
-    , m_page(page)
+    : m_page(page)
     , m_current(NoCurrentItemIndex)
     , m_capacity(DefaultCapacity)
     , m_closed(true)
index 61a0ada..048778b 100644 (file)
@@ -27,7 +27,7 @@
 #define BackForwardList_h
 
 #include <wtf/RefCounted.h>
-#include <wtf/Forward.h>
+#include <wtf/PassRefPtr.h>
 #include <wtf/HashSet.h>
 #include <wtf/Vector.h>
 
@@ -41,7 +41,7 @@ typedef HashSet<RefPtr<HistoryItem> > HistoryItemHashSet;
 
 class BackForwardList : public RefCounted<BackForwardList> {
 public: 
-    BackForwardList(Page*);
+    static PassRefPtr<BackForwardList> create(Page* page) { return adoptRef(new BackForwardList(page)); }
     ~BackForwardList();
     
     Page* page() { return m_page; }
@@ -74,6 +74,8 @@ public:
     HistoryItemVector& entries();
     
 private:
+    BackForwardList(Page*);
+
     Page* m_page;
     HistoryItemVector m_entries;
     HistoryItemHashSet m_entryHash;
index efae3bf..f60d05c 100644 (file)
@@ -77,7 +77,7 @@ Page::Page(ChromeClient* chromeClient, ContextMenuClient* contextMenuClient, Edi
     , m_inspectorController(new InspectorController(this, inspectorClient))
     , m_settings(new Settings(this))
     , m_progress(new ProgressTracker)
-    , m_backForwardList(new BackForwardList(this))
+    , m_backForwardList(BackForwardList::create(this))
     , m_editorClient(editorClient)
     , m_frameCount(0)
     , m_tabKeyCyclesThroughElements(true)
index 4300b29..08f8fc0 100644 (file)
@@ -50,7 +50,7 @@ void CString::init(const char* str, unsigned length)
     if (!str)
         return;
     
-    m_buffer = new CStringBuffer(length + 1);
+    m_buffer = CStringBuffer::create(length + 1);
     memcpy(m_buffer->data(), str, length); 
     m_buffer->data()[length] = '\0';
 }
@@ -81,7 +81,7 @@ DeprecatedCString CString::deprecatedCString() const
 CString CString::newUninitialized(size_t length, char*& characterBuffer)
 {
     CString result;
-    result.m_buffer = new CStringBuffer(length + 1);
+    result.m_buffer = CStringBuffer::create(length + 1);
     char* bytes = result.m_buffer->data();
     bytes[length] = '\0';
     characterBuffer = bytes;
@@ -95,7 +95,7 @@ void CString::copyBufferIfNeeded()
         
     int len = m_buffer->length();
     RefPtr<CStringBuffer> m_temp = m_buffer;
-    m_buffer = new CStringBuffer(len);
+    m_buffer = CStringBuffer::create(len);
     memcpy(m_buffer->data(), m_temp->data(), len);
 }
 
index 376db44..5acbe58 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef CString_h
 #define CString_h
 
+#include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
 
@@ -37,12 +38,14 @@ namespace WebCore {
     
     class CStringBuffer : public RefCounted<CStringBuffer> {
     public:
-        CStringBuffer(unsigned length) : RefCounted<CStringBuffer>(0), m_vector(length) { }
+        static PassRefPtr<CStringBuffer> create(unsigned length) { return adoptRef(new CStringBuffer(length)); }
 
         char* data() { return m_vector.data(); }
         size_t length() const { return m_vector.size(); }
 
     private:
+        CStringBuffer(unsigned length) : m_vector(length) { }
+
         Vector<char> m_vector;
     };
 
index 66f8fab..6246524 100644 (file)
@@ -1,3 +1,12 @@
+2008-02-21  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam.
+
+        Use BackForwardList::create instead.
+        
+        * History/WebBackForwardList.mm:
+        (-[WebBackForwardList init]):
+
 2008-02-21  John Sullivan  <sullivan@apple.com>
 
         Reviewed by Jessica Kahn
index f38d828..6423830 100644 (file)
@@ -101,8 +101,7 @@ WebBackForwardList *kit(BackForwardList* backForwardList)
 
 - (id)init
 {
-    RefPtr<BackForwardList> coreList(new BackForwardList(0));
-    return [self initWithBackForwardList:coreList.release()];
+    return [self initWithBackForwardList:BackForwardList::create(0)];
 }
 
 - (void)dealloc