From f3e4e04de7633a1ec4a86f7b951daa19c55711da Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 24 Mar 2025 11:46:26 +0100 Subject: [PATCH] base: don't copy Xml_node Issue #5411 --- repos/base/include/util/list_model.h | 2 +- repos/base/src/lib/base/root_proxy.cc | 10 +++++----- repos/base/src/test/xml_node/test.cc | 23 +++++++++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/repos/base/include/util/list_model.h b/repos/base/include/util/list_model.h index a3598d297e..b1fc3b663a 100644 --- a/repos/base/include/util/list_model.h +++ b/repos/base/include/util/list_model.h @@ -166,7 +166,7 @@ void Genode::List_model::update_from_xml(Xml_node const &node, ELEM *last_updated = nullptr; /* used for appending to 'updated_list' */ - node.for_each_sub_node([&] (Xml_node sub_node) { + node.for_each_sub_node([&] (Xml_node const &sub_node) { /* skip XML nodes that are unrelated to the data model */ if (!ELEM::type_matches(sub_node)) diff --git a/repos/base/src/lib/base/root_proxy.cc b/repos/base/src/lib/base/root_proxy.cc index 6edd08deda..45e9ff1847 100644 --- a/repos/base/src/lib/base/root_proxy.cc +++ b/repos/base/src/lib/base/root_proxy.cc @@ -126,7 +126,7 @@ namespace { Tslab _session_slab { &_sliced_heap }; - void _handle_session_request(Xml_node, char const *type); + void _handle_session_request(Xml_node const &, char const *type); void _handle_session_requests(); Service_registry _services { }; @@ -152,7 +152,7 @@ namespace { } -void Root_proxy::_handle_session_request(Xml_node request, char const *type) +void Root_proxy::_handle_session_request(Xml_node const &request, char const *type) { if (!request.has_attribute("id") || !request.has_type(type)) return; @@ -235,13 +235,13 @@ void Root_proxy::_handle_session_requests() * step. If we served the new client before the old one, it would look like * an attempt to create a second session. */ - requests.for_each_sub_node([&] (Xml_node request) { + requests.for_each_sub_node([&] (Xml_node const &request) { _handle_session_request(request, "upgrade"); }); - requests.for_each_sub_node([&] (Xml_node request) { + requests.for_each_sub_node([&] (Xml_node const &request) { _handle_session_request(request, "close"); }); - requests.for_each_sub_node([&] (Xml_node request) { + requests.for_each_sub_node([&] (Xml_node const &request) { _handle_session_request(request, "create"); }); } diff --git a/repos/base/src/test/xml_node/test.cc b/repos/base/src/test/xml_node/test.cc index 2963aaa380..4841d77bdb 100644 --- a/repos/base/src/test/xml_node/test.cc +++ b/repos/base/src/test/xml_node/test.cc @@ -241,7 +241,7 @@ struct Formatted_xml_attribute /** * Print attributes of XML node */ -static void print_xml_attr_info(Output &output, Xml_node node, int indent = 0) +static void print_xml_attr_info(Output &output, Xml_node const &node, int indent = 0) { node.for_each_attribute([&] (Xml_attribute const &a) { print(output, Formatted_xml_attribute(a, indent), "\n"); }); @@ -256,10 +256,10 @@ static void print_xml_attr_info(Output &output, Xml_node node, int indent = 0) */ struct Formatted_xml_node { - Xml_node const _node; - unsigned const _indent; + Xml_node const &_node; + unsigned const _indent; - Formatted_xml_node(Xml_node node, unsigned indent = 0) + Formatted_xml_node(Xml_node const &node, unsigned indent = 0) : _node(node), _indent(indent) { } void print(Output &output) const @@ -295,14 +295,17 @@ struct Formatted_xml_node /** * Print content of sub node with specified type */ -static void log_key(Xml_node node, char const *key) +static void log_key(Xml_node const &node, char const *key) { try { - Xml_node sub_node = node.sub_node(key); - sub_node.with_raw_content([&] (char const *start, size_t length) { - log("content of sub node \"", key, "\" = \"", Cstring(start, length), "\""); }); - } catch (Xml_node::Nonexistent_sub_node) { - log("sub node \"", key, "\" is not defined\n"); + node.with_sub_node(key, + [&] (Xml_node const &sub_node) { + sub_node.with_raw_content([&] (char const *start, size_t length) { + log("content of sub node \"", key, "\" = \"", Cstring(start, length), "\""); }); + }, + [&] { + log("sub node \"", key, "\" is not defined\n"); + }); } catch (Xml_node::Invalid_syntax) { log("invalid syntax of node \"", key, "\""); }