Skip to content

Commit 4425216

Browse files
committed
---
yaml --- r: 212777 b: refs/heads/tmp c: e87c62f h: refs/heads/master i: 212775: 4f9cc23 v: v3
1 parent 0bfea5c commit 4425216

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3232
refs/heads/beta: 4efc4ec178f6ddf3c8cd268b011f3a04056f9d16
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35-
refs/heads/tmp: c5d0e2a0733b5271d1044979cf824dccb2a3c3d5
35+
refs/heads/tmp: e87c62fb12e6b02cfc39fc2a16c315615714757a
3636
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3737
refs/tags/homu-tmp: bea1c4a78e5233ea6f85a2028a26e08c26635fca
3838
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412

branches/tmp/src/libcollections/string.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -468,24 +468,24 @@ impl String {
468468
#[inline]
469469
#[stable(feature = "rust1", since = "1.0.0")]
470470
pub fn push(&mut self, ch: char) {
471-
if (ch as u32) < 0x80 {
472-
self.vec.push(ch as u8);
473-
return;
474-
}
475-
476-
let cur_len = self.len();
477-
// This may use up to 4 bytes.
478-
self.vec.reserve(4);
471+
match ch.len_utf8() {
472+
1 => self.vec.push(ch as u8),
473+
ch_len => {
474+
let cur_len = self.len();
475+
// This may use up to 4 bytes.
476+
self.vec.reserve(ch_len);
479477

480-
unsafe {
481-
// Attempt to not use an intermediate buffer by just pushing bytes
482-
// directly onto this string.
483-
let slice = slice::from_raw_parts_mut (
484-
self.vec.as_mut_ptr().offset(cur_len as isize),
485-
4
486-
);
487-
let used = ch.encode_utf8(slice).unwrap_or(0);
488-
self.vec.set_len(cur_len + used);
478+
unsafe {
479+
// Attempt to not use an intermediate buffer by just pushing bytes
480+
// directly onto this string.
481+
let slice = slice::from_raw_parts_mut (
482+
self.vec.as_mut_ptr().offset(cur_len as isize),
483+
ch_len
484+
);
485+
let used = ch.encode_utf8(slice).unwrap_or(0);
486+
self.vec.set_len(cur_len + used);
487+
}
488+
}
489489
}
490490
}
491491

0 commit comments

Comments
 (0)