Switch to string views.

This commit is contained in:
Dario 2025-01-16 20:34:49 -03:00 committed by Mr-Wiseguy
parent 3fa66680d2
commit aa6418ba42
2 changed files with 8 additions and 8 deletions

View File

@ -157,15 +157,15 @@ void Element::clear_children() {
children.clear();
}
void Element::add_style(Style *style, const std::list<std::string> &style_names) {
for (const std::string &style_name : style_names) {
void Element::add_style(Style *style, const std::initializer_list<std::string_view> &style_names) {
for (const std::string_view &style_name : style_names) {
style_name_index_map.emplace(style_name, styles.size());
}
styles.emplace_back(style);
uint32_t initial_style_counter = style_names.size();
for (const std::string &style_name : style_names) {
for (const std::string_view &style_name : style_names) {
if (style_active_set.find(style_name) != style_active_set.end()) {
initial_style_counter--;
}
@ -184,7 +184,7 @@ void Element::set_text(const std::string &text) {
base->SetInnerRML(text);
}
void Element::set_style_enabled(const std::string &style_name, bool enable) {
void Element::set_style_enabled(const std::string_view &style_name, bool enable) {
if (enable && style_active_set.find(style_name) == style_active_set.end()) {
// Style was disabled and will be enabled.
style_active_set.emplace(style_name);

View File

@ -11,8 +11,8 @@ class Element : public Style, public Rml::EventListener {
private:
std::vector<Style *> styles;
std::vector<uint32_t> styles_counter;
std::unordered_set<std::string> style_active_set;
std::unordered_multimap<std::string, uint32_t> style_name_index_map;
std::unordered_set<std::string_view> style_active_set;
std::unordered_multimap<std::string_view, uint32_t> style_name_index_map;
void add_child(Element *child);
void register_event_listeners(uint32_t events_enabled);
@ -44,10 +44,10 @@ public:
Element(Element *parent, uint32_t events_enabled = 0, Rml::String base_class = "div");
virtual ~Element();
void clear_children();
void add_style(Style *style, const std::list<std::string> &style_names);
void add_style(Style *style, const std::initializer_list<std::string_view> &style_names);
void set_enabled(bool enabled);
void set_text(const std::string &text);
void set_style_enabled(const std::string &style_name, bool enabled);
void set_style_enabled(const std::string_view &style_name, bool enabled);
};
} // namespace recompui