Skip to content

Commit 813c44a

Browse files
authored
Implement SecondaryMap::insert in terms of SecondaryMap::try_insert (#12462)
* Add `PanicOnOom` extension trait To make it clear that we are only ignoring OOM errors, and not hiding the unwrapping of other kinds of errors, in our various TODOs for #12069 * Implement `SecondaryMap::insert` in terms of `SecondaryMap::try_insert`
1 parent 5bdb78b commit 813c44a

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

cranelift/entity/src/map.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use serde::{
1515
de::{Deserializer, SeqAccess, Visitor},
1616
ser::{SerializeSeq, Serializer},
1717
};
18-
use wasmtime_core::error::OutOfMemory;
18+
use wasmtime_core::{alloc::PanicOnOom as _, error::OutOfMemory};
1919

2020
/// A mapping `K -> V` for densely indexed entity references.
2121
///
@@ -113,14 +113,7 @@ where
113113

114114
/// Insert the given key-value pair, returning the old value if it exists.
115115
pub fn insert(&mut self, k: K, v: V) -> Option<V> {
116-
let i = k.index();
117-
if i < self.elems.len() {
118-
Some(core::mem::replace(&mut self.elems[i], v))
119-
} else {
120-
self.resize(i + 1);
121-
self.elems[i] = v;
122-
None
123-
}
116+
self.try_insert(k, v).panic_on_oom()
124117
}
125118

126119
/// Like `insert` but returns an error on allocation failure.

0 commit comments

Comments
 (0)