Add an EntityMap::get_or_default() method.
This covers a common pattern for secondary entity maps: Get the value in the map or the default value for out-of-range keys.
This commit is contained in:
@@ -189,13 +189,7 @@ fn write_instruction(w: &mut Write,
|
||||
if !func.locations.is_empty() {
|
||||
let regs = isa.register_info();
|
||||
for &r in func.dfg.inst_results(inst) {
|
||||
write!(s,
|
||||
",{}",
|
||||
func.locations
|
||||
.get(r)
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
.display(®s))?
|
||||
write!(s, ",{}", func.locations.get_or_default(r).display(®s))?
|
||||
}
|
||||
}
|
||||
write!(s, "]")?;
|
||||
|
||||
Reference in New Issue
Block a user