From 9ad80849b1ced209c8075ddcc14e236953836937 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Thu, 14 Mar 2019 18:35:16 -0700 Subject: [PATCH] fix(pulseaudio): Avoid allocation of string vector on every call of getPortIcon() --- src/modules/pulseaudio.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index e2872134..b5dfe49f 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -1,4 +1,5 @@ #include "modules/pulseaudio.hpp" +#include waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value &config) : ALabel(config, "{volume}%"), @@ -174,19 +175,20 @@ void waybar::modules::Pulseaudio::serverInfoCb(pa_context *context, sinkInfoCb, data); } +static const std::array ports = { + "headphones", + "speaker", + "hdmi", + "headset", + "handsfree", + "portable", + "car", + "hifi", + "phone", +}; + const std::string waybar::modules::Pulseaudio::getPortIcon() const { - std::vector ports = { - "headphones", - "speaker", - "hdmi", - "headset", - "handsfree", - "portable", - "car", - "hifi", - "phone", - }; std::string nameLC = port_name_; std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower); for (auto const& port : ports) {