Rolling out r17865 because it caused a performance regression.
[WebKit-https.git] / WebCore / platform / CString.cpp
index 93a3da4dab61792cb306fda862883801b3c3a958..7c33adb816b1321a4787fbaa703d0cc36a4f30ce 100644 (file)
@@ -59,6 +59,14 @@ const char* CString::data() const
 {
     return m_buffer ? m_buffer->data() : 0;
 }
+
+char* CString::mutableData()
+{
+    copyBufferIfNeeded();
+    if (!m_buffer)
+        return 0;
+    return m_buffer->data();
+}
     
 unsigned CString::length() const
 {
@@ -80,4 +88,15 @@ CString CString::newUninitialized(size_t length, char*& characterBuffer)
     return result;
 }
 
+void CString::copyBufferIfNeeded()
+{
+    if (!m_buffer || m_buffer->hasOneRef())
+        return;
+        
+    int len = m_buffer->length();
+    RefPtr<CStringBuffer> m_temp = m_buffer;
+    m_buffer = new CStringBuffer(len);
+    memcpy(m_buffer->data(), m_temp->data(), len);
+}
+
 }