Insert a constant; using this method indicates that a constant value will be used and thus will be emitted to the `MachBuffer`. The current implementation can deduplicate constants that are [VCodeConstantData::Pool] or [VCodeConstantData::WellKnown] but not [VCodeConstantData::Generated].
(&mut self, data: VCodeConstantData)
| 1849 | /// that are [VCodeConstantData::Pool] or [VCodeConstantData::WellKnown] but not |
| 1850 | /// [VCodeConstantData::Generated]. |
| 1851 | pub fn insert(&mut self, data: VCodeConstantData) -> VCodeConstant { |
| 1852 | match data { |
| 1853 | VCodeConstantData::Generated(_) => self.constants.push(data), |
| 1854 | VCodeConstantData::Pool(constant, _) => match self.pool_uses.get(&constant) { |
| 1855 | None => { |
| 1856 | let vcode_constant = self.constants.push(data); |
| 1857 | self.pool_uses.insert(constant, vcode_constant); |
| 1858 | vcode_constant |
| 1859 | } |
| 1860 | Some(&vcode_constant) => vcode_constant, |
| 1861 | }, |
| 1862 | VCodeConstantData::WellKnown(data_ref) => { |
| 1863 | match self.well_known_uses.entry(data_ref as *const [u8]) { |
| 1864 | Entry::Vacant(v) => { |
| 1865 | let vcode_constant = self.constants.push(data); |
| 1866 | v.insert(vcode_constant); |
| 1867 | vcode_constant |
| 1868 | } |
| 1869 | Entry::Occupied(o) => *o.get(), |
| 1870 | } |
| 1871 | } |
| 1872 | VCodeConstantData::U64(value) => match self.u64s.entry(value) { |
| 1873 | Entry::Vacant(v) => { |
| 1874 | let vcode_constant = self.constants.push(data); |
| 1875 | v.insert(vcode_constant); |
| 1876 | vcode_constant |
| 1877 | } |
| 1878 | Entry::Occupied(o) => *o.get(), |
| 1879 | }, |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | /// Return the number of constants inserted. |
| 1884 | pub fn len(&self) -> usize { |