From: Claudio Sacerdoti Coen Date: Fri, 5 Sep 2003 17:33:04 +0000 (+0000) Subject: get_childNodes no longer used ==> major performance speed-up X-Git-Tag: v0_0_1~26 X-Git-Url: http://matita.cs.unibo.it/gitweb/?p=helm.git;a=commitdiff_plain;h=a9f9195de421375634346e0d55a7d06c7718488d get_childNodes no longer used ==> major performance speed-up --- diff --git a/helm/gTopLevel/xmlDiff.ml b/helm/gTopLevel/xmlDiff.ml index 307e02ac0..2b9806c44 100644 --- a/helm/gTopLevel/xmlDiff.ml +++ b/helm/gTopLevel/xmlDiff.ml @@ -97,6 +97,18 @@ prerr_endline ("@@@ find_mstylable_node salgo da " ^ match n#get_localName with highlighter ;; +let iter_children ~f (n:Gdome.node) = + let rec aux = + function + None -> () + | Some n -> + let sibling = n#get_nextSibling in + (f n) ; + aux sibling + in + aux n#get_firstChild +;; + let highlight_nodes ~xrefs (doc:Gdome.document) = let highlighted = ref [] in let rec aux (n:Gdome.element) = @@ -109,14 +121,10 @@ let highlight_nodes ~xrefs (doc:Gdome.document) = highlighted := (highlight_node ~color:"#00ff00"(* light green *) doc (n :> Gdome.node)):: !highlighted ; - let children = n#get_childNodes in - for i = 0 to children#get_length - 1 do - match children#item i with - None -> assert false - | Some n -> - if n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE then - aux (new Gdome.element_of_node n) - done + iter_children (n :> Gdome.node) + ~f:(function n -> + if n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE then + aux (new Gdome.element_of_node n)) in aux doc#get_documentElement ; !highlighted @@ -285,8 +293,10 @@ prerr_endline !debugs ; done | _,_ -> assert false end ; +(* debugging only let fchildren = f#get_childNodes in let tchildren = t#get_childNodes in +*) let rec dumb_diff = function [],[] -> () @@ -306,31 +316,33 @@ prerr_endline ("XML_DIFF: appendo i nodi residui " ^ String.concat ", " (List.ma prerr_endline ("XML_DIFF: cancello i nodi residui " ^ String.concat ", " (List.map (function n -> match n#get_localName with Some s -> s#to_string | None -> "_") tl1)) ; List.iter (function n -> ignore (f#removeChild n)) tl1 in - let node_list_of_nodeList nl = - let rec aux i = - match nl#item ~index:i with + let node_list_of_nodeList n = + let rec aux = + function None -> [] | Some n when n#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE or n#get_nodeType = GdomeNodeTypeT.TEXT_NODE -> - n::(aux (i+1)) + n::(aux n#get_nextSibling) | Some n -> prerr_endline ("XML_DIFF: mi sto perdendo i nodi di tipo " ^ string_of_int (Obj.magic n#get_nodeType)) ; - aux (i+1) + aux n#get_nextSibling in - aux 0 + aux n#get_firstChild in +(* debugging stuff only for i = 0 to fchildren#get_length - 1 do match fchildren#item i with None -> prerr_endline "EUREKA: ma siamo matti?" |Some n -> match n#get_nodeType with GdomeNodeTypeT.ATTRIBUTE_NODE -> prerr_endline "EUREKA attr" | GdomeNodeTypeT.CDATA_SECTION_NODE -> prerr_endline "EUREKA text" | GdomeNodeTypeT.DOCUMENT_FRAGMENT_NODE -> prerr_endline "EUREKA document fragment" | _ -> prerr_endline ("EUREKA " ^ string_of_int (Obj.magic n#get_nodeType)) done ; -prerr_endline("XML_DIFF: from ha " ^ string_of_int fchildren#get_length ^ " nodi, ovvero " ^ string_of_int (List.length (node_list_of_nodeList fchildren)) ^ " figli"); -prerr_endline("XML_DIFF: to ha " ^ string_of_int tchildren#get_length ^ " nodi, ovvero " ^ string_of_int (List.length (node_list_of_nodeList tchildren)) ^ " figli"); +prerr_endline("XML_DIFF: from ha " ^ string_of_int fchildren#get_length ^ " nodi, ovvero " ^ string_of_int (List.length (node_list_of_nodeList f)) ^ " figli"); +prerr_endline("XML_DIFF: to ha " ^ string_of_int tchildren#get_length ^ " nodi, ovvero " ^ string_of_int (List.length (node_list_of_nodeList t)) ^ " figli"); prerr_endline ("XML_DIFF: chiamo dumb_diff su " ^ String.concat ", " (List.map (function n -> match n#get_localName with Some s -> s#to_string | None -> "_") (node_list_of_nodeList fchildren)) ^ " e " ^ String.concat ", " (List.map (function n -> match n#get_localName with Some s -> s#to_string | None -> "_") (node_list_of_nodeList tchildren))) ; +*) dumb_diff - (node_list_of_nodeList fchildren, node_list_of_nodeList tchildren) + (node_list_of_nodeList f, node_list_of_nodeList t) | t1,t2,_,_,_,_ when (t1 = GdomeNodeTypeT.ELEMENT_NODE || t1 = GdomeNodeTypeT.TEXT_NODE) && (t2 = GdomeNodeTypeT.ELEMENT_NODE || t2 = GdomeNodeTypeT.TEXT_NODE) ->