1+ use thin_vec:: ThinVec ;
2+
13use super :: * ;
24use rustpython_compiler_core:: SourceFile ;
35
46pub ( super ) struct PositionalArguments {
57 pub range : TextRange ,
6- pub args : Box < [ ast:: Expr ] > ,
8+ pub args : ThinVec < ast:: Expr > ,
79}
810
911impl Node for PositionalArguments {
1012 fn ast_to_object ( self , vm : & VirtualMachine , source_file : & SourceFile ) -> PyObjectRef {
1113 let Self { args, range : _ } = self ;
12- BoxedSlice ( args) . ast_to_object ( vm, source_file)
14+ args. ast_to_object ( vm, source_file)
1315 }
1416
1517 fn ast_from_object (
1618 vm : & VirtualMachine ,
1719 source_file : & SourceFile ,
1820 object : PyObjectRef ,
1921 ) -> PyResult < Self > {
20- let args: BoxedSlice < _ > = Node :: ast_from_object ( vm, source_file, object) ?;
22+ let args: ThinVec < _ > = Node :: ast_from_object ( vm, source_file, object) ?;
2123 Ok ( Self {
22- args : args . 0 ,
24+ args,
2325 range : TextRange :: default ( ) , // TODO
2426 } )
2527 }
2628}
2729
2830pub ( super ) struct KeywordArguments {
2931 pub range : TextRange ,
30- pub keywords : Box < [ ast:: Keyword ] > ,
32+ pub keywords : ThinVec < ast:: Keyword > ,
3133}
3234
3335impl Node for KeywordArguments {
3436 fn ast_to_object ( self , vm : & VirtualMachine , source_file : & SourceFile ) -> PyObjectRef {
3537 let Self { keywords, range : _ } = self ;
3638 // TODO: use range
37- BoxedSlice ( keywords) . ast_to_object ( vm, source_file)
39+ keywords. ast_to_object ( vm, source_file)
3840 }
3941
4042 fn ast_from_object (
4143 vm : & VirtualMachine ,
4244 source_file : & SourceFile ,
4345 object : PyObjectRef ,
4446 ) -> PyResult < Self > {
45- let keywords: BoxedSlice < _ > = Node :: ast_from_object ( vm, source_file, object) ?;
47+ let keywords: ThinVec < _ > = Node :: ast_from_object ( vm, source_file, object) ?;
4648 Ok ( Self {
47- keywords : keywords . 0 ,
49+ keywords,
4850 range : TextRange :: default ( ) , // TODO
4951 } )
5052 }
@@ -59,7 +61,7 @@ pub(super) fn merge_function_call_arguments(
5961 ast:: Arguments {
6062 node_index : Default :: default ( ) ,
6163 range,
62- args : pos_args. args ,
64+ args : pos_args. args . into ( ) ,
6365 keywords : key_args. keywords ,
6466 }
6567}
@@ -82,7 +84,7 @@ pub(super) fn split_function_call_arguments(
8284 // debug_assert!(range.contains_range(positional_arguments_range));
8385 let positional_arguments = PositionalArguments {
8486 range : positional_arguments_range,
85- args,
87+ args : args . into ( ) ,
8688 } ;
8789
8890 let keyword_arguments_range = keywords
@@ -121,7 +123,7 @@ pub(super) fn split_class_def_args(
121123 // debug_assert!(range.contains_range(positional_arguments_range));
122124 let positional_arguments = PositionalArguments {
123125 range : positional_arguments_range,
124- args,
126+ args : args . into ( ) ,
125127 } ;
126128
127129 let keyword_arguments_range = keywords
@@ -149,18 +151,18 @@ pub(super) fn merge_class_def_args(
149151 let args = if let Some ( positional_arguments) = positional_arguments {
150152 positional_arguments. args
151153 } else {
152- vec ! [ ] . into_boxed_slice ( )
154+ ThinVec :: new ( )
153155 } ;
154156 let keywords = if let Some ( keyword_arguments) = keyword_arguments {
155157 keyword_arguments. keywords
156158 } else {
157- vec ! [ ] . into_boxed_slice ( )
159+ ThinVec :: new ( )
158160 } ;
159161
160162 Some ( Box :: new ( ast:: Arguments {
161163 node_index : Default :: default ( ) ,
162164 range : Default :: default ( ) , // TODO
163- args,
165+ args : args . into ( ) ,
164166 keywords,
165167 } ) )
166168}
0 commit comments