Bug 1575519 - use `auto&` in ranged-for loops to avoid copies; r=chutten
authorNathan Froyd <froydnj@mozilla.com>
Wed, 21 Aug 2019 12:35:16 +0000
changeset 489178 d3cf30302250fca413dd2c19cea7bb4b01e66575
parent 489177 15d657ead37c61ae9c6da0c8a06ff477eeb8fc51
child 489179 4ab60925635ce3d59573a6021486ab9bd272cbec
push id36465
push userdvarga@mozilla.com
push dateWed, 21 Aug 2019 16:47:43 +0000
treeherdermozilla-central@4ab60925635c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1575519
milestone70.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 1575519 - use `auto&` in ranged-for loops to avoid copies; r=chutten This style is used consistently throughout telemetry code, but was missed in these places. Differential Revision: https://phabricator.services.mozilla.com/D42830
toolkit/components/telemetry/core/TelemetryEvent.cpp
toolkit/components/telemetry/core/TelemetryScalar.cpp
--- a/toolkit/components/telemetry/core/TelemetryEvent.cpp
+++ b/toolkit/components/telemetry/core/TelemetryEvent.cpp
@@ -1289,17 +1289,17 @@ nsresult TelemetryEvent::CreateSnapshots
         }
       }
     };
 
     // Take a snapshot of the plain and dynamic builtin events.
     snapshotter(gEventRecords);
     if (aClear) {
       gEventRecords.Clear();
-      for (auto pair : leftovers) {
+      for (auto& pair : leftovers) {
         gEventRecords.Put(pair.first(),
                           new EventRecordArray(std::move(pair.second())));
       }
       leftovers.Clear();
     }
   }
 
   // (2) Serialize the events to a JS object.
--- a/toolkit/components/telemetry/core/TelemetryScalar.cpp
+++ b/toolkit/components/telemetry/core/TelemetryScalar.cpp
@@ -1841,17 +1841,17 @@ ScalarResult internal_UpdateKeyedScalar(
 /**
  * Helper function to convert an array of |DynamicScalarInfo|
  * to |DynamicScalarDefinition| used by the IPC calls.
  */
 void internal_DynamicScalarToIPC(
     const StaticMutexAutoLock& lock,
     const nsTArray<DynamicScalarInfo>& aDynamicScalarInfos,
     nsTArray<DynamicScalarDefinition>& aIPCDefs) {
-  for (auto info : aDynamicScalarInfos) {
+  for (auto& info : aDynamicScalarInfos) {
     DynamicScalarDefinition stubDefinition;
     stubDefinition.type = info.kind;
     stubDefinition.dataset = info.dataset;
     stubDefinition.expired = info.mDynamicExpiration;
     stubDefinition.keyed = info.keyed;
     stubDefinition.name = info.mDynamicName;
     stubDefinition.builtin = info.builtin;
     aIPCDefs.AppendElement(stubDefinition);
@@ -1886,17 +1886,17 @@ void internal_RegisterScalars(const Stat
   // Register the new scalars.
   if (!gDynamicScalarInfo) {
     gDynamicScalarInfo = new nsTArray<DynamicScalarInfo>();
   }
   if (!gDynamicStoreNames) {
     gDynamicStoreNames = new nsTArray<RefPtr<nsAtom>>();
   }
 
-  for (auto scalarInfo : scalarInfos) {
+  for (auto& scalarInfo : scalarInfos) {
     // Allow expiring scalars that were already registered.
     CharPtrEntryType* existingKey =
         gScalarNameIDMap.GetEntry(scalarInfo.name());
     if (existingKey) {
       // Change the scalar to expired if needed.
       if (scalarInfo.mDynamicExpiration && !scalarInfo.builtin) {
         DynamicScalarInfo& scalarData =
             (*gDynamicScalarInfo)[existingKey->mData.id];
@@ -3655,17 +3655,17 @@ void TelemetryScalar::GetDynamicScalarDe
  */
 void TelemetryScalar::AddDynamicScalarDefinitions(
     const nsTArray<DynamicScalarDefinition>& aDefs) {
   MOZ_ASSERT(!XRE_IsParentProcess());
 
   nsTArray<DynamicScalarInfo> dynamicStubs;
 
   // Populate the definitions array before acquiring the lock.
-  for (auto def : aDefs) {
+  for (auto& def : aDefs) {
     bool recordOnRelease = def.dataset == nsITelemetry::DATASET_ALL_CHANNELS;
     dynamicStubs.AppendElement(DynamicScalarInfo{def.type,
                                                  recordOnRelease,
                                                  def.expired,
                                                  def.name,
                                                  def.keyed,
                                                  def.builtin,
                                                  {} /* stores */});