Skip to content

Commit 5f904d2

Browse files
committed
Shave off one more string append in a rare case.
1 parent a542258 commit 5f904d2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/libcore/int-template.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ fn parse_buf(buf: [u8], radix: uint) -> option<T> {
8989
fn from_str(s: str) -> option<T> { parse_buf(str::bytes(s), 10u) }
9090

9191
#[doc = "Convert to a string in a given base"]
92-
fn to_str(n: T, radix: uint) -> str {
93-
assert (0u < radix && radix <= 16u);
94-
ret if n < 0 as T {
95-
"-" + uint::to_str(-n as uint, radix)
96-
} else { uint::to_str(n as uint, radix) };
92+
fn to_str(n: T, radix: uint) -> str unsafe {
93+
to_str_bytes(n, radix) {|slice|
94+
vec::unpack_slice(slice) {|p, len|
95+
str::unsafe::from_buf_len(p, len)
96+
}
97+
}
9798
}
9899

99100
fn to_str_bytes<U>(n: T, radix: uint, f: fn([u8]/&) -> U) -> U {

0 commit comments

Comments
 (0)