aboutsummaryrefslogtreecommitdiffhomepage
path: root/kernel/vars.ml
diff options
context:
space:
mode:
authorGravatar ppedrot <ppedrot@85f007b7-540e-0410-9357-904b9bb8a0f7>2013-10-23 15:15:21 +0000
committerGravatar ppedrot <ppedrot@85f007b7-540e-0410-9357-904b9bb8a0f7>2013-10-23 15:15:21 +0000
commit71a463426a9cf552ba78b28708ea860adc59e553 (patch)
tree34a9a1c7454ed60109df0efbe4f8626a548a7596 /kernel/vars.ml
parent5f8ce72b29f4a4620ce46895f2e563b2fd85f24b (diff)
Optimizing Vars.replace_vars
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/coq/trunk@16916 85f007b7-540e-0410-9357-904b9bb8a0f7
Diffstat (limited to 'kernel/vars.ml')
-rw-r--r--kernel/vars.ml19
1 files changed, 12 insertions, 7 deletions
diff --git a/kernel/vars.ml b/kernel/vars.ml
index c7ec69c87..123c96d6d 100644
--- a/kernel/vars.ml
+++ b/kernel/vars.ml
@@ -155,20 +155,25 @@ let subst1_named_decl lam = substl_named_decl [lam]
let rec thin_val = function
| [] -> []
- | s :: tl ->
- let id, { sit = c } = s in
+ | (id, c) :: tl ->
match Constr.kind c with
- | Constr.Var v -> if Id.equal id v then thin_val tl else s::(thin_val tl)
- | _ -> s :: (thin_val tl)
+ | Constr.Var v ->
+ if Id.equal id v then thin_val tl
+ else (id, make_substituend c) :: (thin_val tl)
+ | _ -> (id, make_substituend c) :: (thin_val tl)
+
+let rec find_var id = function
+| [] -> raise Not_found
+| (idc, c) :: subst ->
+ if Id.equal id idc then c
+ else find_var id subst
(* (replace_vars sigma M) applies substitution sigma to term M *)
let replace_vars var_alist =
- let var_alist =
- List.map (fun (str,c) -> (str,make_substituend c)) var_alist in
let var_alist = thin_val var_alist in
let rec substrec n c = match Constr.kind c with
| Constr.Var x ->
- (try lift_substituend n (List.assoc x var_alist)
+ (try lift_substituend n (find_var x var_alist)
with Not_found -> c)
| _ -> Constr.map_with_binders succ substrec n c
in