Skip to content

Commit 2362ced

Browse files
committed
Array-based List type
1 parent 155bd5e commit 2362ced

File tree

2 files changed

+389
-447
lines changed

2 files changed

+389
-447
lines changed

src/Fable.Transforms/Fable2Babel.fs

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -932,24 +932,36 @@ module Util =
932932
// | Fable.NewList (headAndTail, _) when List.contains "FABLE_LIBRARY" com.Options.Define ->
933933
// makeList com ctx r headAndTail
934934
// Optimization for bundle size: compile list literals as List.ofArray
935+
| Replacements.ListLiteral(exprs, t) ->
936+
[|List.rev exprs |> makeArray com ctx|]
937+
|> libCall com ctx r "List" "newList"
938+
// match exprs with
939+
// | [] -> libCall com ctx r "List" "empty" [||]
940+
// | [TransformExpr com ctx expr] -> libCall com ctx r "List" "singleton" [|expr|]
941+
// | exprs -> [|makeArray com ctx exprs|] |> libCall com ctx r "List" "ofArray"
935942
| Fable.NewList (headAndTail, _) ->
936-
let rec getItems acc = function
937-
| None -> List.rev acc, None
938-
| Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
939-
| Some(head, tail) -> List.rev (head::acc), Some tail
940-
match getItems [] headAndTail with
941-
| [], None ->
942-
libCall com ctx r "List" "empty" [||]
943-
| [TransformExpr com ctx expr], None ->
944-
libCall com ctx r "List" "singleton" [|expr|]
945-
| exprs, None ->
946-
[|makeArray com ctx exprs|]
947-
|> libCall com ctx r "List" "ofArray"
948-
| [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
943+
match headAndTail with
944+
| None -> libCall com ctx r "List" "empty" [||]
945+
| Some(TransformExpr com ctx head, TransformExpr com ctx tail) ->
949946
libCall com ctx r "List" "cons" [|head; tail|]
950-
| exprs, Some(TransformExpr com ctx tail) ->
951-
[|makeArray com ctx exprs; tail|]
952-
|> libCall com ctx r "List" "ofArrayWithTail"
947+
948+
// let rec getItems acc = function
949+
// | None -> List.rev acc, None
950+
// | Some(head, Fable.Value(Fable.NewList(tail, _),_)) -> getItems (head::acc) tail
951+
// | Some(head, tail) -> List.rev (head::acc), Some tail
952+
// match getItems [] headAndTail with
953+
// | [], None ->
954+
// libCall com ctx r "List" "empty" [||]
955+
// | [TransformExpr com ctx expr], None ->
956+
// libCall com ctx r "List" "singleton" [|expr|]
957+
// | exprs, None ->
958+
// [|makeArray com ctx exprs|]
959+
// |> libCall com ctx r "List" "ofArray"
960+
// | [TransformExpr com ctx head], Some(TransformExpr com ctx tail) ->
961+
// libCall com ctx r "List" "cons" [|head; tail|]
962+
// | exprs, Some(TransformExpr com ctx tail) ->
963+
// [|makeArray com ctx exprs; tail|]
964+
// |> libCall com ctx r "List" "ofArrayWithTail"
953965
| Fable.NewOption (value, t) ->
954966
match value with
955967
| Some (TransformExpr com ctx e) ->

0 commit comments

Comments
 (0)