[前][次][番号順一覧][スレッド一覧]

ruby-changes:73498

From: Kazuki <ko1@a...>
Date: Fri, 9 Sep 2022 16:03:38 +0900 (JST)
Subject: [ruby-changes:73498] aff6534e32 (master): Avoid unnecessary copying when removing the leading part of a string

https://git.ruby-lang.org/ruby.git/commit/?id=aff6534e32

From aff6534e32b5e46036808ed0579d31a8dbad8190 Mon Sep 17 00:00:00 2001
From: Kazuki Yamaguchi <k@r...>
Date: Thu, 8 Sep 2022 22:12:02 +0900
Subject: Avoid unnecessary copying when removing the leading part of a string

Remove the superfluous str_modify_keep_cr() call from rb_str_update().
It ends up calling either rb_str_drop_bytes() or rb_str_splice_0(),
which already does checks if necessary.

The extra call makes the string "independent". This is not always
wanted, in other words, it can keep the same shared root when merely
removing the leading part of a shared string.
---
 string.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/string.c b/string.c
index 963652cdb9..c9ec827708 100644
--- a/string.c
+++ b/string.c
@@ -5359,7 +5359,6 @@ rb_str_update(VALUE str, long beg, long len, VALUE val) https://github.com/ruby/ruby/blob/trunk/string.c#L5359
     if (len > slen - beg) {
         len = slen - beg;
     }
-    str_modify_keep_cr(str);
     p = str_nth(RSTRING_PTR(str), RSTRING_END(str), beg, enc, singlebyte);
     if (!p) p = RSTRING_END(str);
     e = str_nth(p, RSTRING_END(str), len, enc, singlebyte);
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]