diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2003-06-23 12:45:42 +0000 |
---|---|---|
committer | Xavier Leroy <xavier.leroy@inria.fr> | 2003-06-23 12:45:42 +0000 |
commit | d8e2ca67bc8a1980e8343cfc81791ae50e1c7f47 (patch) | |
tree | b825502aa55c909f478ccf47c60b9c6dea1d74d6 | |
parent | af6f4447aeb7fc6af0fc8a59f7dfade2d8adf359 (diff) |
Optimisation du cas tableau constant
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5612 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r-- | bytecomp/translcore.ml | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/bytecomp/translcore.ml b/bytecomp/translcore.ml index bff8a5dcc..a47a0c915 100644 --- a/bytecomp/translcore.ml +++ b/bytecomp/translcore.ml @@ -596,7 +596,24 @@ let rec transl_exp e = | Record_float -> Psetfloatfield lbl.lbl_pos in Lprim(access, [transl_exp arg; transl_exp newval]) | Texp_array expr_list -> - Lprim(Pmakearray (array_kind e), transl_list expr_list) + let kind = array_kind e in + let ll = transl_list expr_list in + begin try + (* Deactivate constant optimization if array is small enough *) + if List.length ll <= 5 then raise Not_constant; + let cl = List.map extract_constant ll in + let master = + match kind with + | Paddrarray | Pintarray -> + Lconst(Const_block(0, cl)) + | Pfloatarray -> + Lconst(Const_float_array(List.map extract_float cl)) + | Pgenarray -> + assert false in + Lprim(Pccall prim_obj_dup, [master]) + with Not_constant -> + Lprim(Pmakearray kind, ll) + end | Texp_ifthenelse(cond, ifso, Some ifnot) -> Lifthenelse(transl_exp cond, event_before ifso (transl_exp ifso), |