Skip to content

Commit

Permalink
Add bumpalo_try
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanBrouwer committed Aug 6, 2024
1 parent 17ce490 commit 873d6de
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ by_address = "1.2"
rpds = "1.1"
test_each_file = "0.3"
stacker = "0.1.15"
bumpalo = "3.16.0"
bumpalo = "3.16.0"
bumpalo_try = "0.1.0"
1 change: 1 addition & 0 deletions prism-parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ ariadne.workspace = true
by_address.workspace = true
stacker.workspace = true
bumpalo.workspace = true
bumpalo_try.workspace = true
14 changes: 2 additions & 12 deletions prism-parser/src/core/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::error::{err_combine_opt, ParseError};
use crate::parser::var_map::BlockCtx;
use crate::grammar::action_result::ActionResult;
use bumpalo::Bump;
use bumpalo_try::BumpaloExtend;

#[derive(Eq, PartialEq, Hash, Clone)]
pub struct CacheKey {
Expand Down Expand Up @@ -78,18 +79,7 @@ impl<'arn> Allocs<'arn> {
&self,
iter: I,
) -> Option<&'arn [T]> {
let mut iter = iter.into_iter();
let mut all_ok = true;
let slice = self.bump.alloc_slice_fill_with(iter.len(), |_| {
let v = iter.next().expect("Exact size iter has enough elements");
if let Some(v) = v {
v
} else {
all_ok = false;
todo!()
}
});
all_ok.then_some(slice)
self.bump.alloc_slice_fill_iter_option(iter).map(|s| &*s)
}
}

Expand Down

0 comments on commit 873d6de

Please sign in to comment.