Skip to main content

no_mistakes_postgres_engine/embedded/helpers/
sites.rs

1use super::summary::ImportedSite;
2
3/// Imported-helper calls seen during one walk. A call expression can be
4/// recovered more than once (provenance, composition, alternatives), so each
5/// distinct shape at one source offset is interned to a single hole index.
6#[derive(Default)]
7pub struct Sites {
8    list: Vec<ImportedSite>,
9    starts: Vec<u32>,
10}
11
12impl Sites {
13    pub(crate) fn intern(&mut self, start: u32, site: ImportedSite) -> usize {
14        let existing = self
15            .list
16            .iter()
17            .zip(&self.starts)
18            .position(|(known, at)| *at == start && *known == site);
19        existing.unwrap_or_else(|| {
20            self.list.push(site);
21            self.starts.push(start);
22            self.list.len() - 1
23        })
24    }
25
26    pub(crate) fn source_offset(&self, index: usize) -> Option<u32> {
27        self.starts.get(index).copied()
28    }
29
30    pub(crate) fn into_list(self) -> Vec<ImportedSite> {
31        self.list
32    }
33}