Title: [138666] trunk/Source
Revision
138666
Author
alecfl...@chromium.org
Date
2013-01-02 15:48:58 -0800 (Wed, 02 Jan 2013)

Log Message

IndexedDB: Use non-const buffers in put() to avoid copies
https://bugs.webkit.org/show_bug.cgi?id=105572

Reviewed by Adam Barth.

Source/WebCore:

Change the new put() method to allow the implementation to consume
or adopt the vector, to avoid copying.

No new tests as this is an interface change that will be implemented later.

* Modules/indexeddb/IDBDatabaseBackendImpl.cpp:
(WebCore::IDBDatabaseBackendImpl::put):
* Modules/indexeddb/IDBDatabaseBackendImpl.h:
(IDBDatabaseBackendImpl):
* Modules/indexeddb/IDBDatabaseBackendInterface.h:

Source/WebKit/chromium:

Pass on non-const Vectors to allow buffer adoption rather than copies.

* public/WebIDBDatabase.h:
(WebIDBDatabase):
(WebKit::WebIDBDatabase::put):
* src/IDBDatabaseBackendProxy.cpp:
(WebKit::IDBDatabaseBackendProxy::put):
* src/IDBDatabaseBackendProxy.h:
(IDBDatabaseBackendProxy):
* src/WebIDBDatabaseImpl.cpp:
(WebKit::WebIDBDatabaseImpl::put):
* src/WebIDBDatabaseImpl.h:
(WebIDBDatabaseImpl):
* tests/IDBDatabaseBackendTest.cpp:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (138665 => 138666)


--- trunk/Source/WebCore/ChangeLog	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebCore/ChangeLog	2013-01-02 23:48:58 UTC (rev 138666)
@@ -1,3 +1,21 @@
+2013-01-02  Alec Flett  <alecfl...@chromium.org>
+
+        IndexedDB: Use non-const buffers in put() to avoid copies
+        https://bugs.webkit.org/show_bug.cgi?id=105572
+
+        Reviewed by Adam Barth.
+
+        Change the new put() method to allow the implementation to consume
+        or adopt the vector, to avoid copying.
+
+        No new tests as this is an interface change that will be implemented later.
+
+        * Modules/indexeddb/IDBDatabaseBackendImpl.cpp:
+        (WebCore::IDBDatabaseBackendImpl::put):
+        * Modules/indexeddb/IDBDatabaseBackendImpl.h:
+        (IDBDatabaseBackendImpl):
+        * Modules/indexeddb/IDBDatabaseBackendInterface.h:
+
 2013-01-02  Adam Barth  <aba...@webkit.org>
 
         [V8] Remove INC_STATS because it is unused

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp (138665 => 138666)


--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.cpp	2013-01-02 23:48:58 UTC (rev 138666)
@@ -321,7 +321,7 @@
     ASSERT_NOT_REACHED();
 }
 
-void IDBDatabaseBackendImpl::put(int64_t transactionId, int64_t objectStoreId, const Vector<uint8_t>&, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&)
+void IDBDatabaseBackendImpl::put(int64_t transactionId, int64_t objectStoreId, Vector<uint8_t>* value, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&)
 {
     ASSERT_NOT_REACHED();
 }

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.h (138665 => 138666)


--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.h	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendImpl.h	2013-01-02 23:48:58 UTC (rev 138666)
@@ -78,7 +78,7 @@
     void transactionFinishedAndAbortFired(PassRefPtr<IDBTransactionBackendImpl>);
 
     virtual void get(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, bool keyOnly, PassRefPtr<IDBCallbacks>) OVERRIDE;
-    virtual void put(int64_t transactionId, int64_t objectStoreId, const Vector<uint8_t>&, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE;
+    virtual void put(int64_t transactionId, int64_t objectStoreId, Vector<uint8_t>* value, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE;
     virtual void setIndexKeys(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKey> prpPrimaryKey, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE;
     virtual void setIndexesReady(int64_t transactionId, int64_t objectStoreId, const Vector<int64_t>& indexIds) OVERRIDE;
     virtual void openCursor(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, unsigned short direction, bool keyOnly, TaskType, PassRefPtr<IDBCallbacks>) OVERRIDE;

Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendInterface.h (138665 => 138666)


--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendInterface.h	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseBackendInterface.h	2013-01-02 23:48:58 UTC (rev 138666)
@@ -80,7 +80,8 @@
     typedef Vector<RefPtr<IDBKey> > IndexKeys;
 
     virtual void get(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, bool keyOnly, PassRefPtr<IDBCallbacks>) = 0;
-    virtual void put(int64_t transactionId, int64_t objectStoreId, const Vector<uint8_t>&, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) = 0;
+    // Note that 'value' may be consumed/adopted by this call.
+    virtual void put(int64_t transactionId, int64_t objectStoreId, Vector<uint8_t>* value, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) = 0;
     virtual void setIndexKeys(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKey> prpPrimaryKey, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) = 0;
     virtual void setIndexesReady(int64_t transactionId, int64_t objectStoreId, const Vector<int64_t>& indexIds) = 0;
     virtual void openCursor(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, unsigned short direction, bool keyOnly, TaskType, PassRefPtr<IDBCallbacks>) = 0;

Modified: trunk/Source/WebKit/chromium/ChangeLog (138665 => 138666)


--- trunk/Source/WebKit/chromium/ChangeLog	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebKit/chromium/ChangeLog	2013-01-02 23:48:58 UTC (rev 138666)
@@ -1,3 +1,25 @@
+2013-01-02  Alec Flett  <alecfl...@chromium.org>
+
+        IndexedDB: Use non-const buffers in put() to avoid copies
+        https://bugs.webkit.org/show_bug.cgi?id=105572
+
+        Reviewed by Adam Barth.
+
+        Pass on non-const Vectors to allow buffer adoption rather than copies.
+
+        * public/WebIDBDatabase.h:
+        (WebIDBDatabase):
+        (WebKit::WebIDBDatabase::put):
+        * src/IDBDatabaseBackendProxy.cpp:
+        (WebKit::IDBDatabaseBackendProxy::put):
+        * src/IDBDatabaseBackendProxy.h:
+        (IDBDatabaseBackendProxy):
+        * src/WebIDBDatabaseImpl.cpp:
+        (WebKit::WebIDBDatabaseImpl::put):
+        * src/WebIDBDatabaseImpl.h:
+        (WebIDBDatabaseImpl):
+        * tests/IDBDatabaseBackendTest.cpp:
+
 2013-01-02  Robert Kroeger  <rjkro...@chromium.org>
 
         [chromium] Use top level field for gesture event source

Modified: trunk/Source/WebKit/chromium/public/WebIDBDatabase.h (138665 => 138666)


--- trunk/Source/WebKit/chromium/public/WebIDBDatabase.h	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebKit/chromium/public/WebIDBDatabase.h	2013-01-02 23:48:58 UTC (rev 138666)
@@ -82,7 +82,8 @@
     typedef WebVector<WebIDBKey> WebIndexKeys;
 
     virtual void get(long long transactionId, long long objectStoreId, long long indexId, const WebIDBKeyRange&, bool keyOnly, WebIDBCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
-    virtual void put(long long transactionId, long long objectStoreId, const WebVector<unsigned char>& value, const WebIDBKey&, PutMode, WebIDBCallbacks*, const WebVector<long long>& indexIds, const WebVector<WebIndexKeys>&) { WEBKIT_ASSERT_NOT_REACHED(); }
+    // Note that 'value' may be consumed/adopted by this call.
+    virtual void put(long long transactionId, long long objectStoreId, WebVector<unsigned char>* value, const WebIDBKey&, PutMode, WebIDBCallbacks*, const WebVector<long long>& indexIds, const WebVector<WebIndexKeys>&) { WEBKIT_ASSERT_NOT_REACHED(); }
     virtual void setIndexKeys(long long transactionId, long long objectStoreId, const WebIDBKey&, const WebVector<long long>& indexIds, const WebVector<WebIndexKeys>&) { WEBKIT_ASSERT_NOT_REACHED(); }
     virtual void setIndexesReady(long long transactionId, long long objectStoreId, const WebVector<long long>& indexIds) { WEBKIT_ASSERT_NOT_REACHED(); }
     virtual void openCursor(long long transactionId, long long objectStoreId, long long indexId, const WebIDBKeyRange&, unsigned short direction, bool keyOnly, TaskType, WebIDBCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }

Modified: trunk/Source/WebKit/chromium/src/IDBDatabaseBackendProxy.cpp (138665 => 138666)


--- trunk/Source/WebKit/chromium/src/IDBDatabaseBackendProxy.cpp	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebKit/chromium/src/IDBDatabaseBackendProxy.cpp	2013-01-02 23:48:58 UTC (rev 138666)
@@ -128,10 +128,13 @@
         m_webIDBDatabase->get(transactionId, objectStoreId, indexId, keyRange, keyOnly, new WebIDBCallbacksImpl(callbacks));
 }
 
-void IDBDatabaseBackendProxy::put(int64_t transactionId, int64_t objectStoreId, const Vector<uint8_t>& buffer, PassRefPtr<IDBKey> key, PutMode putMode, PassRefPtr<IDBCallbacks> callbacks, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys)
+void IDBDatabaseBackendProxy::put(int64_t transactionId, int64_t objectStoreId, Vector<uint8_t>* buffer, PassRefPtr<IDBKey> key, PutMode putMode, PassRefPtr<IDBCallbacks> callbacks, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys)
 {
-    if (m_webIDBDatabase)
-        m_webIDBDatabase->put(transactionId, objectStoreId, buffer, key, static_cast<WebIDBDatabase::PutMode>(putMode), new WebIDBCallbacksImpl(callbacks), indexIds, indexKeys);
+    if (m_webIDBDatabase) {
+        WebVector<unsigned char> webBuffer(buffer->size());
+        webBuffer.assign(buffer->data(), buffer->size());
+        m_webIDBDatabase->put(transactionId, objectStoreId, &webBuffer, key, static_cast<WebIDBDatabase::PutMode>(putMode), new WebIDBCallbacksImpl(callbacks), indexIds, indexKeys);
+    }
 }
 
 void IDBDatabaseBackendProxy::setIndexKeys(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKey> primaryKey, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys)

Modified: trunk/Source/WebKit/chromium/src/IDBDatabaseBackendProxy.h (138665 => 138666)


--- trunk/Source/WebKit/chromium/src/IDBDatabaseBackendProxy.h	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebKit/chromium/src/IDBDatabaseBackendProxy.h	2013-01-02 23:48:58 UTC (rev 138666)
@@ -55,7 +55,7 @@
     virtual void abort(int64_t);
 
     virtual void get(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<WebCore::IDBKeyRange>, bool keyOnly, PassRefPtr<WebCore::IDBCallbacks>) OVERRIDE;
-    virtual void put(int64_t transactionId, int64_t objectStoreId, const Vector<uint8_t>& value, PassRefPtr<WebCore::IDBKey>, PutMode, PassRefPtr<WebCore::IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE;
+    virtual void put(int64_t transactionId, int64_t objectStoreId, Vector<uint8_t>* value, PassRefPtr<WebCore::IDBKey>, PutMode, PassRefPtr<WebCore::IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE;
     virtual void setIndexKeys(int64_t transactionId, int64_t objectStoreId, PassRefPtr<WebCore::IDBKey> prpPrimaryKey, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE;
     virtual void setIndexesReady(int64_t transactionId, int64_t objectStoreId, const Vector<int64_t>& indexIds) OVERRIDE;
     virtual void openCursor(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<WebCore::IDBKeyRange>, unsigned short direction, bool keyOnly, TaskType, PassRefPtr<WebCore::IDBCallbacks>) OVERRIDE;

Modified: trunk/Source/WebKit/chromium/src/WebIDBDatabaseImpl.cpp (138665 => 138666)


--- trunk/Source/WebKit/chromium/src/WebIDBDatabaseImpl.cpp	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebKit/chromium/src/WebIDBDatabaseImpl.cpp	2013-01-02 23:48:58 UTC (rev 138666)
@@ -147,7 +147,7 @@
         m_databaseBackend->get(transactionId, objectStoreId, indexId, keyRange, keyOnly, IDBCallbacksProxy::create(adoptPtr(callbacks)));
 }
 
-void WebIDBDatabaseImpl::put(long long transactionId, long long objectStoreId, const WebVector<unsigned char>& value, const WebIDBKey& key, PutMode putMode, WebIDBCallbacks* callbacks, const WebVector<long long>& webIndexIds, const WebVector<WebIndexKeys>& webIndexKeys)
+void WebIDBDatabaseImpl::put(long long transactionId, long long objectStoreId, WebVector<unsigned char>* value, const WebIDBKey& key, PutMode putMode, WebIDBCallbacks* callbacks, const WebVector<long long>& webIndexIds, const WebVector<WebIndexKeys>& webIndexKeys)
 {
     if (!m_databaseBackend)
         return;
@@ -164,9 +164,9 @@
         indexKeys[i] = indexKeyList;
     }
 
-    Vector<uint8_t> valueBuffer;
-    valueBuffer.append(value.data(), value.size());
-    m_databaseBackend->put(transactionId, objectStoreId, valueBuffer, key, static_cast<IDBDatabaseBackendInterface::PutMode>(putMode), IDBCallbacksProxy::create(adoptPtr(callbacks)), indexIds, indexKeys);
+    Vector<uint8_t> valueBuffer(value->size());
+    valueBuffer.append(value->data(), value->size());
+    m_databaseBackend->put(transactionId, objectStoreId, &valueBuffer, key, static_cast<IDBDatabaseBackendInterface::PutMode>(putMode), IDBCallbacksProxy::create(adoptPtr(callbacks)), indexIds, indexKeys);
 }
 
 void WebIDBDatabaseImpl::setIndexKeys(long long transactionId, long long objectStoreId, const WebIDBKey& primaryKey, const WebVector<long long>& webIndexIds, const WebVector<WebIndexKeys>& webIndexKeys)

Modified: trunk/Source/WebKit/chromium/src/WebIDBDatabaseImpl.h (138665 => 138666)


--- trunk/Source/WebKit/chromium/src/WebIDBDatabaseImpl.h	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebKit/chromium/src/WebIDBDatabaseImpl.h	2013-01-02 23:48:58 UTC (rev 138666)
@@ -64,7 +64,7 @@
     virtual void commit(long long transactionId);
 
     virtual void get(long long transactionId, long long objectStoreId, long long indexId, const WebIDBKeyRange&, bool keyOnly, WebIDBCallbacks*) OVERRIDE;
-    virtual void put(long long transactionId, long long objectStoreId, const WebVector<unsigned char>& value, const WebIDBKey&, PutMode, WebIDBCallbacks*, const WebVector<long long>& indexIds, const WebVector<WebIndexKeys>&) OVERRIDE;
+    virtual void put(long long transactionId, long long objectStoreId, WebVector<unsigned char>* value, const WebIDBKey&, PutMode, WebIDBCallbacks*, const WebVector<long long>& indexIds, const WebVector<WebIndexKeys>&) OVERRIDE;
     virtual void setIndexKeys(long long transactionId, long long objectStoreId, const WebIDBKey&, const WebVector<long long>& indexIds, const WebVector<WebIndexKeys>&) OVERRIDE;
     virtual void setIndexesReady(long long transactionId, long long objectStoreId, const WebVector<long long>& indexIds) OVERRIDE;
     virtual void openCursor(long long transactionId, long long objectStoreId, long long indexId, const WebIDBKeyRange&, unsigned short direction, bool keyOnly, TaskType, WebIDBCallbacks*) OVERRIDE;

Modified: trunk/Source/WebKit/chromium/tests/IDBDatabaseBackendTest.cpp (138665 => 138666)


--- trunk/Source/WebKit/chromium/tests/IDBDatabaseBackendTest.cpp	2013-01-02 23:41:17 UTC (rev 138665)
+++ trunk/Source/WebKit/chromium/tests/IDBDatabaseBackendTest.cpp	2013-01-02 23:48:58 UTC (rev 138666)
@@ -170,7 +170,7 @@
     virtual void openCursor(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, unsigned short direction, bool keyOnly, TaskType, PassRefPtr<IDBCallbacks>) OVERRIDE { }
     virtual void count(int64_t objectStoreId, int64_t indexId, int64_t transactionId, PassRefPtr<IDBKeyRange>, PassRefPtr<IDBCallbacks>) OVERRIDE { }
     virtual void get(int64_t objectStoreId, int64_t indexId, int64_t transactionId, PassRefPtr<IDBKeyRange>, bool keyOnly, PassRefPtr<IDBCallbacks>) OVERRIDE { }
-    virtual void put(int64_t transactionId, int64_t objectStoreId, const Vector<uint8_t>&, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE { }
+    virtual void put(int64_t transactionId, int64_t objectStoreId, Vector<uint8_t>*, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE { }
     virtual void setIndexKeys(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKey> prpPrimaryKey, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) OVERRIDE { }
     virtual void setIndexesReady(int64_t transactionId, int64_t objectStoreId, const Vector<int64_t>& indexIds) OVERRIDE { }
     virtual void deleteRange(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKeyRange>, PassRefPtr<IDBCallbacks>) OVERRIDE { }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to