mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
RARRAY_AREF: convert into an inline function
RARRAY_AREF has been a macro for reasons. We might not be able to change that for public APIs, but why not relax the situation internally to make it an inline function.
This commit is contained in:
parent
72d0f2f0e0
commit
ff30358d13
Notes:
git
2020-08-15 12:09:51 +09:00
12 changed files with 34 additions and 17 deletions
2
array.c
2
array.c
|
@ -7221,7 +7221,7 @@ rb_ary_sample(rb_execution_context_t *ec, VALUE ary, VALUE randgen, VALUE nv, VA
|
||||||
return rb_ary_new_capa(0);
|
return rb_ary_new_capa(0);
|
||||||
case 1:
|
case 1:
|
||||||
i = rnds[0];
|
i = rnds[0];
|
||||||
return rb_ary_new_from_values(1, &RARRAY_AREF(ary, i));
|
return rb_ary_new_from_args(1, RARRAY_AREF(ary, i));
|
||||||
case 2:
|
case 2:
|
||||||
i = rnds[0];
|
i = rnds[0];
|
||||||
j = rnds[1];
|
j = rnds[1];
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "internal/array.h"
|
||||||
#include "internal/class.h"
|
#include "internal/class.h"
|
||||||
#include "internal/complex.h"
|
#include "internal/complex.h"
|
||||||
#include "internal/math.h"
|
#include "internal/math.h"
|
||||||
|
|
1
dir.c
1
dir.c
|
@ -105,6 +105,7 @@ char *strchr(char*,char);
|
||||||
#include "encindex.h"
|
#include "encindex.h"
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "internal/array.h"
|
||||||
#include "internal/dir.h"
|
#include "internal/dir.h"
|
||||||
#include "internal/encoding.h"
|
#include "internal/encoding.h"
|
||||||
#include "internal/error.h"
|
#include "internal/error.h"
|
||||||
|
|
|
@ -2087,7 +2087,8 @@ lazy_flat_map_proc(VALUE proc_entry, struct MEMO *result, VALUE memos, long memo
|
||||||
long i;
|
long i;
|
||||||
LAZY_MEMO_RESET_BREAK(result);
|
LAZY_MEMO_RESET_BREAK(result);
|
||||||
for (i = 0; i + 1 < RARRAY_LEN(ary); i++) {
|
for (i = 0; i + 1 < RARRAY_LEN(ary); i++) {
|
||||||
lazy_yielder_yield(result, proc_index, 1, &RARRAY_AREF(ary, i));
|
const VALUE argv = RARRAY_AREF(ary, i);
|
||||||
|
lazy_yielder_yield(result, proc_index, 1, &argv);
|
||||||
}
|
}
|
||||||
if (break_p) LAZY_MEMO_SET_BREAK(result);
|
if (break_p) LAZY_MEMO_SET_BREAK(result);
|
||||||
if (i >= RARRAY_LEN(ary)) return 0;
|
if (i >= RARRAY_LEN(ary)) return 0;
|
||||||
|
|
|
@ -256,20 +256,15 @@ RARRAY_ASET(VALUE ary, long i, VALUE v)
|
||||||
RB_OBJ_WRITE(ary, &ptr[i], v));
|
RB_OBJ_WRITE(ary, &ptr[i], v));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RARRAY_AREF is used as a lvalue. Cannot be a function. */
|
/*
|
||||||
#if 0
|
* :FIXME: we want to convert RARRAY_AREF into an inline function (to add rooms
|
||||||
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
|
* for more sanity checks). However there were situations where the address of
|
||||||
RBIMPL_ATTR_ARTIFICIAL()
|
* this macro is taken i.e. &RARRAY_AREF(...). They cannot be possible if this
|
||||||
static inline VALUE
|
* is not a macro. Such usages are abuse, and we eliminated them internally.
|
||||||
RARRAY_AREF(VALUE ary, long i)
|
* However we are afraid of similar things to remain in the wild. This macro
|
||||||
{
|
* remains as it is due to that. If we could warn such usages we can set a
|
||||||
RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
|
* transition path, but currently no way is found to do so.
|
||||||
|
*/
|
||||||
return RARRAY_CONST_PTR_TRANSIENT(ary)[i];
|
#define RARRAY_AREF(a, i) RARRAY_CONST_PTR_TRANSIENT(a)[i]
|
||||||
}
|
|
||||||
#else
|
|
||||||
# undef RARRAY_AREF
|
|
||||||
# define RARRAY_AREF(a, i) RARRAY_CONST_PTR_TRANSIENT(a)[i]
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* RBIMPL_RARRAY_H */
|
#endif /* RBIMPL_RARRAY_H */
|
||||||
|
|
|
@ -31,6 +31,9 @@
|
||||||
/* Following macros were formerly defined in this header but moved to somewhere
|
/* Following macros were formerly defined in this header but moved to somewhere
|
||||||
* else. In order to detect them we undef here. */
|
* else. In order to detect them we undef here. */
|
||||||
|
|
||||||
|
/* internal/array.h */
|
||||||
|
#undef RARRAY_AREF
|
||||||
|
|
||||||
/* internal/class.h */
|
/* internal/class.h */
|
||||||
#undef RClass
|
#undef RClass
|
||||||
#undef RCLASS_SUPER
|
#undef RCLASS_SUPER
|
||||||
|
|
|
@ -100,4 +100,15 @@ RARY_TRANSIENT_UNSET(VALUE ary)
|
||||||
})
|
})
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#undef RARRAY_AREF
|
||||||
|
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
|
||||||
|
RBIMPL_ATTR_ARTIFICIAL()
|
||||||
|
static inline VALUE
|
||||||
|
RARRAY_AREF(VALUE ary, long i)
|
||||||
|
{
|
||||||
|
RBIMPL_ASSERT_TYPE(ary, RUBY_T_ARRAY);
|
||||||
|
|
||||||
|
return RARRAY_CONST_PTR_TRANSIENT(ary)[i];
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* INTERNAL_ARRAY_H */
|
#endif /* INTERNAL_ARRAY_H */
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "encindex.h"
|
#include "encindex.h"
|
||||||
#include "id_table.h"
|
#include "id_table.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "internal/array.h"
|
||||||
#include "internal/bignum.h"
|
#include "internal/bignum.h"
|
||||||
#include "internal/class.h"
|
#include "internal/class.h"
|
||||||
#include "internal/encoding.h"
|
#include "internal/encoding.h"
|
||||||
|
|
1
pack.c
1
pack.c
|
@ -17,6 +17,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "internal/array.h"
|
||||||
#include "internal/bits.h"
|
#include "internal/bits.h"
|
||||||
#include "internal/string.h"
|
#include "internal/string.h"
|
||||||
#include "internal/symbol.h"
|
#include "internal/symbol.h"
|
||||||
|
|
1
random.c
1
random.c
|
@ -56,6 +56,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "internal/array.h"
|
||||||
#include "internal/compilers.h"
|
#include "internal/compilers.h"
|
||||||
#include "internal/numeric.h"
|
#include "internal/numeric.h"
|
||||||
#include "internal/random.h"
|
#include "internal/random.h"
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "internal/array.h"
|
||||||
#include "internal/complex.h"
|
#include "internal/complex.h"
|
||||||
#include "internal/gc.h"
|
#include "internal/gc.h"
|
||||||
#include "internal/numeric.h"
|
#include "internal/numeric.h"
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
#include "internal/array.h"
|
||||||
#include "internal/inits.h"
|
#include "internal/inits.h"
|
||||||
#include "internal/object.h"
|
#include "internal/object.h"
|
||||||
#include "internal/string.h"
|
#include "internal/string.h"
|
||||||
|
|
Loading…
Reference in a new issue