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

Method try_clone

crates/environ/src/string_pool.rs:75–90  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

73
74impl TryClone for StringPool {
75 fn try_clone(&self) -> Result<Self, OutOfMemory> {
76 let mut new_pool = StringPool::new();
77 // Re-intern strings in index order so that each Atom value is
78 // identical in the clone — callers that hold Atoms from the original
79 // can use them interchangeably with the clone.
80 //
81 // Directly cloning `self.map` would copy &'static str keys that point
82 // into the *original* pool's `strings` allocation. Those pointers
83 // become dangling once the original is dropped, leading to UB on any
84 // subsequent lookup. Re-interning ensures the cloned map's keys point
85 // into the clone's own `strings`.
86 for s in self.strings.iter() {
87 new_pool.insert(s)?;
88 }
89 Ok(new_pool)
90 }
91}
92
93impl TryClone for Atom {

Callers

nothing calls this directly

Calls 4

OkFunction · 0.85
newFunction · 0.50
iterMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected