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

ruby-changes:59981

From: NagayamaRyoga <ko1@a...>
Date: Mon, 10 Feb 2020 01:33:52 +0900 (JST)
Subject: [ruby-changes:59981] e443f23576 (master): compile.c: Drop iseq_list from ibf_dump

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

From e443f23576686edac795e076ba964cbe1beef62f Mon Sep 17 00:00:00 2001
From: NagayamaRyoga <nagayama15@s...>
Date: Thu, 6 Feb 2020 21:31:28 +0900
Subject: compile.c: Drop iseq_list from ibf_dump

[Feature #16505]

diff --git a/compile.c b/compile.c
index 8b3d83e..6589470 100644
--- a/compile.c
+++ b/compile.c
@@ -9525,7 +9525,6 @@ struct ibf_dump_buffer { https://github.com/ruby/ruby/blob/trunk/compile.c#L9525
 };
 
 struct ibf_dump {
-    VALUE iseq_list;      /* [iseqs] */
     st_table *iseq_table; /* iseq -> iseq number */
     struct ibf_dump_buffer global_buffer;
     struct ibf_dump_buffer *current_buffer;
@@ -9647,7 +9646,7 @@ ibf_table_lookup(struct st_table *table, st_data_t key) https://github.com/ruby/ruby/blob/trunk/compile.c#L9646
 }
 
 static int
-ibf_table_index(struct st_table *table, st_data_t key)
+ibf_table_find_or_insert(struct st_table *table, st_data_t key)
 {
     int index = ibf_table_lookup(table, key);
 
@@ -9683,7 +9682,7 @@ ibf_dump_object(struct ibf_dump *dump, VALUE obj) https://github.com/ruby/ruby/blob/trunk/compile.c#L9682
 {
     int obj_index = ibf_table_lookup(dump->current_buffer->obj_table, (st_data_t)obj);
     if (obj_index < 0) {
-        obj_index = ibf_table_index(dump->current_buffer->obj_table, (st_data_t)obj);
+        obj_index = ibf_table_find_or_insert(dump->current_buffer->obj_table, (st_data_t)obj);
         rb_ary_push(dump->current_buffer->obj_list, obj);
     }
     return obj_index;
@@ -9725,12 +9724,7 @@ ibf_dump_iseq(struct ibf_dump *dump, const rb_iseq_t *iseq) https://github.com/ruby/ruby/blob/trunk/compile.c#L9724
         return -1;
     }
     else {
-        int iseq_index = ibf_table_lookup(dump->iseq_table, (st_data_t)iseq);
-        if (iseq_index < 0) {
-            iseq_index = ibf_table_index(dump->iseq_table, (st_data_t)iseq);
-            rb_ary_push(dump->iseq_list, (VALUE)iseq);
-        }
-        return iseq_index;
+        return ibf_table_find_or_insert(dump->iseq_table, (st_data_t)iseq);
     }
 }
 
@@ -10668,22 +10662,41 @@ ibf_load_iseq_each(struct ibf_load *load, rb_iseq_t *iseq, ibf_offset_t offset) https://github.com/ruby/ruby/blob/trunk/compile.c#L10662
     verify_call_cache(iseq);
 }
 
+struct ibf_dump_iseq_list_arg
+{
+    struct ibf_dump *dump;
+    VALUE offset_list;
+};
+
+static int
+ibf_dump_iseq_list_i(st_data_t key, st_data_t val, st_data_t ptr)
+{
+    const rb_iseq_t *iseq = (const rb_iseq_t *)key;
+    struct ibf_dump_iseq_list_arg *args = (struct ibf_dump_iseq_list_arg *)ptr;
+
+    ibf_offset_t offset = ibf_dump_iseq_each(args->dump, iseq);
+    rb_ary_push(args->offset_list, UINT2NUM(offset));
+
+    return ST_CONTINUE;
+}
+
 static void
 ibf_dump_iseq_list(struct ibf_dump *dump, struct ibf_header *header)
 {
-    VALUE list = rb_ary_tmp_new(RARRAY_LEN(dump->iseq_list));
-    long i;
+    VALUE offset_list = rb_ary_tmp_new(dump->iseq_table->num_entries);
 
-    for (i = 0; i < RARRAY_LEN(dump->iseq_list); i++) {
-        ibf_offset_t offset = ibf_dump_iseq_each(dump, (rb_iseq_t *)RARRAY_AREF(dump->iseq_list, i));
-        rb_ary_push(list, UINT2NUM(offset));
-    }
+    struct ibf_dump_iseq_list_arg args;
+    args.dump = dump;
+    args.offset_list = offset_list;
+
+    st_foreach(dump->iseq_table, ibf_dump_iseq_list_i, (st_data_t)&args);
 
-    long size = RARRAY_LEN(dump->iseq_list);
+    st_index_t i;
+    st_index_t size = dump->iseq_table->num_entries;
     ibf_offset_t *offsets = ALLOCA_N(ibf_offset_t, size);
 
     for (i = 0; i < size; i++) {
-        offsets[i] = NUM2UINT(RARRAY_AREF(list, i));
+        offsets[i] = NUM2UINT(RARRAY_AREF(offset_list, i));
     }
 
     ibf_dump_align(dump, sizeof(ibf_offset_t));
@@ -11335,7 +11348,8 @@ ibf_dump_mark(void *ptr) https://github.com/ruby/ruby/blob/trunk/compile.c#L11348
     struct ibf_dump *dump = (struct ibf_dump *)ptr;
     rb_gc_mark(dump->global_buffer.str);
     rb_gc_mark(dump->global_buffer.obj_list);
-    rb_gc_mark(dump->iseq_list);
+
+    rb_mark_set(dump->iseq_table);
 }
 
 static void
@@ -11372,7 +11386,8 @@ static const rb_data_type_t ibf_dump_type = { https://github.com/ruby/ruby/blob/trunk/compile.c#L11386
 static void
 ibf_dump_setup(struct ibf_dump *dump, VALUE dumper_obj)
 {
-    RB_OBJ_WRITE(dumper_obj, &dump->iseq_list, rb_ary_tmp_new(0));
+    dump->iseq_table = NULL;
+
     RB_OBJ_WRITE(dumper_obj, &dump->global_buffer.obj_list, ibf_dump_object_list_new(&dump->global_buffer.obj_table));
     RB_OBJ_WRITE(dumper_obj, &dump->global_buffer.str, rb_str_new(0, 0));
     dump->iseq_table = st_init_numtable(); /* need free */
-- 
cgit v0.10.2


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

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