fix(pulseaudio): Avoid allocation of string vector on every call of getPortIcon()

This commit is contained in:
Aleksei Bavshin 2019-03-14 18:35:16 -07:00
parent 492d151079
commit 9ad80849b1
1 changed files with 13 additions and 11 deletions

View File

@ -1,4 +1,5 @@
#include "modules/pulseaudio.hpp" #include "modules/pulseaudio.hpp"
#include <array>
waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value &config) waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value &config)
: ALabel(config, "{volume}%"), : ALabel(config, "{volume}%"),
@ -174,9 +175,7 @@ void waybar::modules::Pulseaudio::serverInfoCb(pa_context *context,
sinkInfoCb, data); sinkInfoCb, data);
} }
const std::string waybar::modules::Pulseaudio::getPortIcon() const static const std::array<std::string, 9> ports = {
{
std::vector<std::string> ports = {
"headphones", "headphones",
"speaker", "speaker",
"hdmi", "hdmi",
@ -186,7 +185,10 @@ const std::string waybar::modules::Pulseaudio::getPortIcon() const
"car", "car",
"hifi", "hifi",
"phone", "phone",
}; };
const std::string waybar::modules::Pulseaudio::getPortIcon() const
{
std::string nameLC = port_name_; std::string nameLC = port_name_;
std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower); std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower);
for (auto const& port : ports) { for (auto const& port : ports) {