Some more optimisations
[SXSI/xpathcomp.git] / tree.ml
diff --git a/tree.ml b/tree.ml
index 20f0505..1ed56b2 100644 (file)
--- a/tree.ml
+++ b/tree.ml
@@ -106,22 +106,28 @@ type t = { doc : tree;
         }
 
 let text_size t = text_size t.doc
+module MemUnion = Hashtbl.Make (struct 
+      type t = Ptset.Int.t*Ptset.Int.t
+      let equal (x,y) (z,t) = (Ptset.Int.equal x z)&&(Ptset.Int.equal y t)
+      let equal a b = equal a b || equal b a
+      let hash (x,y) =   (* commutative hash *)
+       let x = Ptset.Int.hash x 
+       and y = Ptset.Int.hash y 
+       in
+         if x < y then HASHINT2(x,y) else HASHINT2(y,x)
+    end)
 
 let collect_tags tree =
-  let h_union = Hashtbl.create 511 in
+  let h_union = MemUnion.create BIG_H_SIZE in
   let pt_cup s1 s2 =
-    (* special case, since this is a union we want hash(s1,s2) = hash(s2,s1) *)
-    let x = Ptset.Int.hash s1 
-    and y = Ptset.Int.hash s2 in
-    let h = if x < y then HASHINT2(x,y) else HASHINT2(y,x)in
       try
-       Hashtbl.find h_union h
+       MemUnion.find h_union (s1,s2)
       with
        | Not_found -> let s = Ptset.Int.union s1 s2
          in
-           Hashtbl.add h_union h s;s
+           MemUnion.add h_union (s1,s2) s;s
   in    
-  let h_add = Hashtbl.create 511 in
+  let h_add = Hashtbl.create BIG_H_SIZE in
   let pt_add t s = 
     let k = HASHINT2(Tag.hash t,Ptset.Int.hash s) in
       try
@@ -130,7 +136,7 @@ let collect_tags tree =
       | Not_found -> let r = Ptset.Int.add t s in
          Hashtbl.add h_add k r;r
   in
-  let h = Hashtbl.create 511 in
+  let h = Hashtbl.create BIG_H_SIZE in
   let sing = Ptset.Int.singleton Tag.pcdata in    
   let update t sb sa =
     let sbelow,safter =