Skip to content

Commit

Permalink
[php7] correctly detect write context to optimize more cases of array…
Browse files Browse the repository at this point in the history
… access
  • Loading branch information
RealyUniqueName committed Feb 1, 2017
1 parent c9b7fac commit dcb5cc2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion extra/haxelib_src
29 changes: 24 additions & 5 deletions src/generators/genphp7.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,21 @@ class virtual type_builder ctx wrapper =
match self#parent_expr with
| Some { eexpr = TCall _ } -> true
| _ -> false
(**
Check if currently generated expression is located in a left part of assignment.
*)
method private is_in_write_context =
let rec traverse current parents =
match parents with
| { eexpr = TBinop(OpAssign, left_expr, _) } :: _
| { eexpr = TBinop(OpAssignOp _, left_expr, _) } :: _ -> left_expr == current
| { eexpr = TUnop(op, _, _) } :: _ -> is_modifying_unop op
| [] -> false
| parent :: rest -> traverse parent rest
in
match expr_hierarchy with
| current :: parents -> traverse current parents
| _ -> false
(**
Position of currently generated code in source hx files
*)
Expand Down Expand Up @@ -1774,19 +1789,23 @@ class virtual type_builder ctx wrapper =
self#write_expr target;
write_index "[" "]"
in
let write_depending_on e =
(*let write_depending_on e =
match (reveal_expr e).eexpr with
| TArray (t, i) when t == target ->
write_normal_access ()
| _ ->
write_fast_access ()
in
in*)
match follow target.etype with
| TInst ({ cl_path = path }, _) when path = array_type_path ->
(match self#parent_expr with
if self#is_in_write_context then
write_normal_access()
else
write_fast_access()
(*(match self#parent_expr with
| None -> write_fast_access ()
| Some expr ->
match (reveal_expr expr).eexpr with
match expr.eexpr with
| TUnop (op, _, e) when is_modifying_unop op ->
write_depending_on e
| TBinop (OpAssign, e, _)
Expand All @@ -1796,7 +1815,7 @@ class virtual type_builder ctx wrapper =
write_depending_on e
| _ ->
write_fast_access ()
)
)*)
| _ ->
write_normal_access ()
(**
Expand Down

0 comments on commit dcb5cc2

Please sign in to comment.