Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move is_bit_set into match body #339

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/run_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ impl<'a, D: Dialect> RunProgramContext<'a, D> {
if cost > effective_max_cost {
return err(max_cost_ptr, "cost exceeded");
}
let top = self.op_stack.pop();
let op = match top {
let op = match self.op_stack.pop() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this whole loop should probably be turned into something like:

while let Some(op) = self.op_stack.pop() {
   ...
}

as long as we can ensure the cost check is still performed in the edge case of it exceeding on the last operator

Some(f) => f,
None => break,
};
Expand Down
2 changes: 1 addition & 1 deletion src/traverse_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ pub fn traverse_path(allocator: &Allocator, node_index: &[u8], args: NodePtr) ->
let mut byte_idx = node_index.len() - 1;
let mut bitmask = 0x01;
while byte_idx > first_bit_byte_index || bitmask < last_bitmask {
let is_bit_set: bool = (node_index[byte_idx] & bitmask) != 0;
match allocator.sexp(arg_list) {
SExp::Atom => {
return Err(EvalErr(arg_list, "path into atom".into()));
}
SExp::Pair(left, right) => {
let is_bit_set = (node_index[byte_idx] & bitmask) != 0;
arg_list = if is_bit_set { right } else { left };
}
}
Expand Down