Skip to content

Commit ad7621d

Browse files
committed
Handle array manually in string case conversion methods
1 parent 4faaf7e commit ad7621d

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/liballoc/str.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use core::str::pattern::{Searcher, ReverseSearcher, DoubleEndedSearcher};
4545
use core::mem;
4646
use core::ptr;
4747
use core::iter::FusedIterator;
48+
use core::unicode::conversions;
4849

4950
use borrow::{Borrow, ToOwned};
5051
use boxed::Box;
@@ -369,7 +370,18 @@ impl str {
369370
// See https://github.com/rust-lang/rust/issues/26035
370371
map_uppercase_sigma(self, i, &mut s)
371372
} else {
372-
s.extend(c.to_lowercase());
373+
match conversions::to_lower(c) {
374+
[a, '\0', _] => s.push(a),
375+
[a, b, '\0'] => {
376+
s.push(a);
377+
s.push(b);
378+
}
379+
[a, b, c] => {
380+
s.push(a);
381+
s.push(b);
382+
s.push(c);
383+
}
384+
}
373385
}
374386
}
375387
return s;
@@ -423,7 +435,20 @@ impl str {
423435
#[stable(feature = "unicode_case_mapping", since = "1.2.0")]
424436
pub fn to_uppercase(&self) -> String {
425437
let mut s = String::with_capacity(self.len());
426-
s.extend(self.chars().flat_map(|c| c.to_uppercase()));
438+
for c in self[..].chars() {
439+
match conversions::to_upper(c) {
440+
[a, '\0', _] => s.push(a),
441+
[a, b, '\0'] => {
442+
s.push(a);
443+
s.push(b);
444+
}
445+
[a, b, c] => {
446+
s.push(a);
447+
s.push(b);
448+
s.push(c);
449+
}
450+
}
451+
}
427452
return s;
428453
}
429454

src/libcore/unicode/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ pub(crate) mod version;
2020
pub mod derived_property {
2121
pub use unicode::tables::derived_property::{Case_Ignorable, Cased};
2222
}
23+
pub mod conversions {
24+
pub use unicode::tables::conversions::{to_lower, to_upper};
25+
}
2326

2427
// For use in libsyntax
2528
pub mod property {

0 commit comments

Comments
 (0)