Skip to content

Commit ea8ad39

Browse files
author
bors-servo
authored
Auto merge of #186 - servo:ascii, r=KiChjang
Make to_ascii_{upper,lower}case more efficent. * Use `From<String> for Atom` * Use the fast path with non-letters too <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/string-cache/186) <!-- Reviewable:end -->
2 parents c6e47ae + 1dff0d8 commit ea8ad39

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "string_cache"
4-
version = "0.5.0" # Also update README.md when making a semver-breaking change
4+
version = "0.5.1" # Also update README.md when making a semver-breaking change
55
authors = [ "The Servo Project Developers" ]
66
description = "A string interning library for Rust, developed as part of the Servo project."
77
license = "MIT / Apache-2.0"

src/atom.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,19 +470,21 @@ impl<Static: StaticAtomSet> Deserialize for Atom<Static> {
470470
// over the one from &str.
471471
impl<Static: StaticAtomSet> Atom<Static> {
472472
pub fn to_ascii_uppercase(&self) -> Self {
473-
if self.chars().all(char::is_uppercase) {
474-
self.clone()
475-
} else {
476-
Atom::from(&*((&**self).to_ascii_uppercase()))
473+
for b in self.bytes() {
474+
if let b'a' ... b'z' = b {
475+
return Atom::from((&**self).to_ascii_uppercase())
476+
}
477477
}
478+
self.clone()
478479
}
479480

480481
pub fn to_ascii_lowercase(&self) -> Self {
481-
if self.chars().all(char::is_lowercase) {
482-
self.clone()
483-
} else {
484-
Atom::from(&*((&**self).to_ascii_lowercase()))
482+
for b in self.bytes() {
483+
if let b'A' ... b'Z' = b {
484+
return Atom::from((&**self).to_ascii_lowercase())
485+
}
485486
}
487+
self.clone()
486488
}
487489

488490
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool {

0 commit comments

Comments
 (0)