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 440add86e7
commit d078c546e5
5 changed files with 10 additions and 18 deletions

View File

@@ -64,7 +64,7 @@ pub fn relax_branches(func: &mut Function, isa: &TargetIsa) {
}
while let Some(inst) = pos.next_inst() {
let enc = func.encodings.get(inst).cloned().unwrap_or_default();
let enc = func.encodings.get_or_default(inst);
let size = encinfo.bytes(enc);
// See if this might be a branch that is out of range.