Library.merge/OrdList.union: optimize the important special case where the tables coincide -- NOTE: this changes both the operational behaviour and the result for non-standard eq/ord notion;
--- a/src/Pure/General/ord_list.ML Wed Mar 18 19:11:26 2009 +0100
+++ b/src/Pure/General/ord_list.ML Wed Mar 18 20:03:01 2009 +0100
@@ -85,7 +85,7 @@
LESS => x :: handle_same (unio xs) lst2
| EQUAL => y :: unio xs ys
| GREATER => y :: unio lst1 ys);
- in handle_same (unio list1) list2 end;
+ in if pointer_eq (list1, list2) then list1 else handle_same (unio list1) list2 end;
(*intersection: filter second list for elements present in first list*)
nonfix inter;
--- a/src/Pure/library.ML Wed Mar 18 19:11:26 2009 +0100
+++ b/src/Pure/library.ML Wed Mar 18 20:03:01 2009 +0100
@@ -817,8 +817,10 @@
fun subtract eq = fold (remove eq);
-fun merge _ ([], ys) = ys
- | merge eq (xs, ys) = fold_rev (insert eq) ys xs;
+fun merge eq (xs, ys) =
+ if pointer_eq (xs, ys) then xs
+ else if null xs then ys
+ else fold_rev (insert eq) ys xs;
(* old-style infixes *)