Bug 1187782 (part 4) - Replace nsBaseHashtable::EnumerateRead() calls in dom/base/ with iterators. r=khuey.

This commit is contained in:
Nicholas Nethercote 2015-10-26 22:22:31 -07:00
parent 087874d2bd
commit 298af7337f
2 changed files with 9 additions and 30 deletions

View File

@ -12869,18 +12869,6 @@ nsGlobalWindow::RemoveGamepad(uint32_t aIndex)
mGamepads.Remove(aIndex);
}
// static
PLDHashOperator
nsGlobalWindow::EnumGamepadsForGet(const uint32_t& aKey, Gamepad* aData,
void* aUserArg)
{
nsTArray<RefPtr<Gamepad> >* array =
static_cast<nsTArray<RefPtr<Gamepad> >*>(aUserArg);
array->EnsureLengthAtLeast(aData->Index() + 1);
(*array)[aData->Index()] = aData;
return PL_DHASH_NEXT;
}
void
nsGlobalWindow::GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads)
{
@ -12888,7 +12876,11 @@ nsGlobalWindow::GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads)
aGamepads.Clear();
// mGamepads.Count() may not be sufficient, but it's not harmful.
aGamepads.SetCapacity(mGamepads.Count());
mGamepads.EnumerateRead(EnumGamepadsForGet, &aGamepads);
for (auto iter = mGamepads.Iter(); !iter.Done(); iter.Next()) {
Gamepad* gamepad = iter.UserData();
aGamepads.EnsureLengthAtLeast(gamepad->Index() + 1);
aGamepads[gamepad->Index()] = gamepad;
}
}
already_AddRefed<Gamepad>
@ -12918,22 +12910,15 @@ nsGlobalWindow::HasSeenGamepadInput()
return mHasSeenGamepadInput;
}
// static
PLDHashOperator
nsGlobalWindow::EnumGamepadsForSync(const uint32_t& aKey, Gamepad* aData,
void* aUserArg)
{
RefPtr<GamepadService> gamepadsvc(GamepadService::GetService());
gamepadsvc->SyncGamepadState(aKey, aData);
return PL_DHASH_NEXT;
}
void
nsGlobalWindow::SyncGamepadState()
{
MOZ_ASSERT(IsInnerWindow());
if (mHasSeenGamepadInput) {
mGamepads.EnumerateRead(EnumGamepadsForSync, nullptr);
RefPtr<GamepadService> gamepadsvc(GamepadService::GetService());
for (auto iter = mGamepads.Iter(); !iter.Done(); iter.Next()) {
gamepadsvc->SyncGamepadState(iter.Key(), iter.UserData());
}
}
}
#endif // MOZ_GAMEPAD

View File

@ -763,12 +763,6 @@ public:
void SetHasSeenGamepadInput(bool aHasSeen);
bool HasSeenGamepadInput();
void SyncGamepadState();
static PLDHashOperator EnumGamepadsForSync(const uint32_t& aKey,
mozilla::dom::Gamepad* aData,
void* aUserArg);
static PLDHashOperator EnumGamepadsForGet(const uint32_t& aKey,
mozilla::dom::Gamepad* aData,
void* aUserArg);
#endif
// Inner windows only.