From 11a644548b3f80cb9b2b2be7f4b2414937d4bc7d Mon Sep 17 00:00:00 2001 From: patrick96 Date: Mon, 14 Mar 2022 22:36:35 +0100 Subject: [PATCH] builder: Use unordered_set for attribute activations --- include/components/builder.hpp | 3 ++- src/components/builder.cpp | 14 +++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/components/builder.hpp b/include/components/builder.hpp index 2f5a6384..b5f98e78 100644 --- a/include/components/builder.hpp +++ b/include/components/builder.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "common.hpp" #include "components/types.hpp" @@ -62,7 +63,7 @@ class builder { string m_output; map m_tags{}; - map m_attrs{}; + std::unordered_set m_attrs{}; }; POLYBAR_NS_END diff --git a/src/components/builder.cpp b/src/components/builder.cpp index ec153d2d..8f66b14b 100644 --- a/src/components/builder.cpp +++ b/src/components/builder.cpp @@ -32,10 +32,6 @@ void builder::reset() { m_tags[syntaxtag::P] = 0; m_attrs.clear(); - m_attrs[attribute::NONE] = false; - m_attrs[attribute::UNDERLINE] = false; - m_attrs[attribute::OVERLINE] = false; - m_output.clear(); } @@ -411,11 +407,12 @@ void builder::tag_open(syntaxtag tag, const string& value) { * Insert directive to use given attribute unless already set */ void builder::tag_open(attribute attr) { - if (m_attrs[attr]) { + // Don't emit activation tag if the attribute is already activated + if (m_attrs.count(attr) != 0) { return; } - m_attrs[attr] = true; + m_attrs.insert(attr); switch (attr) { case attribute::UNDERLINE: @@ -467,12 +464,11 @@ void builder::tag_close(syntaxtag tag) { * Insert directive to remove given attribute if set */ void builder::tag_close(attribute attr) { - if (!m_attrs[attr]) { + // Don't close activation tag if it wasn't activated + if (m_attrs.erase(attr) == 0) { return; } - m_attrs[attr] = false; - switch (attr) { case attribute::UNDERLINE: append("%{-u}");