Skip to content

Commit d6fc7bc

Browse files
committed
Merge #32
32: Avoid an extra allocation in UpperHex r=cuviper a=cuviper
2 parents 1cf2196 + b53a797 commit d6fc7bc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/bigint.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ impl fmt::LowerHex for BigInt {
173173

174174
impl fmt::UpperHex for BigInt {
175175
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
176-
f.pad_integral(!self.is_negative(),
177-
"0x",
178-
&self.data.to_str_radix(16).to_ascii_uppercase())
176+
let mut s = self.data.to_str_radix(16);
177+
s.make_ascii_uppercase();
178+
f.pad_integral(!self.is_negative(), "0x", &s)
179179
}
180180
}
181181

src/biguint.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ impl fmt::LowerHex for BigUint {
9393

9494
impl fmt::UpperHex for BigUint {
9595
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
96-
f.pad_integral(true, "0x", &self.to_str_radix(16).to_ascii_uppercase())
96+
let mut s = self.to_str_radix(16);
97+
s.make_ascii_uppercase();
98+
f.pad_integral(true, "0x", &s)
9799
}
98100
}
99101

0 commit comments

Comments
 (0)