aboutsummaryrefslogtreecommitdiffhomepage
path: root/printing/printmod.ml
diff options
context:
space:
mode:
authorGravatar Pierre-Marie Pédrot <pierre-marie.pedrot@inria.fr>2017-09-09 21:47:17 +0200
committerGravatar Pierre-Marie Pédrot <pierre-marie.pedrot@inria.fr>2017-09-28 16:51:21 +0200
commitd28304f6ba18ad9527a63cd01b39a5ad27526845 (patch)
treeddd8c5d10f0d1e52c675e8e027053fac7f05f259 /printing/printmod.ml
parentb9740771e8113cb9e607793887be7a12587d0326 (diff)
Efficient fresh name generation relying on sets.
The old algorithm was relying on list membership, which is O(n). This was nefarious for terms with many binders. We use instead sets in O(log n).
Diffstat (limited to 'printing/printmod.ml')
-rw-r--r--printing/printmod.ml5
1 files changed, 3 insertions, 2 deletions
diff --git a/printing/printmod.ml b/printing/printmod.ml
index 219eafda4..755e905a7 100644
--- a/printing/printmod.ml
+++ b/printing/printmod.ml
@@ -64,9 +64,10 @@ let get_new_id locals id =
if not (Nametab.exists_module dir) then
id
else
- get_id (id::l) (Namegen.next_ident_away id l)
+ get_id (Id.Set.add id l) (Namegen.next_ident_away id l)
in
- get_id (List.map snd locals) id
+ let avoid = List.fold_left (fun accu (_, id) -> Id.Set.add id accu) Id.Set.empty locals in
+ get_id avoid id
(** Inductive declarations *)