Skip to content

Commit 7a59879

Browse files
committed
optimize op_gr for small int
1 parent 81778a5 commit 7a59879

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/more_ops.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,20 @@ pub fn op_mod(a: &mut Allocator, input: NodePtr, _max_cost: Cost) -> Response {
536536

537537
pub fn op_gr(a: &mut Allocator, input: NodePtr, _max_cost: Cost) -> Response {
538538
let [v0, v1] = get_args::<2>(a, input, ">")?;
539-
let (v0, v0_len) = int_atom(a, v0, ">")?;
540-
let (v1, v1_len) = int_atom(a, v1, ">")?;
541-
let cost = GR_BASE_COST + (v0_len + v1_len) as Cost * GR_COST_PER_BYTE;
542-
Ok(Reduction(cost, if v0 > v1 { a.one() } else { a.nil() }))
539+
540+
match (a.small_number(v0), a.small_number(v1)) {
541+
(Some(lhs), Some(rhs)) => {
542+
let cost =
543+
GR_BASE_COST + (len_for_value(lhs) + len_for_value(rhs)) as Cost * GR_COST_PER_BYTE;
544+
Ok(Reduction(cost, if lhs > rhs { a.one() } else { a.nil() }))
545+
}
546+
_ => {
547+
let (v0, v0_len) = int_atom(a, v0, ">")?;
548+
let (v1, v1_len) = int_atom(a, v1, ">")?;
549+
let cost = GR_BASE_COST + (v0_len + v1_len) as Cost * GR_COST_PER_BYTE;
550+
Ok(Reduction(cost, if v0 > v1 { a.one() } else { a.nil() }))
551+
}
552+
}
543553
}
544554

545555
pub fn op_gr_bytes(a: &mut Allocator, input: NodePtr, _max_cost: Cost) -> Response {

0 commit comments

Comments
 (0)