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

@@ -668,11 +668,7 @@ impl<'a> Verifier<'a> {
/// instruction (if any) matches how the ISA would encode it.
fn verify_encoding(&self, inst: Inst) -> Result {
if let Some(isa) = self.isa {
let encoding = self.func
.encodings
.get(inst)
.cloned()
.unwrap_or_default();
let encoding = self.func.encodings.get_or_default(inst);
if encoding.is_legal() {
let verify_encoding =
isa.encode(&self.func.dfg,