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

ruby-changes:56599

From: Yusuke <ko1@a...>
Date: Fri, 19 Jul 2019 23:45:37 +0900 (JST)
Subject: [ruby-changes:56599] Yusuke Endoh: 3e8d4ff3e5 (master): array.c: factor out `assert(RB_TYPE_P(ary, T_ARRAY))` to a function

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

From 3e8d4ff3e571bd556898efd94badb66a5dadf4d2 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Fri, 19 Jul 2019 23:41:24 +0900
Subject: array.c: factor out `assert(RB_TYPE_P(ary, T_ARRAY))` to a function

The assertion blows up gcc 8 by consuming approx. 1.8 GB memory.
This change reduces the amount of memory required to about 200 MB.

A follow-up of ae750799c1b28b06d02e50cd26450b9903516526.

diff --git a/array.c b/array.c
index ffeb884..a4652e6 100644
--- a/array.c
+++ b/array.c
@@ -34,13 +34,19 @@ VALUE rb_cArray; https://github.com/ruby/ruby/blob/trunk/array.c#L34
 #define ARY_MAX_SIZE (LONG_MAX / (int)sizeof(VALUE))
 #define SMALL_ARRAY_LEN 16
 
+static void
+assert_T_ARRAY(VALUE ary)
+{
+    assert(RB_TYPE_P(ary, T_ARRAY));
+}
+
 #define ARY_SHARED_P(ary) \
-  (assert(RB_TYPE_P((VALUE)(ary), T_ARRAY)), \
+  (assert_T_ARRAY((VALUE)(ary)), \
    assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
    FL_TEST_RAW((ary),ELTS_SHARED)!=0)
 
 #define ARY_EMBED_P(ary) \
-  (assert(RB_TYPE_P((VALUE)(ary), T_ARRAY)), \
+  (assert_T_ARRAY((VALUE)(ary)), \
    assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
    FL_TEST_RAW((ary), RARRAY_EMBED_FLAG) != 0)
 
@@ -56,7 +62,7 @@ VALUE rb_cArray; https://github.com/ruby/ruby/blob/trunk/array.c#L62
 	 (RARRAY_EMBED_LEN_MASK >> RARRAY_EMBED_LEN_SHIFT)))
 #define ARY_HEAP_SIZE(a) (assert(!ARY_EMBED_P(a)), assert(ARY_OWNS_HEAP_P(a)), ARY_CAPA(a) * sizeof(VALUE))
 
-#define ARY_OWNS_HEAP_P(a) (assert(RB_TYPE_P((a), T_ARRAY)), \
+#define ARY_OWNS_HEAP_P(a) (assert_T_ARRAY((VALUE)(a)), \
                             !FL_TEST_RAW((a), ELTS_SHARED|RARRAY_EMBED_FLAG))
 
 #define FL_SET_EMBED(a) do { \
@@ -132,7 +138,7 @@ VALUE rb_cArray; https://github.com/ruby/ruby/blob/trunk/array.c#L138
     RB_OBJ_WRITE(_ary_, &RARRAY(_ary_)->as.heap.aux.shared_root, _value_); \
 } while (0)
 #define RARRAY_SHARED_ROOT_FLAG FL_USER5
-#define ARY_SHARED_ROOT_P(ary) (assert(RB_TYPE_P((ary), T_ARRAY)), \
+#define ARY_SHARED_ROOT_P(ary) (assert_T_ARRAY((VALUE)(ary)), \
                                 FL_TEST_RAW((ary), RARRAY_SHARED_ROOT_FLAG))
 #define ARY_SHARED_ROOT_REFCNT(ary) \
     (assert(ARY_SHARED_ROOT_P(ary)), RARRAY(ary)->as.heap.aux.capa)
-- 
cgit v0.10.2


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

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