From 1355b43fd242f20d04b1250c02de355c8e80ac98 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 18:42:22 -0400 Subject: ControllerInterface/Device: Use std::string_view where applicable In these cases, the given string is only ever compared against other string, so std::string can be turned into a std::string_view to allow non-allocating inputs. --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 38b11a932b..9e29389dae 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -52,7 +52,7 @@ std::string Device::GetQualifiedName() const return StringFromFormat("%s/%i/%s", this->GetSource().c_str(), GetId(), this->GetName().c_str()); } -Device::Input* Device::FindInput(const std::string& name) const +Device::Input* Device::FindInput(std::string_view name) const { for (Input* input : m_inputs) { @@ -63,7 +63,7 @@ Device::Input* Device::FindInput(const std::string& name) const return nullptr; } -Device::Output* Device::FindOutput(const std::string& name) const +Device::Output* Device::FindOutput(std::string_view name) const { for (Output* output : m_outputs) { @@ -74,7 +74,7 @@ Device::Output* Device::FindOutput(const std::string& name) const return nullptr; } -bool Device::Control::IsMatchingName(const std::string& name) const +bool Device::Control::IsMatchingName(std::string_view name) const { return GetName() == name; } @@ -90,7 +90,7 @@ std::string Device::FullAnalogSurface::GetName() const return "Full " + m_high.GetName(); } -bool Device::FullAnalogSurface::IsMatchingName(const std::string& name) const +bool Device::FullAnalogSurface::IsMatchingName(std::string_view name) const { if (Control::IsMatchingName(name)) return true; @@ -218,7 +218,7 @@ std::string DeviceContainer::GetDefaultDeviceString() const return device_qualifier.ToString(); } -Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* def_dev) const +Device::Input* DeviceContainer::FindInput(std::string_view name, const Device* def_dev) const { if (def_dev) { @@ -239,7 +239,7 @@ Device::Input* DeviceContainer::FindInput(const std::string& name, const Device* return nullptr; } -Device::Output* DeviceContainer::FindOutput(const std::string& name, const Device* def_dev) const +Device::Output* DeviceContainer::FindOutput(std::string_view name, const Device* def_dev) const { return def_dev->FindOutput(name); } -- cgit v1.2.3 From 27346fee8a5466503f32493510da98846f2efb01 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 19:10:50 -0400 Subject: ControllerInterface/Device: Take vector by const reference in DetectInput() The vector is only ever queryied and it's contents aren't modified, so there's no reason to take the vector by value. We can take a constant reference to it to avoid unnecessary allocating. --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 9e29389dae..9fbeae22cf 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -256,7 +256,7 @@ bool DeviceContainer::HasConnectedDevice(const DeviceQualifier& qualifier) const // and also properly handles detection when using "FullAnalogSurface" inputs. // Upon input, return the detected Device and Input, else return nullptrs std::pair, Device::Input*> -DeviceContainer::DetectInput(u32 wait_ms, std::vector device_strings) +DeviceContainer::DetectInput(u32 wait_ms, const std::vector& device_strings) { struct InputState { @@ -273,7 +273,7 @@ DeviceContainer::DetectInput(u32 wait_ms, std::vector device_string // Acquire devices and initial input states. std::vector device_states; - for (auto& device_string : device_strings) + for (const auto& device_string : device_strings) { DeviceQualifier dq; dq.FromString(device_string); -- cgit v1.2.3 From 02634350500bd4e7b85425cae7bb43a050b5aee4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 19:23:51 -0400 Subject: ControllerInterface/Device: Make DetectInput() a const member function This doesn't actually modify object instance state, so it can be made const. --- Source/Core/InputCommon/ControllerInterface/Device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 9fbeae22cf..954d933ad8 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -256,7 +256,7 @@ bool DeviceContainer::HasConnectedDevice(const DeviceQualifier& qualifier) const // and also properly handles detection when using "FullAnalogSurface" inputs. // Upon input, return the detected Device and Input, else return nullptrs std::pair, Device::Input*> -DeviceContainer::DetectInput(u32 wait_ms, const std::vector& device_strings) +DeviceContainer::DetectInput(u32 wait_ms, const std::vector& device_strings) const { struct InputState { -- cgit v1.2.3