diff options
author | Chris Robinson <[email protected]> | 2022-12-15 22:35:52 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2022-12-15 22:35:52 -0800 |
commit | 8b806c07d716db41e0a463d455cf1a913b933a0f (patch) | |
tree | 7e4516e8f6e79abbbd06dff84ad2a1d0a4f161a6 /alc/backends | |
parent | 2bd11bafa4b36977c9d467d5e2d735a8eba1b336 (diff) |
Avoid extraneous temporaries when filling vectors
Diffstat (limited to 'alc/backends')
-rw-r--r-- | alc/backends/alsa.cpp | 13 | ||||
-rw-r--r-- | alc/backends/jack.cpp | 13 |
2 files changed, 18 insertions, 8 deletions
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index 85f1824b..e495a34d 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -241,6 +241,11 @@ SwParamsPtr CreateSwParams() struct DevMap { std::string name; std::string device_name; + + template<typename T, typename U> + DevMap(T&& name_, U&& devname) + : name{std::forward<T>(name_)}, device_name{std::forward<U>(devname)} + { } }; al::vector<DevMap> PlaybackDevices; @@ -264,7 +269,7 @@ al::vector<DevMap> probe_devices(snd_pcm_stream_t stream) auto defname = ConfigValueStr(nullptr, "alsa", (stream == SND_PCM_STREAM_PLAYBACK) ? "device" : "capture"); - devlist.emplace_back(DevMap{alsaDevice, defname ? defname->c_str() : "default"}); + devlist.emplace_back(alsaDevice, defname ? defname->c_str() : "default"); if(auto customdevs = ConfigValueStr(nullptr, "alsa", (stream == SND_PCM_STREAM_PLAYBACK) ? "custom-devices" : "custom-captures")) @@ -283,8 +288,8 @@ al::vector<DevMap> probe_devices(snd_pcm_stream_t stream) } else { - devlist.emplace_back(DevMap{customdevs->substr(curpos, seppos-curpos), - customdevs->substr(seppos+1, nextpos-seppos-1)}); + devlist.emplace_back(customdevs->substr(curpos, seppos-curpos), + customdevs->substr(seppos+1, nextpos-seppos-1)); const auto &entry = devlist.back(); TRACE("Got device \"%s\", \"%s\"\n", entry.name.c_str(), entry.device_name.c_str()); } @@ -367,7 +372,7 @@ al::vector<DevMap> probe_devices(snd_pcm_stream_t stream) device += ",DEV="; device += std::to_string(dev); - devlist.emplace_back(DevMap{std::move(name), std::move(device)}); + devlist.emplace_back(std::move(name), std::move(device)); const auto &entry = devlist.back(); TRACE("Got device \"%s\", \"%s\"\n", entry.name.c_str(), entry.device_name.c_str()); } diff --git a/alc/backends/jack.cpp b/alc/backends/jack.cpp index cbe1184d..485f19d0 100644 --- a/alc/backends/jack.cpp +++ b/alc/backends/jack.cpp @@ -160,6 +160,11 @@ using JackPortsPtr = std::unique_ptr<const char*[],JackDeleter>; struct DeviceEntry { std::string mName; std::string mPattern; + + template<typename T, typename U> + DeviceEntry(T&& name, U&& pattern) + : mName{std::forward<T>(name)}, mPattern{std::forward<U>(pattern)} + { } }; al::vector<DeviceEntry> PlaybackList; @@ -187,7 +192,7 @@ void EnumerateDevices(jack_client_t *client, al::vector<DeviceEntry> &list) continue; std::string name{portdev.data(), portdev.size()}; - list.emplace_back(DeviceEntry{name, name+":"}); + list.emplace_back(name, name+":"); const auto &entry = list.back(); TRACE("Got device: %s = %s\n", entry.mName.c_str(), entry.mPattern.c_str()); } @@ -197,7 +202,7 @@ void EnumerateDevices(jack_client_t *client, al::vector<DeviceEntry> &list) if(ports[0] && list.empty()) { WARN("No device names found in available ports, adding a generic name.\n"); - list.emplace_back(DeviceEntry{"JACK", ""}); + list.emplace_back("JACK", ""); } } @@ -238,8 +243,8 @@ void EnumerateDevices(jack_client_t *client, al::vector<DeviceEntry> &list) else { /* Otherwise, add a new device entry. */ - list.emplace_back(DeviceEntry{std::string{name.data(), name.size()}, - std::string{pattern.data(), pattern.size()}}); + list.emplace_back(std::string{name.data(), name.size()}, + std::string{pattern.data(), pattern.size()}); const auto &entry = list.back(); TRACE("Got custom device: %s = %s\n", entry.mName.c_str(), entry.mPattern.c_str()); } |