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:
Jakob Stoklund Olesen
2017-04-25 15:50:59 -07:00
parent a332c3d024
commit c36aedfd03
5 changed files with 10 additions and 18 deletions

View File

@@ -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(&regs))?
write!(s, ",{}", func.locations.get_or_default(r).display(&regs))?
}
}
write!(s, "]")?;