1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

array.c: factor out a complex condition of assert

ARY_SHARED_P and ARY_EMBED_P included:

   assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)),

The two predicate macros are used in many other assert conditions,
which caused memory bloat during C compilation.
This change factors out the assertion above to a function.
Now gcc consumes 160 MB instead of 250 MB to compile array.c.
This commit is contained in:
Yusuke Endoh 2019-07-20 09:08:34 +09:00
parent d304f77c58
commit 77bb79b8cf

10
array.c
View file

@ -40,14 +40,20 @@ should_be_T_ARRAY(VALUE ary)
return RB_TYPE_P(ary, T_ARRAY);
}
static int
should_not_be_shared_and_embedded(VALUE ary)
{
return !FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG);
}
#define ARY_SHARED_P(ary) \
(assert(should_be_T_ARRAY((VALUE)(ary))), \
assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
assert(should_not_be_shared_and_embedded((VALUE)ary)), \
FL_TEST_RAW((ary),ELTS_SHARED)!=0)
#define ARY_EMBED_P(ary) \
(assert(should_be_T_ARRAY((VALUE)(ary))), \
assert(!FL_TEST((ary), ELTS_SHARED) || !FL_TEST((ary), RARRAY_EMBED_FLAG)), \
assert(should_not_be_shared_and_embedded((VALUE)ary)), \
FL_TEST_RAW((ary), RARRAY_EMBED_FLAG) != 0)
#define ARY_HEAP_PTR(a) (assert(!ARY_EMBED_P(a)), RARRAY(a)->as.heap.ptr)