From 49806a5486e841edf5933ca75ed235afb7ad2bdb Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 7 Jul 2025 02:11:32 +0300 Subject: [PATCH] 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 --- library/core/src/str/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 8a6925a0e9a43..fe64132ff227d 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());