Shave off one more string append in a rare case.
This commit is contained in:
parent
a542258277
commit
5f904d278f
@ -89,11 +89,12 @@ fn parse_buf(buf: [u8], radix: uint) -> option<T> {
|
|||||||
fn from_str(s: str) -> option<T> { parse_buf(str::bytes(s), 10u) }
|
fn from_str(s: str) -> option<T> { parse_buf(str::bytes(s), 10u) }
|
||||||
|
|
||||||
#[doc = "Convert to a string in a given base"]
|
#[doc = "Convert to a string in a given base"]
|
||||||
fn to_str(n: T, radix: uint) -> str {
|
fn to_str(n: T, radix: uint) -> str unsafe {
|
||||||
assert (0u < radix && radix <= 16u);
|
to_str_bytes(n, radix) {|slice|
|
||||||
ret if n < 0 as T {
|
vec::unpack_slice(slice) {|p, len|
|
||||||
"-" + uint::to_str(-n as uint, radix)
|
str::unsafe::from_buf_len(p, len)
|
||||||
} else { uint::to_str(n as uint, radix) };
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_str_bytes<U>(n: T, radix: uint, f: fn([u8]/&) -> U) -> U {
|
fn to_str_bytes<U>(n: T, radix: uint, f: fn([u8]/&) -> U) -> U {
|
||||||
|
Loading…
Reference in New Issue
Block a user