summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-16 03:46:42 +0000
committerArseny Kapoulkine <arseny.kapoulkine@gmail.com>2014-10-16 03:46:42 +0000
commit5da51dff270f430701b26428c9422f21e0ea4c9c (patch)
treead2e321fd97417a357cab55997e35e0d188b229b /tests
parent883031fb45cf0f86cd36b20ad4762da58dd6126c (diff)
XPath: Optimize attribute axis lookup
When looking for an attribute by name, finding the first attribute means we can stop looking since attribute names are unique. This makes some queries faster by 40%. Another very common pattern in XPath queries is finding an attribute with a specified value using a predicate (@name = 'value'). While we perform an optimal amount of traversal in that case, there is a substantial overhead with evaluating the nodes, saving and restoring the stack state, pushing the attribute node into a set, etc. Detecting this pattern allows us to use optimized code, resulting in up to 2x speedup for some queries. git-svn-id: https://pugixml.googlecode.com/svn/trunk@1061 99668b35-9821-0410-8761-19e4c4f06640
Diffstat (limited to 'tests')
-rw-r--r--tests/test_xpath_paths.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/test_xpath_paths.cpp b/tests/test_xpath_paths.cpp
index 43096bc..4528acd 100644
--- a/tests/test_xpath_paths.cpp
+++ b/tests/test_xpath_paths.cpp
@@ -561,4 +561,22 @@ TEST_XML(xpath_paths_unsorted_child, "<node><foo><bar/></foo><node><foo><bar/></
CHECK(ns[2] == nss[1]);
}
+TEST_XML(xpath_paths_optimize_compare_attribute, "<node id='1' /><node id='2' /><node xmlns='3' />")
+{
+ CHECK_XPATH_NODESET(doc, STR("node[@id = '1']")) % 2;
+ CHECK_XPATH_NODESET(doc, STR("node[@id = '2']")) % 4;
+ CHECK_XPATH_NODESET(doc, STR("node[@id = 2]")) % 4;
+ CHECK_XPATH_NODESET(doc, STR("node[@id[. > 3] = '2']"));
+ CHECK_XPATH_NODESET(doc, STR("node['1' = @id]")) % 2;
+
+ xpath_variable_set set;
+ set.set(STR("var1"), STR("2"));
+ set.set(STR("var2"), 2.0);
+
+ CHECK_XPATH_NODESET_VAR(doc, STR("node[@id = $var1]"), &set) % 4;
+ CHECK_XPATH_NODESET_VAR(doc, STR("node[@id = $var2]"), &set) % 4;
+
+ CHECK_XPATH_NODESET(doc, STR("node[@xmlns = '3']"));
+}
+
#endif