Bug 1596129 - Make use of std::accumulate in IDBObjectStore::AddOrPut. r=dom-workers-and-storage-reviewers,ytausky
authorSimon Giesecke <sgiesecke@mozilla.com>
Thu, 21 Nov 2019 12:40:54 +0000
changeset 565110 a70ff1b7351ea8d354227f2010fc87ebafe9af66
parent 565109 e6ee464360c86a2c681699eace7f73625a3a45d3
child 565111 780c9d2a7aa4e99b826f675c5bfb8c66c23e6165
push id12351
push userffxbld-merge
push dateMon, 02 Dec 2019 11:32:26 +0000
treeherdermozilla-beta@dba4410526a2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdom-workers-and-storage-reviewers, ytausky
bugs1596129
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1596129 - Make use of std::accumulate in IDBObjectStore::AddOrPut. r=dom-workers-and-storage-reviewers,ytausky Depends on D52865 Differential Revision: https://phabricator.services.mozilla.com/D52866
dom/indexedDB/IDBObjectStore.cpp
--- a/dom/indexedDB/IDBObjectStore.cpp
+++ b/dom/indexedDB/IDBObjectStore.cpp
@@ -48,16 +48,18 @@
 #include "mozilla/SystemGroup.h"
 #include "nsCOMPtr.h"
 #include "nsQueryObject.h"
 #include "nsStreamUtils.h"
 #include "nsStringStream.h"
 #include "ProfilerHelpers.h"
 #include "ReportInternalError.h"
 
+#include <numeric>
+
 // Include this last to avoid path problems on Windows.
 #include "ActorsChild.h"
 
 namespace mozilla {
 namespace dom {
 
 using namespace mozilla::dom::indexedDB;
 using namespace mozilla::dom::quota;
@@ -1526,21 +1528,22 @@ already_AddRefed<IDBRequest> IDBObjectSt
   // kMaxIDBMsgOverhead covers the minor stuff not included in this calculation
   // because the precise calculation would slow down this AddOrPut operation.
   static const size_t kMaxIDBMsgOverhead = 1024 * 1024;  // 1MB
   const uint32_t maximalSizeFromPref =
       IndexedDatabaseManager::MaxSerializedMsgSize();
   MOZ_ASSERT(maximalSizeFromPref > kMaxIDBMsgOverhead);
   const size_t kMaxMessageSize = maximalSizeFromPref - kMaxIDBMsgOverhead;
 
-  size_t indexUpdateInfoSize = 0;
-  for (size_t i = 0; i < updateInfo.Length(); i++) {
-    indexUpdateInfoSize += updateInfo[i].value().GetBuffer().Length();
-    indexUpdateInfoSize += updateInfo[i].localizedValue().GetBuffer().Length();
-  }
+  const size_t indexUpdateInfoSize =
+      std::accumulate(updateInfo.cbegin(), updateInfo.cend(), 0u,
+                      [](size_t old, const IndexUpdateInfo& updateInfo) {
+                        return old + updateInfo.value().GetBuffer().Length() +
+                               updateInfo.localizedValue().GetBuffer().Length();
+                      });
 
   const size_t messageSize = cloneWriteInfo.mCloneBuffer.data().Size() +
                              key.GetBuffer().Length() + indexUpdateInfoSize;
 
   if (messageSize > kMaxMessageSize) {
     IDB_REPORT_INTERNAL_ERR();
     aRv.ThrowDOMException(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR,
                           nsPrintfCString("The serialized value is too large"