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

ruby-changes:57005

From: Aaron <ko1@a...>
Date: Tue, 13 Aug 2019 23:01:08 +0900 (JST)
Subject: [ruby-changes:57005] Aaron Patterson: dd1344b81e (master): Add compaction callbacks for Enumerator

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

From dd1344b81eeff9805067e633f60107f4019fa019 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <tenderlove@r...>
Date: Mon, 12 Aug 2019 17:00:34 -0400
Subject: Add compaction callbacks for Enumerator

This commit gives Enumerator compaction support

diff --git a/enumerator.c b/enumerator.c
index 11c863a..04593cc 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -178,15 +178,30 @@ static void https://github.com/ruby/ruby/blob/trunk/enumerator.c#L178
 enumerator_mark(void *p)
 {
     struct enumerator *ptr = p;
-    rb_gc_mark(ptr->obj);
-    rb_gc_mark(ptr->args);
-    rb_gc_mark(ptr->fib);
-    rb_gc_mark(ptr->dst);
-    rb_gc_mark(ptr->lookahead);
-    rb_gc_mark(ptr->feedvalue);
-    rb_gc_mark(ptr->stop_exc);
-    rb_gc_mark(ptr->size);
-    rb_gc_mark(ptr->procs);
+    rb_gc_mark_movable(ptr->obj);
+    rb_gc_mark_movable(ptr->args);
+    rb_gc_mark_movable(ptr->fib);
+    rb_gc_mark_movable(ptr->dst);
+    rb_gc_mark_movable(ptr->lookahead);
+    rb_gc_mark_movable(ptr->feedvalue);
+    rb_gc_mark_movable(ptr->stop_exc);
+    rb_gc_mark_movable(ptr->size);
+    rb_gc_mark_movable(ptr->procs);
+}
+
+static void
+enumerator_compact(void *p)
+{
+    struct enumerator *ptr = p;
+    ptr->obj = rb_gc_location(ptr->obj);
+    ptr->args = rb_gc_location(ptr->args);
+    ptr->fib = rb_gc_location(ptr->fib);
+    ptr->dst = rb_gc_location(ptr->dst);
+    ptr->lookahead = rb_gc_location(ptr->lookahead);
+    ptr->feedvalue = rb_gc_location(ptr->feedvalue);
+    ptr->stop_exc = rb_gc_location(ptr->stop_exc);
+    ptr->size = rb_gc_location(ptr->size);
+    ptr->procs = rb_gc_location(ptr->procs);
 }
 
 #define enumerator_free RUBY_TYPED_DEFAULT_FREE
@@ -203,6 +218,7 @@ static const rb_data_type_t enumerator_data_type = { https://github.com/ruby/ruby/blob/trunk/enumerator.c#L218
 	enumerator_mark,
 	enumerator_free,
 	enumerator_memsize,
+	enumerator_compact,
     },
     0, 0, RUBY_TYPED_FREE_IMMEDIATELY
 };
@@ -223,8 +239,16 @@ static void https://github.com/ruby/ruby/blob/trunk/enumerator.c#L239
 proc_entry_mark(void *p)
 {
     struct proc_entry *ptr = p;
-    rb_gc_mark(ptr->proc);
-    rb_gc_mark(ptr->memo);
+    rb_gc_mark_movable(ptr->proc);
+    rb_gc_mark_movable(ptr->memo);
+}
+
+static void
+proc_entry_compact(void *p)
+{
+    struct proc_entry *ptr = p;
+    ptr->proc = rb_gc_location(ptr->proc);
+    ptr->memo = rb_gc_location(ptr->memo);
 }
 
 #define proc_entry_free RUBY_TYPED_DEFAULT_FREE
@@ -241,6 +265,7 @@ static const rb_data_type_t proc_entry_data_type = { https://github.com/ruby/ruby/blob/trunk/enumerator.c#L265
 	proc_entry_mark,
 	proc_entry_free,
 	proc_entry_memsize,
+	proc_entry_compact,
     },
 };
 
@@ -1197,7 +1222,14 @@ static void https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1222
 yielder_mark(void *p)
 {
     struct yielder *ptr = p;
-    rb_gc_mark(ptr->proc);
+    rb_gc_mark_movable(ptr->proc);
+}
+
+static void
+yielder_compact(void *p)
+{
+    struct yielder *ptr = p;
+    ptr->proc = rb_gc_location(ptr->proc);
 }
 
 #define yielder_free RUBY_TYPED_DEFAULT_FREE
@@ -1214,6 +1246,7 @@ static const rb_data_type_t yielder_data_type = { https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1246
 	yielder_mark,
 	yielder_free,
 	yielder_memsize,
+	yielder_compact,
     },
     0, 0, RUBY_TYPED_FREE_IMMEDIATELY
 };
@@ -1327,8 +1360,16 @@ static void https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1360
 generator_mark(void *p)
 {
     struct generator *ptr = p;
-    rb_gc_mark(ptr->proc);
-    rb_gc_mark(ptr->obj);
+    rb_gc_mark_movable(ptr->proc);
+    rb_gc_mark_movable(ptr->obj);
+}
+
+static void
+generator_compact(void *p)
+{
+    struct generator *ptr = p;
+    ptr->proc = rb_gc_location(ptr->proc);
+    ptr->obj = rb_gc_location(ptr->obj);
 }
 
 #define generator_free RUBY_TYPED_DEFAULT_FREE
@@ -1345,6 +1386,7 @@ static const rb_data_type_t generator_data_type = { https://github.com/ruby/ruby/blob/trunk/enumerator.c#L1386
 	generator_mark,
 	generator_free,
 	generator_memsize,
+	generator_compact,
     },
     0, 0, RUBY_TYPED_FREE_IMMEDIATELY
 };
@@ -2673,7 +2715,14 @@ static void https://github.com/ruby/ruby/blob/trunk/enumerator.c#L2715
 enum_chain_mark(void *p)
 {
     struct enum_chain *ptr = p;
-    rb_gc_mark(ptr->enums);
+    rb_gc_mark_movable(ptr->enums);
+}
+
+static void
+enum_chain_compact(void *p)
+{
+    struct enum_chain *ptr = p;
+    ptr->enums = rb_gc_location(ptr->enums);
 }
 
 #define enum_chain_free RUBY_TYPED_DEFAULT_FREE
@@ -2690,6 +2739,7 @@ static const rb_data_type_t enum_chain_data_type = { https://github.com/ruby/ruby/blob/trunk/enumerator.c#L2739
         enum_chain_mark,
         enum_chain_free,
         enum_chain_memsize,
+        enum_chain_compact,
     },
     0, 0, RUBY_TYPED_FREE_IMMEDIATELY
 };
-- 
cgit v0.10.2


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

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