MCPcopy Index your code
hub / github.com/RustPython/RustPython / intern

Method intern

crates/vm/src/intern.rs:45–74  ·  view source on GitHub ↗
(
        &self,
        s: S,
        typ: PyTypeRef,
    )

Source from the content-addressed store, hash-verified

43
44 #[inline]
45 pub unsafe fn intern<S: InternableString>(
46 &self,
47 s: S,
48 typ: PyTypeRef,
49 ) -> &'static PyStrInterned {
50 if let Some(found) = self.interned(s.as_ref()) {
51 return found;
52 }
53
54 #[cold]
55 fn miss(zelf: &StringPool, s: PyRefExact<PyStr>) -> &'static PyStrInterned {
56 let cache = CachedPyStrRef { inner: s };
57 let inserted = zelf.inner.write().insert(cache.clone());
58 if inserted {
59 let interned = unsafe { cache.as_interned_str() };
60 unsafe { interned.as_object().mark_intern() };
61 interned
62 } else {
63 unsafe {
64 zelf.inner
65 .read()
66 .get(cache.as_ref())
67 .expect("inserted is false")
68 .as_interned_str()
69 }
70 }
71 }
72 let str_ref = s.into_pyref_exact(typ);
73 miss(self, str_ref)
74 }
75
76 #[inline]
77 pub fn interned<S: MaybeInternedString + ?Sized>(

Callers 10

namedtupleFunction · 0.80
isinternedFunction · 0.80
test_internMethod · 0.80
InterningTestCaseClass · 0.80
testInternMethod · 0.80
testNoInternMethod · 0.80
init_genesisMethod · 0.80
intern_strMethod · 0.80

Calls 3

internedMethod · 0.80
into_pyref_exactMethod · 0.80
as_refMethod · 0.45

Tested by 6

isinternedFunction · 0.64
test_internMethod · 0.64
testInternMethod · 0.64
testNoInternMethod · 0.64