Bug 1287784 - micro-optimize GPUParent::RecvInit; r=milan
authorNathan Froyd <froydnj@gmail.com>
Wed, 20 Jul 2016 16:55:07 -0400
changeset 345925 d4e0d608e85a375af999d82651b8f9f5aefae61a
parent 345924 d5baa3f32ca4945ec50f726798774369e51abf64
child 345926 f9152e9e26052e1b5e3532d1b350599f3590e1e0
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmilan
bugs1287784
milestone50.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 1287784 - micro-optimize GPUParent::RecvInit; r=milan We can make GPUParent::RecvInit more efficient in two ways: 1. Using `auto&' for the type of the for-loop variable means that we're not copying each GfxPrefSetting value that we're iterating over, which is a win. 2. Pulling the `gfxPrefs::all()' call out of the loop means that we don't have to call it on each iteration. You may think the compiler could do this for you, but the compiler can't be sure that sGfxPrefList isn't being modified by SetCachedValue.
gfx/ipc/GPUParent.cpp
--- a/gfx/ipc/GPUParent.cpp
+++ b/gfx/ipc/GPUParent.cpp
@@ -43,18 +43,19 @@ GPUParent::Init(base::ProcessId aParentP
   CompositorThreadHolder::Start();
   gfxPlatform::InitNullMetadata();
   return true;
 }
 
 bool
 GPUParent::RecvInit(nsTArray<GfxPrefSetting>&& prefs)
 {
-  for (auto setting : prefs) {
-    gfxPrefs::Pref* pref = gfxPrefs::all()[setting.index()];
+  const nsTArray<gfxPrefs::Pref*>& globalPrefs = gfxPrefs::all();
+  for (auto& setting : prefs) {
+    gfxPrefs::Pref* pref = globalPrefs[setting.index()];
     pref->SetCachedValue(setting.value());
   }
   return true;
 }
 
 bool
 GPUParent::RecvInitVsyncBridge(Endpoint<PVsyncBridgeParent>&& aVsyncEndpoint)
 {