@@ -168,7 +168,7 @@ impl<'a> ser::Serializer for Serializer<'a> {
168168
169169 #[ inline]
170170 fn serialize_char ( self , value : char ) -> Result < Value > {
171- self . serialize_str ( & value. to_string ( ) )
171+ self . serialize_str ( value. encode_utf8 ( & mut [ 0 ; 4 ] ) )
172172 }
173173
174174 #[ inline]
@@ -245,9 +245,9 @@ impl<'a> ser::Serializer for Serializer<'a> {
245245 where
246246 T : Serialize + ?Sized ,
247247 {
248- let table = self . lua . create_table ( ) ?;
249248 let variant = self . lua . create_string ( variant) ?;
250249 let value = self . lua . to_value_with ( value, self . options ) ?;
250+ let table = ( self . lua ) . create_table_with_capacity ( 0 , usize:: from ( !value. is_nil ( ) ) ) ?;
251251 table. raw_set ( variant, value) ?;
252252 Ok ( Value :: Table ( table) )
253253 }
@@ -286,12 +286,17 @@ impl<'a> ser::Serializer for Serializer<'a> {
286286 _name : & ' static str ,
287287 _variant_index : u32 ,
288288 variant : & ' static str ,
289- _len : usize ,
289+ len : usize ,
290290 ) -> Result < Self :: SerializeTupleVariant > {
291+ let capacity = if self . options . serialize_none_to_null && self . options . serialize_unit_to_null {
292+ len
293+ } else {
294+ 0
295+ } ;
291296 Ok ( SerializeTupleVariant {
292297 lua : self . lua ,
293298 variant,
294- table : self . lua . create_table ( ) ?,
299+ table : self . lua . create_table_with_capacity ( capacity , 0 ) ?,
295300 options : self . options ,
296301 } )
297302 }
@@ -461,7 +466,7 @@ impl ser::SerializeTupleVariant for SerializeTupleVariant<'_> {
461466 }
462467
463468 fn end ( self ) -> Result < Value > {
464- let table = self . lua . create_table ( ) ?;
469+ let table = self . lua . create_table_with_capacity ( 0 , 1 ) ?;
465470 table. raw_set ( self . variant , self . table ) ?;
466471 Ok ( Value :: Table ( table) )
467472 }
0 commit comments