Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use raw string where appropriate. add newlines
  • Loading branch information
ShaharNaveh committed Jun 21, 2025
commit 18b385e9a3b70957f856c4b4c3140903ce57edfe
12 changes: 11 additions & 1 deletion vm/src/builtins/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@
radd?.call((zelf,), vm)
} else {
Err(vm.new_type_error(format!(
"can only concatenate str (not \"{}\") to str",
r#"can only concatenate str (not "{}") to str"#,
other.class().name()
)))
}
Expand Down Expand Up @@ -570,11 +570,12 @@
hash => hash,
}
}

#[cold]
fn _compute_hash(&self, vm: &VirtualMachine) -> hash::PyHash {
let hash_val = vm.state.hash_secret.hash_bytes(self.as_bytes());
debug_assert_ne!(hash_val, hash::SENTINEL);
// like with char_len, we don't need a cmpxchg loop, since it'll always be the same value

Check warning on line 578 in vm/src/builtins/str.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (cmpxchg)
self.hash.store(hash_val, atomic::Ordering::Relaxed);
hash_val
}
Expand All @@ -583,6 +584,7 @@
pub fn byte_len(&self) -> usize {
self.data.len()
}

#[inline]
pub fn is_empty(&self) -> bool {
self.data.is_empty()
Expand Down Expand Up @@ -1439,6 +1441,7 @@
struct CharLenStr<'a>(&'a str, usize);
impl std::ops::Deref for CharLenStr<'_> {
type Target = str;

fn deref(&self) -> &Self::Target {
self.0
}
Expand Down Expand Up @@ -1852,6 +1855,7 @@
fn as_ref(&self) -> Option<&Wtf8> {
Some(self.as_wtf8())
}

fn is_empty(&self) -> bool {
self.data.is_empty()
}
Expand All @@ -1861,6 +1865,7 @@
fn as_ref(&self) -> Option<&str> {
self.data.as_str()
}

fn is_empty(&self) -> bool {
self.data.is_empty()
}
Expand All @@ -1870,6 +1875,7 @@
fn as_ref(&self) -> Option<&AsciiStr> {
self.data.as_ascii()
}

fn is_empty(&self) -> bool {
self.data.is_empty()
}
Expand All @@ -1893,9 +1899,11 @@
fn is_lowercase(self) -> bool {
self.is_lowercase()
}

fn is_uppercase(self) -> bool {
self.is_uppercase()
}

fn bytes_len(self) -> usize {
self.len_utf8()
}
Expand Down Expand Up @@ -2122,9 +2130,11 @@
fn is_lowercase(self) -> bool {
self.is_lowercase()
}

fn is_uppercase(self) -> bool {
self.is_uppercase()
}

fn bytes_len(self) -> usize {
1
}
Expand Down Expand Up @@ -2250,8 +2260,8 @@
("Format This As Title String", "fOrMaT thIs aS titLe String"),
("Format,This-As*Title;String", "fOrMaT,thIs-aS*titLe;String"),
("Getint", "getInt"),
("Greek Ωppercases ...", "greek ωppercases ..."),

Check warning on line 2263 in vm/src/builtins/str.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (ωppercases)

Check warning on line 2263 in vm/src/builtins/str.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (Ωppercases)
("Greek ῼitlecases ...", "greek ῳitlecases ..."),

Check warning on line 2264 in vm/src/builtins/str.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (ῳitlecases)

Check warning on line 2264 in vm/src/builtins/str.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (ῼitlecases)
];
for (title, input) in tests {
assert_eq!(PyStr::from(input).title().as_str(), Ok(title));
Expand All @@ -2265,8 +2275,8 @@
"A Titlecased Line",
"A\nTitlecased Line",
"A Titlecased, Line",
"Greek Ωppercases ...",

Check warning on line 2278 in vm/src/builtins/str.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (Ωppercases)
"Greek ῼitlecases ...",

Check warning on line 2279 in vm/src/builtins/str.rs

View workflow job for this annotation

GitHub Actions / Check Rust code with rustfmt and clippy

Unknown word (ῼitlecases)
];

for s in pos {
Expand Down
Loading