Fix ArrayString to implement .push(char) faster

Previously we used formatting, which is a virtual call and quite the
detour. Now copy the utf-8 encoding code from Rust (thank you Alex
Crichton) and use that.
This commit is contained in:
bluss
2016-10-04 14:40:33 +02:00
parent f331bb1228
commit 7a7ec178b9
4 changed files with 87 additions and 2 deletions
+15
View File
@@ -356,6 +356,21 @@ fn test_string_clone() {
assert_eq!(&t, &s);
}
#[test]
fn test_string_push() {
let text = "abcαβγ";
let mut s = ArrayString::<[_; 8]>::new();
for c in text.chars() {
if let Err(_) = s.push(c) {
break;
}
}
assert_eq!("abcαβ", &s[..]);
s.push('x').ok();
assert_eq!("abcαβx", &s[..]);
assert!(s.push('x').is_err());
}
#[test]
fn test_insert_at_length() {