2008-03-25 Brady Eidson <beidson@apple.com>
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Mar 2008 00:29:30 +0000 (00:29 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Mar 2008 00:29:30 +0000 (00:29 +0000)
        Reviewed by Anders

        Add the ability to transform a CString into a SharedBuffer to avoid copying data
        This is valuable to avoid copying a block of data for an upcoming patch

        * platform/SharedBuffer.cpp:
        (WebCore::SharedBuffer::adoptVector):
        * platform/SharedBuffer.h:

        * platform/text/CString.cpp:
        (WebCore::CString::releaseBuffer):
        * platform/text/CString.h:
        (WebCore::CStringBuffer::releaseBuffer):

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

WebCore/ChangeLog
WebCore/platform/SharedBuffer.cpp
WebCore/platform/SharedBuffer.h
WebCore/platform/text/CString.cpp
WebCore/platform/text/CString.h

index d1e1928..ca45fbe 100644 (file)
@@ -1,5 +1,21 @@
 2008-03-25  Brady Eidson  <beidson@apple.com>
 
+        Reviewed by Anders
+
+        Add the ability to transform a CString into a SharedBuffer to avoid copying data
+        This is valuable to avoid copying a block of data for an upcoming patch
+
+        * platform/SharedBuffer.cpp:
+        (WebCore::SharedBuffer::adoptVector):
+        * platform/SharedBuffer.h:
+
+        * platform/text/CString.cpp:
+        (WebCore::CString::releaseBuffer):
+        * platform/text/CString.h:
+        (WebCore::CStringBuffer::releaseBuffer):
+
+2008-03-25  Brady Eidson  <beidson@apple.com>
+
         Attempt to fix .bkl build systems after recent archive additions
 
         * webcore-base.bkl:
index e99d27d..e1e812b 100644 (file)
@@ -42,6 +42,13 @@ SharedBuffer::SharedBuffer(const unsigned char* data, int size)
     m_buffer.append(data, size);
 }
 
+PassRefPtr<SharedBuffer> SharedBuffer::adoptVector(Vector<char>& vector)
+{
+    RefPtr<SharedBuffer> buffer = create();
+    buffer->m_buffer.swap(vector);
+    return buffer.release();
+}
+
 unsigned SharedBuffer::size() const
 {
     if (hasPlatformData())
index 9ce1f12..eb5c167 100644 (file)
@@ -52,6 +52,8 @@ public:
     static PassRefPtr<SharedBuffer> create(const unsigned char* c, int i) { return adoptRef(new SharedBuffer(c, i)); }
 
     static PassRefPtr<SharedBuffer> createWithContentsOfFile(const String& filePath);
+
+    static PassRefPtr<SharedBuffer> adoptVector(Vector<char>& vector);
     
 #if PLATFORM(MAC)
     NSData *createNSData();
index f1434ad..8e68628 100644 (file)
@@ -99,4 +99,17 @@ bool operator==(const CString& a, const CString& b)
     return !strncmp(a.data(), b.data(), min(a.length(), b.length()));
 }
 
+PassRefPtr<SharedBuffer> CString::releaseBuffer()
+{
+    if (!m_buffer)
+        return 0;
+
+    copyBufferIfNeeded();
+        
+    RefPtr<SharedBuffer> result = m_buffer->releaseBuffer();
+    m_buffer = 0;
+    return result.release();
+}
+
+
 }
index fcb4c8c..09f112f 100644 (file)
@@ -26,6 +26,8 @@
 #ifndef CString_h
 #define CString_h
 
+#include "SharedBuffer.h"
+
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
@@ -38,6 +40,8 @@ namespace WebCore {
 
         char* data() { return m_vector.data(); }
         size_t length() const { return m_vector.size(); }
+        
+        PassRefPtr<SharedBuffer> releaseBuffer() { return SharedBuffer::adoptVector(m_vector); }
 
     private:
         CStringBuffer(unsigned length) : m_vector(length) { }
@@ -59,6 +63,8 @@ namespace WebCore {
         unsigned length() const;
 
         bool isNull() const { return !m_buffer; }
+        
+        PassRefPtr<SharedBuffer> releaseBuffer();
 
     private:
         void copyBufferIfNeeded();