Skip to content

Commit c95c6b5

Browse files
committed
refactoring
1 parent 321d719 commit c95c6b5

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

jscomp/core/lam_compile.ml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ let default_action ~saturated failaction =
154154
if saturated then Complete
155155
else Default x
156156

157+
let get_const_name i (sw_names : Lambda.switch_names option) =
158+
match sw_names with
159+
| None -> None
160+
| Some {consts} -> Some consts.(i)
161+
162+
let get_block_name i (sw_names : Lambda.switch_names option) =
163+
match sw_names with
164+
| None -> None
165+
| Some {blocks} -> Some blocks.(i)
166+
157167
let no_effects_const = lazy true
158168
(* let has_effects_const = lazy false *)
159169

@@ -599,12 +609,8 @@ and compile_switch
599609
default_action ~saturated:sw_consts_full sw_failaction in
600610
let sw_blocks_default =
601611
default_action ~saturated:sw_blocks_full sw_failaction in
602-
603-
let get_name is_const i =
604-
match sw_names with
605-
| None -> None
606-
| Some {blocks; consts} ->
607-
Some (if is_const then consts.(i) else blocks.(i)) in
612+
let get_const_name i = get_const_name i sw_names in
613+
let get_block_name i = get_block_name i sw_names in
608614
let compile_whole (cxt : Lam_compile_context.t ) =
609615
match compile_lambda
610616
{cxt with continuation = NeedValue Not_tail}
@@ -614,20 +620,20 @@ and compile_switch
614620
| { block; value = Some e } ->
615621
block @
616622
(if sw_consts_full && sw_consts = [] then
617-
compile_cases cxt (E.tag e) sw_blocks sw_blocks_default (get_name false)
623+
compile_cases cxt (E.tag e) sw_blocks sw_blocks_default get_block_name
618624
else if sw_blocks_full && sw_blocks = [] then
619-
compile_cases cxt e sw_consts sw_num_default (get_name true)
625+
compile_cases cxt e sw_consts sw_num_default get_const_name
620626
else
621627
(* [e] will be used twice *)
622628
let dispatch e =
623629
S.if_
624630
(E.is_type_number e )
625-
(compile_cases cxt e sw_consts sw_num_default (get_name true)
631+
(compile_cases cxt e sw_consts sw_num_default get_const_name
626632
)
627633
(* default still needed, could simplified*)
628634
~else_:
629635
(compile_cases cxt (E.tag e ) sw_blocks
630-
sw_blocks_default (get_name false)) in
636+
sw_blocks_default get_block_name) in
631637
match e.expression_desc with
632638
| J.Var _ -> [ dispatch e]
633639
| _ ->

0 commit comments

Comments
 (0)