Revert "Optimize subtree_elements by calling find_close only once."
authorKim Nguyễn <kn@lri.fr>
Tue, 24 Apr 2012 14:14:17 +0000 (16:14 +0200)
committerKim Nguyễn <kn@lri.fr>
Tue, 24 Apr 2012 14:14:17 +0000 (16:14 +0200)
This reverts commit e9b536b9310b8a3df206a62df73651656a2ec3cb.
Return wrong results for the root node.

xml-tree.cpp

index 84d42e2..8c0386e 100644 (file)
@@ -344,18 +344,20 @@ xml_tree* xml_tree::load(int fd, char* name, bool load_tc, int sf)
 
 uint32_t xml_tree::subtree_elements(xml_tree::node_t x) const
 {
-  xml_tree::node_t fin = bp_find_close(par, x);
-  uint32_t size = (fin - x)/2;
+
+  uint32_t size = bp_subtree_size(par, x);
   if (x == root()){
     x = bp_first_child(par,x);
     size = size - 1;
   };
 
+  int s = x + 2*size - 1;
   int ntext =
-    tags->rank(xml_tree::PCDATA_OPEN_TAG_ID, fin) -
+    tags->rank(xml_tree::PCDATA_OPEN_TAG_ID, s) -
     tags->rank(xml_tree::PCDATA_OPEN_TAG_ID, x-1);
 
   size = size - ntext;
+  xml_tree::node_t fin = bp_find_close(par, x);
   xml_tree::node_t y = tags->select_next(xml_tree::ATTRIBUTE_OPEN_TAG_ID, x);
   while (y != xml_tree::NIL && y < fin){
     size -= subtree_size(y);