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

ruby-changes:65584

From: Aaron <ko1@a...>
Date: Thu, 18 Mar 2021 02:55:54 +0900 (JST)
Subject: [ruby-changes:65584] 8359821870 (master): Use rb_fstring for "defined" strings.

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

From 8359821870d756eb75d66c5ddb5d119f6247c35d Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Tue, 16 Mar 2021 15:30:47 -0700
Subject: Use rb_fstring for "defined" strings.

We can take advantage of fstrings to de-duplicate the defined strings.
This means we don't need to keep the list of defined strings on the VM
(or register them as mark objects)
---
 insns.def |  4 ++--
 iseq.c    | 16 +---------------
 vm.c      |  4 ----
 vm_core.h |  1 -
 4 files changed, 3 insertions(+), 22 deletions(-)

diff --git a/insns.def b/insns.def
index 1dc0bb3..5704bf4 100644
--- a/insns.def
+++ b/insns.def
@@ -662,14 +662,14 @@ adjuststack https://github.com/ruby/ruby/blob/trunk/insns.def#L662
 /* defined? */
 DEFINE_INSN
 defined
-(rb_num_t op_type, VALUE obj, VALUE needstr)
+(rb_num_t op_type, VALUE obj, VALUE pushval)
 (VALUE v)
 (VALUE val)
 // attr bool leaf = leafness_of_defined(op_type);
 {
     val = Qnil;
     if (vm_defined(ec, GET_CFP(), op_type, obj, v)) {
-      val = needstr;
+      val = pushval;
     }
 }
 
diff --git a/iseq.c b/iseq.c
index f696df9..3624c5a 100644
--- a/iseq.c
+++ b/iseq.c
@@ -3103,24 +3103,10 @@ rb_iseq_defined_string(enum defined_type type) https://github.com/ruby/ruby/blob/trunk/iseq.c#L3103
 	"expression",
     };
     const char *estr;
-    VALUE *defs, str;
 
     if ((unsigned)(type - 1) >= (unsigned)numberof(expr_names)) rb_bug("unknown defined type %d", type);
     estr = expr_names[type - 1];
-    if (!estr[0]) return 0;
-    defs = GET_VM()->defined_strings;
-    if (!defs) {
-	defs = ruby_xcalloc(numberof(expr_names), sizeof(VALUE));
-	GET_VM()->defined_strings = defs;
-    }
-    str = defs[type-1];
-    if (!str) {
-	str = rb_str_new_cstr(estr);
-	OBJ_FREEZE(str);
-	defs[type-1] = str;
-	rb_gc_register_mark_object(str);
-    }
-    return str;
+    return rb_fstring_cstr(estr);
 }
 
 /* A map from encoded_insn to insn_data: decoded insn number, its len,
diff --git a/vm.c b/vm.c
index 6b8119b..1238ceb 100644
--- a/vm.c
+++ b/vm.c
@@ -2677,15 +2677,11 @@ ruby_vm_destruct(rb_vm_t *vm) https://github.com/ruby/ruby/blob/trunk/vm.c#L2677
 static size_t
 vm_memsize(const void *ptr)
 {
-    const rb_vm_t *vmobj = ptr;
     size_t size = sizeof(rb_vm_t);
 
     // TODO
     // size += vmobj->ractor_num * sizeof(rb_ractor_t);
 
-    if (vmobj->defined_strings) {
-	size += DEFINED_EXPR * sizeof(VALUE);
-    }
     return size;
 }
 
diff --git a/vm_core.h b/vm_core.h
index a7644eb..31ac4ac 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -650,7 +650,6 @@ typedef struct rb_vm_struct { https://github.com/ruby/ruby/blob/trunk/vm_core.h#L650
 
     rb_at_exit_list *at_exit;
 
-    VALUE *defined_strings;
     st_table *frozen_strings;
 
     const struct rb_builtin_function *builtin_function_table;
-- 
cgit v1.1


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

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