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.
This commit is contained in:
Nathan Froyd 2016-07-20 16:55:07 -04:00
Родитель f55fa7da7a
Коммит 2f28c4b3a4
1 изменённых файлов: 3 добавлений и 2 удалений

Просмотреть файл

@ -48,8 +48,9 @@ GPUParent::Init(base::ProcessId aParentPid,
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;