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

Method push

crates/wasi-common/src/table.rs:35–51  ·  view source on GitHub ↗

Insert a resource at the next available index.

(&self, a: Arc<T>)

Source from the content-addressed store, hash-verified

33
34 /// Insert a resource at the next available index.
35 pub fn push<T: Any + Send + Sync>(&self, a: Arc<T>) -> Result<u32, Error> {
36 let mut inner = self.0.write().unwrap();
37 // NOTE: The performance of this new key calculation could be very bad once keys wrap
38 // around.
39 if inner.map.len() == u32::MAX as usize {
40 return Err(Error::trap(EnvError::msg("table has no free keys")));
41 }
42 loop {
43 let key = inner.next_key;
44 inner.next_key += 1;
45 if inner.map.contains_key(&key) {
46 continue;
47 }
48 inner.map.insert(key, a);
49 return Ok(key);
50 }
51 }
52
53 /// Check if the table has a resource at the given index.
54 pub fn contains_key(&self, key: u32) -> bool {

Callers 15

newMethod · 0.45
finishMethod · 0.45
getMethod · 0.45
newMethod · 0.45
connectMethod · 0.45
poll_produceMethod · 0.45
valFunction · 0.45
openMethod · 0.45
loadMethod · 0.45
loadMethod · 0.45
load_by_nameMethod · 0.45

Calls 8

msgFunction · 0.85
OkFunction · 0.85
trapFunction · 0.50
unwrapMethod · 0.45
writeMethod · 0.45
lenMethod · 0.45
contains_keyMethod · 0.45
insertMethod · 0.45

Tested by 2

mainFunction · 0.36
request_with_header_sizeFunction · 0.36