Insert constant data into the pool, returning a handle for later referencing; when constant data is inserted that is a duplicate of previous constant data, the existing handle will be returned.
(&mut self, constant_value: ConstantData)
| 215 | /// data is inserted that is a duplicate of previous constant data, the existing handle will be |
| 216 | /// returned. |
| 217 | pub fn insert(&mut self, constant_value: ConstantData) -> Constant { |
| 218 | if let Some(cst) = self.values_to_handles.get(&constant_value) { |
| 219 | return *cst; |
| 220 | } |
| 221 | |
| 222 | let constant_handle = Constant::new(self.len()); |
| 223 | self.set(constant_handle, constant_value); |
| 224 | constant_handle |
| 225 | } |
| 226 | |
| 227 | /// Retrieve the constant data given a handle. |
| 228 | pub fn get(&self, constant_handle: Constant) -> &ConstantData { |