Bug 1578453 - Correctly calculate response size in IndexGetKeyRequestOp::GetResponse and ObjectStoreGetKeyRequestOp::GetResponse r=ttung,asuth
authorSimon Giesecke <sgiesecke@mozilla.com>
Thu, 26 Sep 2019 21:49:54 +0000
changeset 495381 d23a0a0ffa93fe273c571592bdbff6aa68f6ca2b
parent 495380 feba8126032f55aaee9accdfa97eb269e363818e
child 495382 91c6cd8945d71d2bb2fea59748336f6b436f15aa
push id36627
push userdluca@mozilla.com
push dateFri, 27 Sep 2019 21:57:13 +0000
treeherdermozilla-central@d23a0a0ffa93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersttung, asuth
bugs1578453
milestone71.0a1
first release with
nightly linux32
d23a0a0ffa93 / 71.0a1 / 20190927215713 / files
nightly linux64
d23a0a0ffa93 / 71.0a1 / 20190927215713 / files
nightly mac
d23a0a0ffa93 / 71.0a1 / 20190927215713 / files
nightly win32
d23a0a0ffa93 / 71.0a1 / 20190927215713 / files
nightly win64
d23a0a0ffa93 / 71.0a1 / 20190927215713 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1578453 - Correctly calculate response size in IndexGetKeyRequestOp::GetResponse and ObjectStoreGetKeyRequestOp::GetResponse r=ttung,asuth Before this, the response size was always calculated as 0, since it used the swapped-out array. In addition, make use of std::accumulate to increase idiomacy. Differential Revision: https://phabricator.services.mozilla.com/D44806
dom/indexedDB/ActorsParent.cpp
--- a/dom/indexedDB/ActorsParent.cpp
+++ b/dom/indexedDB/ActorsParent.cpp
@@ -2,16 +2,17 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ActorsParent.h"
 
 #include <algorithm>
+#include <numeric>
 #include <stdint.h>  // UINTPTR_MAX, uintptr_t
 #include "FileInfo.h"
 #include "FileManager.h"
 #include "IDBObjectStore.h"
 #include "IDBTransaction.h"
 #include "IndexedDatabase.h"
 #include "IndexedDatabaseInlines.h"
 #include "IndexedDatabaseManager.h"
@@ -24913,27 +24914,23 @@ nsresult ObjectStoreGetKeyRequestOp::DoD
 }
 
 void ObjectStoreGetKeyRequestOp::GetResponse(RequestResponse& aResponse,
                                              size_t* aResponseSize) {
   MOZ_ASSERT_IF(mLimit, mResponse.Length() <= mLimit);
 
   if (mGetAll) {
     aResponse = ObjectStoreGetAllKeysResponse();
-    *aResponseSize = 0;
-
-    if (!mResponse.IsEmpty()) {
-      nsTArray<Key>& response =
-          aResponse.get_ObjectStoreGetAllKeysResponse().keys();
-
-      mResponse.SwapElements(response);
-      for (uint32_t i = 0; i < mResponse.Length(); ++i) {
-        *aResponseSize += mResponse[i].GetBuffer().Length();
-      }
-    }
+    *aResponseSize = std::accumulate(mResponse.begin(), mResponse.end(), 0u,
+                                     [](size_t old, const auto& entry) {
+                                       return old + entry.GetBuffer().Length();
+                                     });
+
+    mResponse.SwapElements(
+        aResponse.get_ObjectStoreGetAllKeysResponse().keys());
 
     return;
   }
 
   aResponse = ObjectStoreGetKeyResponse();
   *aResponseSize = 0;
 
   if (!mResponse.IsEmpty()) {
@@ -25487,24 +25484,22 @@ nsresult IndexGetKeyRequestOp::DoDatabas
 }
 
 void IndexGetKeyRequestOp::GetResponse(RequestResponse& aResponse,
                                        size_t* aResponseSize) {
   MOZ_ASSERT_IF(!mGetAll, mResponse.Length() <= 1);
 
   if (mGetAll) {
     aResponse = IndexGetAllKeysResponse();
-    *aResponseSize = 0;
-
-    if (!mResponse.IsEmpty()) {
-      mResponse.SwapElements(aResponse.get_IndexGetAllKeysResponse().keys());
-      for (uint32_t i = 0; i < mResponse.Length(); ++i) {
-        *aResponseSize += mResponse[i].GetBuffer().Length();
-      }
-    }
+    *aResponseSize = std::accumulate(mResponse.begin(), mResponse.end(), 0u,
+                                     [](size_t old, const auto& entry) {
+                                       return old + entry.GetBuffer().Length();
+                                     });
+
+    mResponse.SwapElements(aResponse.get_IndexGetAllKeysResponse().keys());
 
     return;
   }
 
   aResponse = IndexGetKeyResponse();
   *aResponseSize = 0;
 
   if (!mResponse.IsEmpty()) {