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

ruby-changes:72218

From: Nobuyoshi <ko1@a...>
Date: Fri, 17 Jun 2022 23:27:33 +0900 (JST)
Subject: [ruby-changes:72218] 7f05f7378d (master): Reuse an interned string

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

From 7f05f7378d3dea53796338346970faa5594aa8ed Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 17 Jun 2022 23:27:16 +0900
Subject: Reuse an interned string

Repeating to intern the same string is just redundant, as interned
strings for the same content are always the same object until it gets
collected.
---
 iseq.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/iseq.c b/iseq.c
index 42cf9a2fa6..88e8cf9349 100644
--- a/iseq.c
+++ b/iseq.c
@@ -1215,6 +1215,7 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, V https://github.com/ruby/ruby/blob/trunk/iseq.c#L1215
     rb_ast_t *(*parse)(VALUE vparser, VALUE fname, VALUE file, int start);
     int ln;
     rb_ast_t *INITIALIZED ast;
+    VALUE name = rb_fstring_lit("<compiled>");
 
     /* safe results first */
     make_compile_option(&option, opt);
@@ -1229,7 +1230,6 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, V https://github.com/ruby/ruby/blob/trunk/iseq.c#L1230
     }
     {
 	const VALUE parser = rb_parser_new();
-        VALUE name = rb_fstring_lit("<compiled>");
         const rb_iseq_t *outer_scope = rb_iseq_new(NULL, name, name, Qnil, 0, ISEQ_TYPE_TOP);
         VALUE outer_scope_v = (VALUE)outer_scope;
         rb_parser_set_context(parser, outer_scope, FALSE);
@@ -1242,8 +1242,7 @@ rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE realpath, VALUE line, V https://github.com/ruby/ruby/blob/trunk/iseq.c#L1242
 	rb_exc_raise(GET_EC()->errinfo);
     }
     else {
-	INITIALIZED VALUE label = rb_fstring_lit("<compiled>");
-	iseq = rb_iseq_new_with_opt(&ast->body, label, file, realpath, line,
+	iseq = rb_iseq_new_with_opt(&ast->body, name, file, realpath, line,
 				    NULL, 0, ISEQ_TYPE_TOP, &option);
 	rb_ast_dispose(ast);
     }
-- 
cgit v1.2.1


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

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