Skip to content

Commit 7396604

Browse files
Implement PublicKey ordering using FFI
Instead of selializing the key we can call down to the ffi layer to do ordering. Co-authored-by: Tobin C. Harding <me@tobin.cc>
1 parent 0faf404 commit 7396604

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/key.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,13 +673,16 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
673673

674674
impl PartialOrd for PublicKey {
675675
fn partial_cmp(&self, other: &PublicKey) -> Option<core::cmp::Ordering> {
676-
self.serialize().partial_cmp(&other.serialize())
676+
Some(self.cmp(other))
677677
}
678678
}
679679

680680
impl Ord for PublicKey {
681681
fn cmp(&self, other: &PublicKey) -> core::cmp::Ordering {
682-
self.serialize().cmp(&other.serialize())
682+
let ret = unsafe {
683+
ffi::secp256k1_ec_pubkey_cmp(ffi::secp256k1_context_no_precomp, self.as_c_ptr(), other.as_c_ptr())
684+
};
685+
ret.cmp(&0i32)
683686
}
684687
}
685688

0 commit comments

Comments
 (0)