From 39729290df0c837adca574626117267158483dd3 Mon Sep 17 00:00:00 2001 From: Charles Dang Date: Sun, 15 Sep 2024 17:28:15 -0400 Subject: [PATCH] GUI2: optimize create_widget_builder No need for all this config searching... there's only one tag! --- src/gui/core/window_builder.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/gui/core/window_builder.cpp b/src/gui/core/window_builder.cpp index a6e765a207e..ef2765764b9 100644 --- a/src/gui/core/window_builder.cpp +++ b/src/gui/core/window_builder.cpp @@ -76,23 +76,23 @@ builder_widget::builder_widget(const config& cfg) builder_widget_ptr create_widget_builder(const config& cfg) { - config::const_all_children_itors children = cfg.all_children_range(); - VALIDATE(children.size() == 1, "Grid cell does not have exactly 1 child."); + VALIDATE(cfg.all_children_count() == 1, "Grid cell does not have exactly 1 child."); + auto [widget_key, widget_cfg] = *cfg.ordered_begin(); - if(const auto grid = cfg.optional_child("grid")) { - return std::make_shared(grid.value()); + if(widget_key == "grid") { + return std::make_shared(widget_cfg); } - if(const auto instance = cfg.optional_child("instance")) { - return std::make_shared(instance.value()); + if(widget_key == "instance") { + return std::make_shared(widget_cfg); } - if(const auto pane = cfg.optional_child("pane")) { - return std::make_shared(pane.value()); + if(widget_key == "pane") { + return std::make_shared(widget_cfg); } - if(const auto viewport = cfg.optional_child("viewport")) { - return std::make_shared(viewport.value()); + if(widget_key == "viewport") { + return std::make_shared(widget_cfg); } for(const auto& [type, builder] : widget_builder_lookup()) { @@ -100,8 +100,8 @@ builder_widget_ptr create_widget_builder(const config& cfg) continue; } - if(const auto c = cfg.optional_child(type)) { - return builder(c.value()); + if(widget_key == type) { + return builder(widget_cfg); } } @@ -109,7 +109,7 @@ builder_widget_ptr create_widget_builder(const config& cfg) // // To fix this: add your new widget to source-lists/libwesnoth_widgets and rebuild. - FAIL("Unknown widget type " + cfg.ordered_begin()->key); + FAIL("Unknown widget type " + widget_key); } std::unique_ptr build_single_widget_instance_helper(const std::string& type, const config& cfg)