srctree

Robin Linden parent 803ad523 4c15e72b
dom: Drop use of reference_wrapper in nodes_by_xpath

This hasn't really helped us, we have a lot of CI helping us detect theproblems this would have prevented, and it made adapting this to workwith other node types more annoying.

inlinesplit
dom/dom.cpp added: 8, removed: 10, total 0
@@ -44,8 +44,8 @@ std::string to_string(Document const &document) {
 
// https://developer.mozilla.org/en-US/docs/Web/XPath
// https://en.wikipedia.org/wiki/XPath
std::vector<Element const *> nodes_by_xpath(std::reference_wrapper<Element const> root, std::string_view xpath) {
std::vector<Element const *> next_search{&root.get()};
std::vector<Element const *> nodes_by_xpath(Element const &root, std::string_view xpath) {
std::vector<Element const *> next_search{&root};
std::vector<Element const *> searching{};
std::vector<Element const *> goal_nodes{};
 
 
dom/dom.h added: 8, removed: 10, total 0
@@ -5,7 +5,6 @@
#ifndef DOM_DOM_H_
#define DOM_DOM_H_
 
#include <functional>
#include <map>
#include <string>
#include <string_view>
@@ -40,8 +39,7 @@ struct Document {
[[nodiscard]] bool operator==(Document const &) const = default;
};
 
// reference_wrapper to ensure that the argument isn't a temporary since we return pointers into it.
std::vector<Element const *> nodes_by_xpath(std::reference_wrapper<Element const>, std::string_view);
std::vector<Element const *> nodes_by_xpath(Element const &, std::string_view);
 
std::string to_string(Document const &node);
 
 
dom/dom_test.cpp added: 8, removed: 10, total 0
@@ -21,8 +21,8 @@ dom::Node create_element_node(std::string_view name, dom::AttrMap attrs, std::ve
return dom::Element{std::string{name}, std::move(attrs), std::move(children)};
}
 
std::vector<dom::Element const *> nodes_by_xpath(std::reference_wrapper<dom::Node const> root, std::string_view xpath) {
return nodes_by_xpath(std::get<dom::Element>(root.get()), xpath);
std::vector<dom::Element const *> nodes_by_xpath(dom::Node const &root, std::string_view xpath) {
return nodes_by_xpath(std::get<dom::Element>(root), xpath);
}
} // namespace