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

Method insert_new_boxed_str

crates/environ/src/string_pool.rs:198–213  ·  view source on GitHub ↗
(&mut self, owned: Box<str>)

Source from the content-addressed store, hash-verified

196 }
197
198 fn insert_new_boxed_str(&mut self, owned: Box<str>) -> Result<Atom, OutOfMemory> {
199 debug_assert!(!self.map.contains_key(&*owned));
200
201 let index = self.strings.len();
202 let atom = Atom::new(index);
203 self.strings.push(owned)?;
204
205 // SAFETY: We never expose this borrow and never mutate or reallocate
206 // strings once inserted into the pool.
207 let s = unsafe { mem::transmute::<&str, &'static str>(&self.strings[index]) };
208
209 let old = self.map.insert(s, atom)?;
210 debug_assert!(old.is_none());
211
212 Ok(atom)
213 }
214
215 /// Get the `Atom` for the given string, if it has already been inserted
216 /// into this pool.

Callers 2

visit_seqMethod · 0.80
insertMethod · 0.80

Calls 5

OkFunction · 0.85
newFunction · 0.50
lenMethod · 0.45
pushMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected