Optimize subtree_elements by calling find_close only once.
authorKim Nguyễn <kn@lri.fr>
Tue, 24 Apr 2012 13:47:38 +0000 (15:47 +0200)
committerKim Nguyễn <kn@lri.fr>
Tue, 24 Apr 2012 13:47:38 +0000 (15:47 +0200)
xml-tree.cpp

index 8c0386e..84d42e2 100644 (file)
@@ -344,20 +344,18 @@ 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
 {
-
-  uint32_t size = bp_subtree_size(par, x);
+  xml_tree::node_t fin = bp_find_close(par, x);
+  uint32_t size = (fin - x)/2;
   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, s) -
+    tags->rank(xml_tree::PCDATA_OPEN_TAG_ID, fin) -
     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);