Use Ref for storing ast nodes in collections. (#37)

cmp, eq is done as pointer comparison which makes retrieval super fast.

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2023-11-05 22:32:00 -08:00
committed by GitHub
parent d3fd0a3a78
commit a751cd69e1
7 changed files with 137 additions and 116 deletions

View File

@@ -56,7 +56,13 @@ fn analyze_file(regos: &[String], expected_scopes: &[Scope]) -> Result<()> {
let analyzer = Analyzer::new();
let schedule = analyzer.analyze(&modules_ref)?;
for (idx, (_, scope)) in schedule.scopes.iter().enumerate() {
let mut scopes: Vec<(&Query, &regorus::Scope)> = schedule
.scopes
.iter()
.map(|(r, s)| (r.inner(), s))
.collect();
scopes.sort_by(|a, b| a.0.span.line.cmp(&b.0.span.line));
for (idx, (_, scope)) in scopes.iter().enumerate() {
if idx > expected_scopes.len() {
bail!("extra scope generated.")
}