builder: Use unordered_set for attribute activations

This commit is contained in:
patrick96 2022-03-14 22:36:35 +01:00 committed by Patrick Ziegler
parent 7fb5f165db
commit 11a644548b
2 changed files with 7 additions and 10 deletions

View File

@ -1,6 +1,7 @@
#pragma once
#include <map>
#include <unordered_set>
#include "common.hpp"
#include "components/types.hpp"
@ -62,7 +63,7 @@ class builder {
string m_output;
map<tags::syntaxtag, int> m_tags{};
map<tags::attribute, bool> m_attrs{};
std::unordered_set<tags::attribute> m_attrs{};
};
POLYBAR_NS_END

View File

@ -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}");