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.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.h') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index ac18c18803..8281396515 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "Common/CommonTypes.h" @@ -42,14 +43,14 @@ public: class Control // input or output { public: + virtual ~Control() = default; virtual std::string GetName() const = 0; - virtual ~Control() {} virtual Input* ToInput() { return nullptr; } virtual Output* ToOutput() { return nullptr; } // May be overridden to allow multiple valid names. // Useful for backwards-compatible configurations when names change. - virtual bool IsMatchingName(const std::string& name) const; + virtual bool IsMatchingName(std::string_view name) const; }; // @@ -111,8 +112,8 @@ public: const std::vector& Inputs() const { return m_inputs; } const std::vector& Outputs() const { return m_outputs; } - Input* FindInput(const std::string& name) const; - Output* FindOutput(const std::string& name) const; + Input* FindInput(std::string_view name) const; + Output* FindOutput(std::string_view name) const; protected: void AddInput(Input* const i); @@ -124,7 +125,7 @@ protected: FullAnalogSurface(Input* low, Input* high) : m_low(*low), m_high(*high) {} ControlState GetState() const override; std::string GetName() const override; - bool IsMatchingName(const std::string& name) const override; + bool IsMatchingName(std::string_view name) const override; private: Input& m_low; @@ -177,8 +178,8 @@ public: class DeviceContainer { public: - Device::Input* FindInput(const std::string& name, const Device* def_dev) const; - Device::Output* FindOutput(const std::string& name, const Device* def_dev) const; + Device::Input* FindInput(std::string_view name, const Device* def_dev) const; + Device::Output* FindOutput(std::string_view name, const Device* def_dev) const; std::vector GetAllDeviceStrings() const; std::string GetDefaultDeviceString() const; -- cgit v1.2.3 From 246e2a77ceb7fb5ebf05286af07f598b3db40c2b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 18:46:44 -0400 Subject: ControllerInterface/Device: std::move strings in constructor where applicable Allows callers to move std::string values into the constructor, potentially avoiding copies. --- Source/Core/InputCommon/ControllerInterface/Device.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.h') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index 8281396515..b5a8695629 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -156,8 +156,8 @@ class DeviceQualifier { public: DeviceQualifier() : cid(-1) {} - DeviceQualifier(const std::string& _source, const int _id, const std::string& _name) - : source(_source), cid(_id), name(_name) + DeviceQualifier(std::string source_, const int id_, std::string name_) + : source(std::move(source_)), cid(id_), name(std::move(name_)) { } void FromDevice(const Device* const dev); -- 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.h') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index b5a8695629..fd947ee654 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -188,7 +188,7 @@ public: bool HasConnectedDevice(const DeviceQualifier& qualifier) const; std::pair, Device::Input*> - DetectInput(u32 wait_ms, std::vector device_strings); + DetectInput(u32 wait_ms, const std::vector& device_strings); protected: mutable std::mutex m_devices_mutex; -- 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.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Device.h') diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index fd947ee654..a2cf0a329a 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -188,7 +188,7 @@ public: bool HasConnectedDevice(const DeviceQualifier& qualifier) const; std::pair, Device::Input*> - DetectInput(u32 wait_ms, const std::vector& device_strings); + DetectInput(u32 wait_ms, const std::vector& device_strings) const; protected: mutable std::mutex m_devices_mutex; -- cgit v1.2.3