summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-06-11 05:05:20 +0000
committerbors <bors@rust-lang.org>2015-06-11 05:05:20 +0000
commit37cf025f1c04b2deab2afe7dd08c1f4fa2cb18d6 (patch)
treeadb665019434fc36ab8f28af0a55d8a12b88dda6 /src/libcollections
parent2fbbd54afe4297032f521fa80ed0e5230d6e03e3 (diff)
parente87c62fb12e6b02cfc39fc2a16c315615714757a (diff)
downloadrust-37cf025f1c04b2deab2afe7dd08c1f4fa2cb18d6.tar.gz
rust-37cf025f1c04b2deab2afe7dd08c1f4fa2cb18d6.zip
Auto merge of #26154 - pmarcelll:master, r=Gankro
Various methods in both libcore/char.rs and librustc_unicode/char.rs were previously marked with #[inline], now every method is marked in char's impl blocks.
Partially fixes #26124.
EDIT: I'm not familiar with pull reqests (yet), apparently Github added my second commit to thit PR...
Fixes #26124 
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/string.rs34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index 7ede6545b9f..6717f2f45fa 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -468,24 +468,24 @@ impl String {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn push(&mut self, ch: char) {
-        if (ch as u32) < 0x80 {
-            self.vec.push(ch as u8);
-            return;
-        }
-
-        let cur_len = self.len();
-        // This may use up to 4 bytes.
-        self.vec.reserve(4);
+        match ch.len_utf8() {
+            1 => self.vec.push(ch as u8),
+            ch_len => {
+                let cur_len = self.len();
+                // This may use up to 4 bytes.
+                self.vec.reserve(ch_len);
 
-        unsafe {
-            // Attempt to not use an intermediate buffer by just pushing bytes
-            // directly onto this string.
-            let slice = slice::from_raw_parts_mut (
-                self.vec.as_mut_ptr().offset(cur_len as isize),
-                4
-            );
-            let used = ch.encode_utf8(slice).unwrap_or(0);
-            self.vec.set_len(cur_len + used);
+                unsafe {
+                    // Attempt to not use an intermediate buffer by just pushing bytes
+                    // directly onto this string.
+                    let slice = slice::from_raw_parts_mut (
+                        self.vec.as_mut_ptr().offset(cur_len as isize),
+                        ch_len
+                    );
+                    let used = ch.encode_utf8(slice).unwrap_or(0);
+                    self.vec.set_len(cur_len + used);
+                }
+            }
         }
     }