yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

input_engine: Iterate by reference rather than by value where applicable

Avoids creating copies of several object instances (some of which being
over 100 bytes in size).
This commit is contained in:
Lioncash 2021-12-13 09:32:55 -05:00
parent 755822ceec
commit e826e6715a
1 changed files with 10 additions and 10 deletions

View File

@ -170,19 +170,19 @@ BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion)
} }
void InputEngine::ResetButtonState() { void InputEngine::ResetButtonState() {
for (std::pair<PadIdentifier, ControllerData> controller : controller_list) { for (const auto& controller : controller_list) {
for (std::pair<int, bool> button : controller.second.buttons) { for (const auto& button : controller.second.buttons) {
SetButton(controller.first, button.first, false); SetButton(controller.first, button.first, false);
} }
for (std::pair<int, bool> button : controller.second.hat_buttons) { for (const auto& button : controller.second.hat_buttons) {
SetHatButton(controller.first, button.first, false); SetHatButton(controller.first, button.first, false);
} }
} }
} }
void InputEngine::ResetAnalogState() { void InputEngine::ResetAnalogState() {
for (std::pair<PadIdentifier, ControllerData> controller : controller_list) { for (const auto& controller : controller_list) {
for (std::pair<int, float> axis : controller.second.axes) { for (const auto& axis : controller.second.axes) {
SetAxis(controller.first, axis.first, 0.0); SetAxis(controller.first, axis.first, 0.0);
} }
} }
@ -190,7 +190,7 @@ void InputEngine::ResetAnalogState() {
void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value) { void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int button, bool value) {
std::lock_guard lock{mutex_callback}; std::lock_guard lock{mutex_callback};
for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { for (const auto& poller_pair : callback_list) {
const InputIdentifier& poller = poller_pair.second; const InputIdentifier& poller = poller_pair.second;
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Button, button)) { if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Button, button)) {
continue; continue;
@ -218,7 +218,7 @@ void InputEngine::TriggerOnButtonChange(const PadIdentifier& identifier, int but
void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value) { void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value) {
std::lock_guard lock{mutex_callback}; std::lock_guard lock{mutex_callback};
for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { for (const auto& poller_pair : callback_list) {
const InputIdentifier& poller = poller_pair.second; const InputIdentifier& poller = poller_pair.second;
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::HatButton, button)) { if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::HatButton, button)) {
continue; continue;
@ -247,7 +247,7 @@ void InputEngine::TriggerOnHatButtonChange(const PadIdentifier& identifier, int
void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value) { void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value) {
std::lock_guard lock{mutex_callback}; std::lock_guard lock{mutex_callback};
for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { for (const auto& poller_pair : callback_list) {
const InputIdentifier& poller = poller_pair.second; const InputIdentifier& poller = poller_pair.second;
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Analog, axis)) { if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Analog, axis)) {
continue; continue;
@ -274,7 +274,7 @@ void InputEngine::TriggerOnAxisChange(const PadIdentifier& identifier, int axis,
void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier, void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
[[maybe_unused]] BatteryLevel value) { [[maybe_unused]] BatteryLevel value) {
std::lock_guard lock{mutex_callback}; std::lock_guard lock{mutex_callback};
for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { for (const auto& poller_pair : callback_list) {
const InputIdentifier& poller = poller_pair.second; const InputIdentifier& poller = poller_pair.second;
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Battery, 0)) { if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Battery, 0)) {
continue; continue;
@ -288,7 +288,7 @@ void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier,
void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion, void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion,
const BasicMotion& value) { const BasicMotion& value) {
std::lock_guard lock{mutex_callback}; std::lock_guard lock{mutex_callback};
for (const std::pair<int, InputIdentifier> poller_pair : callback_list) { for (const auto& poller_pair : callback_list) {
const InputIdentifier& poller = poller_pair.second; const InputIdentifier& poller = poller_pair.second;
if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Motion, motion)) { if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Motion, motion)) {
continue; continue;