File tree Expand file tree Collapse file tree 1 file changed +16
-10
lines changed
Expand file tree Collapse file tree 1 file changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -1991,17 +1991,23 @@ impl Compiler {
19911991 keys : & [ Option < ast:: Expr > ] ,
19921992 values : & [ ast:: Expr ] ,
19931993 ) -> CompileResult < ( ) > {
1994- emit ! ( self , Instruction :: BuildMap { size: 0 } ) ;
1995- for ( key, value) in keys. iter ( ) . zip ( values. iter ( ) ) {
1996- if let Some ( key) = key {
1997- self . compile_expression ( key) ?;
1998- self . compile_expression ( value) ?;
1999- emit ! ( self , Instruction :: MapAdd { i: 0 } ) ;
2000- } else {
2001- self . compile_expression ( value) ?;
2002- emit ! ( self , Instruction :: DictUpdate ) ;
2003- }
1994+ let mut size = 0 ;
1995+ let ( packed, unpacked) : ( Vec < _ > , Vec < _ > ) = keys
1996+ . iter ( )
1997+ . zip ( values. iter ( ) )
1998+ . partition ( |( k, _) | k. is_some ( ) ) ;
1999+ for ( key, value) in packed {
2000+ self . compile_expression ( key. as_ref ( ) . unwrap ( ) ) ?;
2001+ self . compile_expression ( value) ?;
2002+ size += 1 ;
20042003 }
2004+ emit ! ( self , Instruction :: BuildMap { size } ) ;
2005+
2006+ for ( _, value) in unpacked {
2007+ self . compile_expression ( value) ?;
2008+ emit ! ( self , Instruction :: DictUpdate ) ;
2009+ }
2010+
20052011 Ok ( ( ) )
20062012 }
20072013
You can’t perform that action at this time.
0 commit comments