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

Method insert

crates/environ/src/string_pool.rs:180–196  ·  view source on GitHub ↗

Insert a new string into this pool.

(&mut self, s: &str)

Source from the content-addressed store, hash-verified

178
179 /// Insert a new string into this pool.
180 pub fn insert(&mut self, s: &str) -> Result<Atom, OutOfMemory> {
181 if let Some(atom) = self.map.get(s) {
182 return Ok(*atom);
183 }
184
185 self.map.reserve(1)?;
186 self.strings.reserve(1)?;
187
188 let mut owned = TryString::new();
189 owned.reserve_exact(s.len())?;
190 owned.push_str(s).expect("reserved capacity");
191 let owned = owned
192 .into_boxed_str()
193 .expect("reserved exact capacity, so shouldn't need to realloc");
194
195 self.insert_new_boxed_str(owned)
196 }
197
198 fn insert_new_boxed_str(&mut self, owned: Box<str>) -> Result<Atom, OutOfMemory> {
199 debug_assert!(!self.map.contains_key(&*owned));

Callers 7

set_trampoline_typeMethod · 0.45
importMethod · 0.45
try_cloneMethod · 0.45
insert_new_boxed_strMethod · 0.45
basicFunction · 0.45
stressFunction · 0.45

Calls 10

OkFunction · 0.85
into_boxed_strMethod · 0.80
insert_new_boxed_strMethod · 0.80
newFunction · 0.50
getMethod · 0.45
reserveMethod · 0.45
reserve_exactMethod · 0.45
lenMethod · 0.45
expectMethod · 0.45
push_strMethod · 0.45

Tested by 3

basicFunction · 0.36
stressFunction · 0.36