From 60147b0b08c7fab5b1bd6a300ee19c7ccc5b3001 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 25 Dec 2024 08:08:46 -0700 Subject: [PATCH] opt: for little-endian targets, use as_le_bytes --- src/bytes.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/bytes.rs b/src/bytes.rs index 712527f..be19624 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -365,12 +365,18 @@ impl Uint { "Buffer is too small to hold the bytes of the Uint" ); - let chunks = buf[..Self::BYTES].chunks_mut(8); + #[cfg(target_endian = "little")] + buf[..Self::BYTES].copy_from_slice(self.as_le_slice()); - self.limbs.iter().zip(chunks).for_each(|(&limb, chunk)| { - let le = limb.to_le_bytes(); - chunk.copy_from_slice(&le[..chunk.len()]); - }); + #[cfg(not(target_endian = "little"))] + { + let chunks = buf[..Self::BYTES].chunks_mut(8); + + self.limbs.iter().zip(chunks).for_each(|(&limb, chunk)| { + let le = limb.to_le_bytes(); + chunk.copy_from_slice(&le[..chunk.len()]); + }); + } Self::BYTES }