u8::to_string() specialisation (far less asm).

This commit is contained in:
Giles Cope 2021-02-26 23:04:42 +00:00
parent 9a9477fada
commit a69960a4ec
No known key found for this signature in database
GPG Key ID: DF85161DAE0FF36B

View File

@ -2224,6 +2224,25 @@ impl ToString for char {
}
}
#[stable(feature = "u8_to_string_specialization", since="1.999.0")]
impl ToString for u8 {
#[inline]
fn to_string(&self) -> String {
let mut result = String::with_capacity(3);
let mut n = *self;
if n >= 100 {
result.push((b'0' + n / 100) as char);
n %= 100;
}
if !result.is_empty() || n >= 10 {
result.push((b'0' + n / 10) as char);
n %= 10;
};
result.push((b'0' + n) as char);
result
}
}
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
impl ToString for str {
#[inline]