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

ruby-changes:68188

From: Nobuyoshi <ko1@a...>
Date: Fri, 1 Oct 2021 20:29:06 +0900 (JST)
Subject: [ruby-changes:68188] b6534691a1 (master): Copy path strings as interned strings

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

From b6534691a16d751d59fc572d5dddebcaeb21f007 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 28 Sep 2021 23:24:40 +0900
Subject: Copy path strings as interned strings

---
 ruby.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/ruby.c b/ruby.c
index c1f8aceb09..0d8c03ebf4 100644
--- a/ruby.c
+++ b/ruby.c
@@ -1677,6 +1677,13 @@ tty_enabled(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1677
 # define tty_enabled() 0
 #endif
 
+static VALUE
+copy_str(VALUE str, rb_encoding *enc, bool intern)
+{
+    if (!intern) return rb_enc_associate(rb_str_dup(str), enc);
+    return rb_enc_interned_str(RSTRING_PTR(str), RSTRING_LEN(str), enc);
+}
+
 static VALUE
 process_options(int argc, char **argv, ruby_cmdline_options_t *opt)
 {
@@ -1909,7 +1916,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1916
 	    if (newpath == path) continue;
 	    path = newpath;
 #else
-	    path = rb_enc_associate(rb_str_dup(path), lenc);
+	    path = copy_str(path, lenc, !mark);
 #endif
 	    if (mark) rb_ivar_set(path, id_initial_load_path_mark, path);
             if (!modifiable) {
@@ -1926,7 +1933,8 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) https://github.com/ruby/ruby/blob/trunk/ruby.c#L1933
         VALUE loaded_features = vm->loaded_features;
         for (long i = loaded_before_enc; i < RARRAY_LEN(loaded_features); ++i) {
 	    VALUE path = RARRAY_AREF(loaded_features, i);
-	    path = rb_enc_associate(rb_str_dup(path), IF_UTF8_PATH(uenc, lenc));
+            if (rb_enc_get(path) == IF_UTF8_PATH(uenc, lenc)) continue;
+            path = copy_str(path, IF_UTF8_PATH(uenc, lenc), true);
 	    RARRAY_ASET(loaded_features, i, path);
         }
         rb_get_expanded_load_path();
-- 
cgit v1.2.1


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

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