MCPcopy Index your code
hub / github.com/aiscriptdev/aiscript / intern

Method intern

aiscript-vm/src/string/interned.rs:273–303  ·  view source on GitHub ↗
(self, mc: &Mutation<'gc>, s: &[u8])

Source from the content-addressed store, hash-verified

271 }
272
273 fn intern(self, mc: &Mutation<'gc>, s: &[u8]) -> InternedString<'gc> {
274 // SAFETY: If a new string is added, we call the write barrier.
275 let mut dyn_strings = unsafe { self.0.0.unlock_unchecked() }.borrow_mut();
276
277 // SAFETY: The RawTable outlives the iterator
278 unsafe {
279 for bucket in dyn_strings.iter_hash(str_hash(s)) {
280 let (key, _) = *bucket.as_ref();
281 if let Some(st) = key.upgrade(mc).map(InternedString::from_inner) {
282 if st == s {
283 return st;
284 }
285 } else {
286 // SAFETY: it is okay to erase items yielded by the iterator.
287 dyn_strings.erase(bucket);
288 }
289 }
290 }
291
292 // SAFETY: We are going to modify the dyn_strings table, so call the write barrier.
293 Gc::write(mc, self.0);
294
295 let s = InternedString::from_slice(mc, s);
296 dyn_strings.insert(
297 s.stored_hash(),
298 (Gc::downgrade(s.into_inner()), s.stored_hash()),
299 |(_, hash)| *hash,
300 );
301
302 s
303 }
304}
305
306#[derive(Copy, Clone, Collect)]

Callers 15

create_serde_moduleFunction · 0.45
create_random_moduleFunction · 0.45
create_http_moduleFunction · 0.45
response_to_objectFunction · 0.45
create_env_moduleFunction · 0.45
env_argsFunction · 0.45
env_varsFunction · 0.45
env_getFunction · 0.45
create_math_moduleFunction · 0.45
create_jwt_moduleFunction · 0.45
claims_to_objectFunction · 0.45
jwt_encodeFunction · 0.45

Calls 9

str_hashFunction · 0.85
StaticClass · 0.85
stored_hashMethod · 0.80
into_innerMethod · 0.80
borrow_mutMethod · 0.45
as_refMethod · 0.45
upgradeMethod · 0.45
eraseMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected