@@ -250,7 +250,7 @@ impl Optimizer<'_> {
250
250
} ) => arg. is_lit ( ) ,
251
251
Expr :: This ( ..) => usage. is_fn_local ,
252
252
Expr :: Arrow ( arr) => {
253
- is_arrow_simple_enough_for_copy ( arr)
253
+ is_arrow_simple_enough_for_copy ( arr) . map_or ( false , |cost| cost <= 8 )
254
254
&& !( usage. property_mutation_count > 0
255
255
|| usage. executed_multiple_time
256
256
|| usage. used_as_arg && ref_count > 1 )
@@ -906,9 +906,9 @@ impl Optimizer<'_> {
906
906
}
907
907
}
908
908
909
- fn is_arrow_simple_enough_for_copy ( e : & ArrowExpr ) -> bool {
909
+ fn is_arrow_simple_enough_for_copy ( e : & ArrowExpr ) -> Option < u8 > {
910
910
if e. is_async {
911
- return false ;
911
+ return None ;
912
912
}
913
913
914
914
match & * e. body {
@@ -917,32 +917,34 @@ fn is_arrow_simple_enough_for_copy(e: &ArrowExpr) -> bool {
917
917
}
918
918
}
919
919
920
- fn is_arrow_body_simple_enough_for_copy ( e : & Expr ) -> bool {
920
+ fn is_arrow_body_simple_enough_for_copy ( e : & Expr ) -> Option < u8 > {
921
921
match e {
922
- Expr :: Ident ( ..) | Expr :: Lit ( ..) => return true ,
923
- Expr :: Member ( MemberExpr { prop, .. } ) if !prop. is_computed ( ) => return true ,
924
- Expr :: Unary ( u) => return is_arrow_body_simple_enough_for_copy ( & u. arg ) ,
922
+ Expr :: Ident ( ..) | Expr :: Lit ( ..) => return Some ( 1 ) ,
923
+ Expr :: Member ( MemberExpr { prop, .. } ) if !prop. is_computed ( ) => return Some ( 3 ) ,
924
+ Expr :: Unary ( u) => return Some ( is_arrow_body_simple_enough_for_copy ( & u. arg ) ? + 1 ) ,
925
925
926
926
Expr :: Bin ( b) => {
927
- return is_arrow_body_simple_enough_for_copy ( & b. left )
928
- && is_arrow_body_simple_enough_for_copy ( & b. right )
927
+ return Some (
928
+ is_arrow_body_simple_enough_for_copy ( & b. left ) ?
929
+ + is_arrow_body_simple_enough_for_copy ( & b. right ) ?
930
+ + 2 ,
931
+ )
929
932
}
930
933
_ => { }
931
934
}
932
935
933
- false
936
+ None
934
937
}
935
938
936
- fn is_block_stmt_of_fn_simple_enough_for_copy ( b : & BlockStmt ) -> bool {
939
+ fn is_block_stmt_of_fn_simple_enough_for_copy ( b : & BlockStmt ) -> Option < u8 > {
937
940
if b. stmts . len ( ) == 1 {
938
941
if let Stmt :: Return ( ret) = & b. stmts [ 0 ] {
939
942
return ret
940
943
. arg
941
944
. as_deref ( )
942
- . map ( is_arrow_body_simple_enough_for_copy)
943
- . unwrap_or ( true ) ;
945
+ . map_or ( Some ( 0 ) , is_arrow_body_simple_enough_for_copy) ;
944
946
}
945
947
}
946
948
947
- false
949
+ None
948
950
}
0 commit comments