Skip to content

Commit 47e3bd4

Browse files
committed
remove unused static data for to_lowercase
remove a ton of unused empty strings in char::to_lowercase. The last column in the lower case table is completely unused. I noticed this table when analyzing code bloat when compiling to wasm. using to_lowercase increased the binary size from 50kb to 75kb (which is mostly consisting of empty entries '\u{0}'). Removing the last column is an obvious solution, two others could be done too. 1. The second column has only one entry. Remove that column and create a special handling for that. 2. Group consecutive chars with the same conversion distance.
1 parent dc3e59c commit 47e3bd4

File tree

4 files changed

+867
-862
lines changed

4 files changed

+867
-862
lines changed

library/alloc/src/str.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,16 +385,11 @@ impl str {
385385
map_uppercase_sigma(rest, i, &mut s)
386386
} else {
387387
match conversions::to_lower(c) {
388-
[a, '\0', _] => s.push(a),
389-
[a, b, '\0'] => {
388+
[a, '\0'] => s.push(a),
389+
[a, b] => {
390390
s.push(a);
391391
s.push(b);
392392
}
393-
[a, b, c] => {
394-
s.push(a);
395-
s.push(b);
396-
s.push(c);
397-
}
398393
}
399394
}
400395
}

library/core/src/char/methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ impl char {
10181018
#[stable(feature = "rust1", since = "1.0.0")]
10191019
#[inline]
10201020
pub fn to_lowercase(self) -> ToLowercase {
1021-
ToLowercase(CaseMappingIter::new(conversions::to_lower(self)))
1021+
ToLowercase(CaseMappingIter::new_lower(conversions::to_lower(self)))
10221022
}
10231023

10241024
/// Returns an iterator that yields the uppercase mapping of this `char` as one or more

library/core/src/char/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,13 @@ impl CaseMappingIter {
489489
CaseMappingIter::Three(chars[0], chars[1], chars[2])
490490
}
491491
}
492+
fn new_lower(chars: [char; 2]) -> CaseMappingIter {
493+
if chars[1] == '\0' {
494+
CaseMappingIter::One(chars[0]) // Including if chars[0] == '\0'
495+
} else {
496+
CaseMappingIter::Two(chars[0], chars[1])
497+
}
498+
}
492499
}
493500

494501
impl Iterator for CaseMappingIter {

0 commit comments

Comments
 (0)