Skip to content

Commit a5135a4

Browse files
committed
Refactor Uint256::from_uint126
1 parent 219afe7 commit a5135a4

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

packages/std/src/math/uint256.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,12 @@ impl Uint256 {
102102
pub const fn from_uint128(num: Uint128) -> Self {
103103
let num = num.u128();
104104
let bytes = num.to_le_bytes();
105-
let words: [u64; 4] = [
106-
u64::from_le_bytes([
107-
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
108-
]),
109-
u64::from_le_bytes([
110-
bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14],
111-
bytes[15],
112-
]),
113-
0,
114-
0,
115-
];
116-
Self(U256(words))
105+
106+
Self::from_le_bytes([
107+
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
108+
bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15],
109+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
110+
])
117111
}
118112

119113
/// Returns a copy of the number as big endian bytes.

0 commit comments

Comments
 (0)