about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2025-07-07 02:11:32 +0300
committerSimonas Kazlauskas <git@kazlauskas.me>2025-07-07 02:14:58 +0300
commit49806a5486e841edf5933ca75ed235afb7ad2bdb (patch)
tree65ee93abfcd60892cf36510edb5980feadd06e3d
parenta84ab0ce6c4557a2f01a3a6c3fdb0f92098db78d (diff)
downloadrust-49806a5486e841edf5933ca75ed235afb7ad2bdb.tar.gz
rust-49806a5486e841edf5933ca75ed235afb7ad2bdb.zip
lib: more eagerly return `self.len()` from `ceil_char_boundary`
There is no reason to go through the complicated branch as it would
always return `self.len()` in this case. Also helps debug code somewhat
and I guess might make optimizations easier (although I haven't really a
sample to demonstrate this.)

ref. #93743
Suggested by @chrisduerr
-rw-r--r--library/core/src/str/mod.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs
index 8a6925a0e9a..fe64132ff22 100644
--- a/library/core/src/str/mod.rs
+++ b/library/core/src/str/mod.rs
@@ -446,7 +446,7 @@ impl str {
     #[unstable(feature = "round_char_boundary", issue = "93743")]
     #[inline]
     pub fn ceil_char_boundary(&self, index: usize) -> usize {
-        if index > self.len() {
+        if index >= self.len() {
             self.len()
         } else {
             let upper_bound = Ord::min(index + 4, self.len());