mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-04 02:39:22 +00:00
Simplify compile_dict
This commit is contained in:
parent
64736d0541
commit
6bda1a9e9e
1 changed files with 10 additions and 16 deletions
|
@ -1991,23 +1991,17 @@ impl Compiler {
|
||||||
keys: &[Option<ast::Expr>],
|
keys: &[Option<ast::Expr>],
|
||||||
values: &[ast::Expr],
|
values: &[ast::Expr],
|
||||||
) -> CompileResult<()> {
|
) -> CompileResult<()> {
|
||||||
let mut size = 0;
|
emit!(self, Instruction::BuildMap { size: 0 });
|
||||||
let (packed, unpacked): (Vec<_>, Vec<_>) = keys
|
for (key, value) in keys.iter().zip(values.iter()) {
|
||||||
.iter()
|
if let Some(key) = key {
|
||||||
.zip(values.iter())
|
self.compile_expression(key)?;
|
||||||
.partition(|(k, _)| k.is_some());
|
self.compile_expression(value)?;
|
||||||
for (key, value) in packed {
|
emit!(self, Instruction::MapAdd { i: 0 });
|
||||||
self.compile_expression(key.as_ref().unwrap())?;
|
} else {
|
||||||
self.compile_expression(value)?;
|
self.compile_expression(value)?;
|
||||||
size += 1;
|
emit!(self, Instruction::DictUpdate);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
emit!(self, Instruction::BuildMap { size });
|
|
||||||
|
|
||||||
for (_, value) in unpacked {
|
|
||||||
self.compile_expression(value)?;
|
|
||||||
emit!(self, Instruction::DictUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue