From f828eae3eaca02c9659d63cbcab65c9dd8e13869 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Thu, 14 May 2015 08:01:03 -0700 Subject: Implement xml_node::attribute with a hint Extra argument 'hint' is used to start the attribute lookup; if the attribute is not found the lookup is restarted from the beginning of the attriubte list. This allows to optimize attribute lookups if you need to get many attributes from the node and can make assumptions about the likely ordering. The code is correct regardless of the order, but it is faster than using vanilla lookups if the order matches the calling order. Fixes #30. --- tests/test_dom_traverse.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/test_dom_traverse.cpp') diff --git a/tests/test_dom_traverse.cpp b/tests/test_dom_traverse.cpp index e4b8c44..8f96d93 100644 --- a/tests/test_dom_traverse.cpp +++ b/tests/test_dom_traverse.cpp @@ -1130,3 +1130,24 @@ TEST_XML(dom_ranged_for, "35 CHECK(index == 5); } #endif + +TEST_XML(dom_node_attribute_hinted, "") +{ + xml_node node = doc.first_child(); + xml_attribute attr1 = node.attribute(STR("attr1")); + xml_attribute attr2 = node.attribute(STR("attr2")); + xml_attribute attr3 = node.attribute(STR("attr3")); + + xml_attribute hint; + CHECK(!xml_node().attribute(STR("test"), hint) && !hint); + + CHECK(node.attribute(STR("attr2"), hint) == attr2 && hint == attr3); + CHECK(node.attribute(STR("attr3"), hint) == attr3 && !hint); + + CHECK(node.attribute(STR("attr1"), hint) == attr1 && hint == attr2); + CHECK(node.attribute(STR("attr2"), hint) == attr2 && hint == attr3); + CHECK(node.attribute(STR("attr1"), hint) == attr1 && hint == attr2); + CHECK(node.attribute(STR("attr1"), hint) == attr1 && hint == attr2); + + CHECK(!node.attribute(STR("attr"), hint) && hint == attr2); +} \ No newline at end of file -- cgit v1.2.3