| 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. |