Skip to content

Commit

Permalink
perf: remove im crate (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored Oct 10, 2024
1 parent 6ba5125 commit 38b1ca2
Show file tree
Hide file tree
Showing 24 changed files with 135 additions and 193 deletions.
44 changes: 0 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ uuid = { version = "1.1", features = ["v4", "serde"] }
regex = { version = "1.7.3" }
anyhow = { version = "1.0.70" }
itertools = { version = "0.10.5" }
im = { version = "15.1.0" }
serde_json = { version = "1.0.96" }
serde = { version = "1.0.164", features = ["derive"] }
sha2 = { version = "0.10.8" }
Expand Down
9 changes: 3 additions & 6 deletions crates/core/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use anyhow::{bail, Result};
use grit_pattern_matcher::file_owners::FileOwner;
pub use grit_util::ByteRange;
use grit_util::{AnalysisLog as GritAnalysisLog, Ast, Position, Range, VariableMatch};
use im::Vector;
use marzano_language::grit_ts_node::grit_node_types;
use marzano_language::language::{MarzanoLanguage, Tree};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -113,9 +112,7 @@ impl MatchResult {
}
}

pub(crate) fn file_to_match_result(
file: &Vector<&FileOwner<Tree>>,
) -> Result<Option<MatchResult>> {
pub(crate) fn file_to_match_result(file: &[&FileOwner<Tree>]) -> Result<Option<MatchResult>> {
if file.is_empty() {
bail!("cannot have file with no versions")
} else if file.len() == 1 {
Expand All @@ -136,8 +133,8 @@ impl MatchResult {
}
} else {
return Ok(Some(MatchResult::Rewrite(Rewrite::file_to_rewrite(
file.front().unwrap(),
file.back().unwrap(),
file.first().unwrap(),
file.last().unwrap(),
)?)));
}
}
Expand Down
9 changes: 4 additions & 5 deletions crates/core/src/built_in_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use grit_pattern_matcher::{
},
};
use grit_util::{AnalysisLogs, CodeRange, Language};
use im::Vector;
use itertools::Itertools;
use rand::prelude::SliceRandom;
use rand::Rng;
Expand Down Expand Up @@ -422,22 +421,22 @@ fn distinct_fn<'a>(
let list = args.into_iter().next().unwrap();
match list {
Some(MarzanoResolvedPattern::List(list)) => {
let mut unique_list = Vector::new();
let mut unique_list = Vec::new();
for item in list {
if !unique_list.contains(&item) {
unique_list.push_back(item);
unique_list.push(item);
}
}
Ok(MarzanoResolvedPattern::List(unique_list))
}
Some(MarzanoResolvedPattern::Binding(binding)) => match binding.last() {
Some(b) => {
if let Some(list_items) = b.list_items() {
let mut unique_list = Vector::new();
let mut unique_list = Vec::new();
for item in list_items {
let resolved = ResolvedPattern::from_node_binding(item);
if !unique_list.contains(&resolved) {
unique_list.push_back(resolved);
unique_list.push(resolved);
}
}
Ok(MarzanoResolvedPattern::List(unique_list))
Expand Down
9 changes: 4 additions & 5 deletions crates/core/src/marzano_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use grit_util::{
error::{GritPatternError, GritResult},
AnalysisLogs, Ast, FileOrigin, InputRanges, MatchRanges,
};
use im::vector;
use marzano_language::{
language::{MarzanoLanguage, Tree},
target_language::TargetLanguage,
Expand Down Expand Up @@ -332,7 +331,7 @@ impl<'a> ExecContext<'a, MarzanoQueryContext> for MarzanoContext<'a> {
};
}

let Some(new_files) = state.bindings[GLOBAL_VARS_SCOPE_INDEX.into()]
let Some(new_files) = state.bindings[GLOBAL_VARS_SCOPE_INDEX as usize]
.last()
.and_then(|binding| binding[NEW_FILES_INDEX].value.as_ref())
.and_then(ResolvedPattern::get_list_items)
Expand Down Expand Up @@ -375,9 +374,9 @@ impl<'a> ExecContext<'a, MarzanoQueryContext> for MarzanoContext<'a> {
let _ = state.files.push_new_file(self.files().last().unwrap());
}

state.effects = vector![];
let the_new_files = state.bindings[GLOBAL_VARS_SCOPE_INDEX.into()]
.back_mut()
state.effects = vec![];
let the_new_files = state.bindings[GLOBAL_VARS_SCOPE_INDEX as usize]
.last_mut()
.unwrap()[NEW_FILES_INDEX]
.as_mut();
the_new_files.value = Some(ResolvedPattern::from_list_parts([].into_iter()));
Expand Down
Loading

0 comments on commit 38b1ca2

Please sign in to comment.