From 4d1671f1475258fe5f3379f5bfa0a9cca78538fd Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 27 Dec 2022 19:14:59 +1000 Subject: [PATCH] USB: Use map lookup instead of advance --- pcsx2/USB/deviceproxy.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pcsx2/USB/deviceproxy.h b/pcsx2/USB/deviceproxy.h index 3be7ce096c..27942dfc3d 100644 --- a/pcsx2/USB/deviceproxy.h +++ b/pcsx2/USB/deviceproxy.h @@ -113,16 +113,10 @@ public: return nullptr; } - DeviceProxy* Device(int index) + DeviceProxy* Device(s32 index) { - if (index < 0) - return nullptr; // Don't try to go backwards at the beginning of an iterator and crash and burn when pcsx2 is run for the first time. - - auto it = registerDeviceMap.begin(); - std::advance(it, index); - if (it != registerDeviceMap.end()) - return it->second.get(); - return nullptr; + const auto it = registerDeviceMap.find(static_cast(index)); + return (it != registerDeviceMap.end()) ? it->second.get() : nullptr; } DeviceType Index(const std::string_view& name)