From 7cdd41642d85458066342c12cfe4a5e579b15278 Mon Sep 17 00:00:00 2001 From: Quinton Miller <nicetas.c@gmail.com> Date: Fri, 8 Nov 2024 12:49:50 +0800 Subject: [PATCH] Optimize `String#rchop?()` --- src/string.cr | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/string.cr b/src/string.cr index 09272c80eb45..273472d34517 100644 --- a/src/string.cr +++ b/src/string.cr @@ -1798,11 +1798,7 @@ class String def rchop? : String? return if empty? - if to_unsafe[bytesize - 1] < 0x80 || single_byte_optimizable? - return unsafe_byte_slice_string(0, bytesize - 1) - end - - self[0, size - 1] + unsafe_byte_slice_string(0, Char::Reader.new(at_end: self).pos, @length > 0 ? @length - 1 : 0) end # Returns a new `String` with *suffix* removed from the end of the string if possible, else returns `nil`.