Skip to content

Commit

Permalink
use consts BFIELD_ZERO and BFIELD_ONE for traits Zero and One
Browse files Browse the repository at this point in the history
Avoid Montgomery reduction for those known, frequently used constants.
  • Loading branch information
jan-ferdinand committed May 11, 2023
1 parent 8924cdc commit 2346ac1
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions twenty-first/src/shared_math/b_field_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,24 +403,24 @@ impl FiniteField for BFieldElement {}
impl Zero for BFieldElement {
#[inline]
fn zero() -> Self {
BFieldElement::new(0)
BFIELD_ZERO
}

#[inline]
fn is_zero(&self) -> bool {
self.canonical_representation() == 0
self == &BFIELD_ZERO
}
}

impl One for BFieldElement {
#[inline]
fn one() -> Self {
BFieldElement::new(1)
BFIELD_ONE
}

#[inline]
fn is_one(&self) -> bool {
self.canonical_representation() == 1
self == &BFIELD_ONE
}
}

Expand Down

0 comments on commit 2346ac1

Please sign in to comment.