MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / try_alloc

Method try_alloc

crates/core/src/slab.rs:328–341  ·  view source on GitHub ↗
(&mut self, value: T)

Source from the content-addressed store, hash-verified

326 /// returned via `Err(value)`.
327 #[inline]
328 pub fn try_alloc(&mut self, value: T) -> Result<Id, T> {
329 if let Some(index) = self.try_alloc_index() {
330 let next_free = match self.entries[index.index()] {
331 Entry::Free { next_free } => next_free,
332 Entry::Occupied { .. } => unreachable!(),
333 };
334 self.free = next_free;
335 self.entries[index.index()] = Entry::Occupied(value);
336 self.len += 1;
337 Ok(Id(index))
338 } else {
339 Err(value)
340 }
341 }
342
343 #[inline]
344 fn try_alloc_index(&mut self) -> Option<EntryIndex> {

Callers 3

allocMethod · 0.80
alloc_slowMethod · 0.80
pushMethod · 0.80

Calls 4

OkFunction · 0.85
try_alloc_indexMethod · 0.80
IdClass · 0.70
indexMethod · 0.45

Tested by

no test coverage detected