Ruby
2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
|
Go to the documentation of this file.
25 #define id_each idEach
28 #define id_lshift idLTLT
29 #define id_call idCall
30 #define id_size idSize
40 #define ENUM_WANT_SVALUE() do { \
41 i = rb_enum_values_pack(argc, argv); \
55 enum_yield_array(
VALUE ary)
145 #define COUNT_BIGNUM IMEMO_FL_USER0
146 #define MEMO_V3_SET(m, v) RB_OBJ_WRITE((m), &(m)->u3.value, (v))
149 imemo_count_up(
struct MEMO *memo)
154 else if (++memo->
u3.
cnt == 0) {
156 unsigned long buf[2] = {0, 1};
163 imemo_count_value(
struct MEMO *memo)
181 imemo_count_up(memo);
192 imemo_count_up(memo);
202 imemo_count_up(memo);
242 rb_warn(
"given block not used");
249 return imemo_count_value(memo);
305 if (!
NIL_P(if_none)) {
322 imemo_count_up(memo);
335 imemo_count_up(memo);
367 func = find_index_iter_i;
372 rb_warn(
"given block not used");
406 return ((
unsigned long)
n > limit) ? (
long)limit :
n;
862 op =
id ?
ID2SYM(
id) : init;
876 if (iter == inject_op_i &&
880 return ary_inject_op(
obj, init, op);
942 group = enum_yield(
argc,
i);
974 return enum_hashify(
obj, 0, 0, group_by_i);
1015 return enum_hashify(
obj, 0, 0, tally_i);
1055 return enum_take(
obj,
argv[0]);
1095 #define SORT_BY_BUFSIZE 16
1131 sort_by_cmp(
const void *ap,
const void *
bp,
void *data)
1138 if (
RBASIC(ary)->klass) {
1260 sort_by_cmp, (
void *)
ary));
1274 #define ENUMFUNC(name) argc ? name##_eqq : rb_block_given_p() ? name##_iter_i : name##_i
1276 #define MEMO_ENUM_NEW(v1) (rb_check_arity(argc, 0, 1), MEMO_NEW((v1), (argc ? *argv : 0), 0))
1278 #define DEFINE_ENUMFUNCS(name) \
1279 static VALUE enum_##name##_func(VALUE result, struct MEMO *memo); \
1282 name##_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \
1284 return enum_##name##_func(rb_enum_values_pack(argc, argv), MEMO_CAST(memo)); \
1288 name##_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \
1290 return enum_##name##_func(rb_yield_values2(argc, argv), MEMO_CAST(memo)); \
1294 name##_eqq(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \
1296 ENUM_WANT_SVALUE(); \
1297 return enum_##name##_func(rb_funcallv(MEMO_CAST(memo)->v2, id_eqq, 1, &i), MEMO_CAST(memo)); \
1301 enum_##name##_func(VALUE result, struct MEMO *memo)
1303 #define WARN_UNUSED_BLOCK(argc) do { \
1304 if ((argc) > 0 && rb_block_given_p()) { \
1305 rb_warn("given block not used"); \
1311 if (!
RTEST(result)) {
1353 if (
RTEST(result)) {
1395 if (
RTEST(result)) {
1423 data->
rev ?
"max" :
"min",
1424 data->
by ?
"_by" :
"");
1430 nmin_cmp(
const void *ap,
const void *
bp,
void *_data)
1435 #define rb_cmpint(cmp, a, b) rb_cmpint(cmpint_reenter_check(data, (cmp)), a, b)
1441 nmin_block_cmp(
const void *ap,
const void *
bp,
void *_data)
1446 cmpint_reenter_check(data, cmp);
1468 eltsize = data->
by ? 2 : 1;
1474 #define GETPTR(i) (beg+(i)*eltsize)
1476 #define SWAP(i, j) do { \
1478 memcpy(tmp, GETPTR(i), sizeof(VALUE)*eltsize); \
1479 memcpy(GETPTR(i), GETPTR(j), sizeof(VALUE)*eltsize); \
1480 memcpy(GETPTR(j), tmp, sizeof(VALUE)*eltsize); \
1484 long pivot_index = left + (right-left)/2;
1485 long num_pivots = 1;
1487 SWAP(pivot_index, right);
1488 pivot_index = right;
1492 while (
i <= right-num_pivots) {
1497 SWAP(
i, right-num_pivots);
1502 SWAP(
i, store_index);
1508 for (
i = right; right-num_pivots <
i;
i--) {
1515 if (store_index <=
n &&
n <= store_index+num_pivots)
1518 if (
n < store_index) {
1519 right = store_index-1;
1522 left = store_index+num_pivots;
1542 cmpv = enum_yield(
argc,
i);
1668 if (
RTEST(result)) {
1946 minmax_i_update(
i, j, memo);
1998 minmax_ii_update(
i, j, memo);
2031 minmax_ii_update(m->
last, m->
last, m);
2036 minmax_i_update(m->
last, m->
last, m);
2255 vi = enum_yield(
argc,
i);
2281 minmax_by_i_update(vi, vj,
i, j, memo);
2362 VALUE n = imemo_count_value(m);
2446 enum_yield(
argc,
i);
2503 #define dont_recycle_block_arg(arity) ((arity) == 1 || (arity) < 0)
2545 n = add_int(
size, slice_size-1);
2546 return div_int(
n, slice_size);
2620 n = add_int(
size, 1 - cons_size);
2696 struct MEMO *memo = (
struct MEMO *)memoval;
2715 if (
NIL_P(result)) {
2716 enum_yield_array(tmp);
2744 struct MEMO *memo = (
struct MEMO *)memoval;
2768 if (
NIL_P(result)) {
2769 enum_yield_array(tmp);
2927 if (memo->
u3.
cnt == 0) {
3016 enum_yield(
argc,
i);
3032 size = enum_size(
self, args, 0);
3077 if (
n <= 0)
return Qnil;
3084 while (
n < 0 || 0 < --
n) {
3120 else if (
NIL_P(
v) ||
v == separator) {
3261 enum_chunk(
VALUE enumerable)
3294 if (
RTEST(header_p)) {
3506 #define UPDATE_MEMO ((void)(memo = MEMO_FOR(struct sliceafter_arg, _memo)))
3630 #define UPDATE_MEMO ((void)(memo = MEMO_FOR(struct slicewhen_arg, _memo)))
3753 enum_slice_when(
VALUE enumerable)
3819 enum_chunk_while(
VALUE enumerable)
3846 const int unused = (
assert(memo !=
NULL), 0);
4064 return int_range_sum(beg, end, excl, memo.
v);
4070 hash_sum(
obj, &memo);
4147 #define rb_intern(str) rb_intern_const(str)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
VALUE rb_assoc_new(VALUE car, VALUE cdr)
VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, int min_argc, int max_argc, VALUE data2)
int(* cmpfunc)(const void *, const void *, void *)
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
void rb_warn(const char *fmt,...)
int rb_block_given_p(void)
Determines if the current method is given a block.
VALUE rb_hash_values(VALUE hash)
void rb_warning(const char *fmt,...)
#define RBASIC_CLEAR_CLASS(obj)
VALUE rb_hash_clear(VALUE hash)
#define NEW_PARTIAL_MEMO_FOR(type, value, member)
struct cmp_opt_data cmp_opt
#define dont_recycle_block_arg(arity)
VALUE rb_attr_get(VALUE, ID)
VALUE rb_hash_aref(VALUE hash, VALUE key)
VALUE rb_equal(VALUE, VALUE)
Same as Object#===, case equality.
VALUE rb_nmin_run(VALUE obj, VALUE num, int by, int rev, int ary)
VALUE rb_funcallv_public(VALUE, ID, int, const VALUE *)
Calls a method.
void rb_ary_store(VALUE ary, long idx, VALUE val)
#define RB_TYPE_P(obj, type)
VALUE rb_rational_plus(VALUE self, VALUE other)
#define FIXNUM_ZERO_P(num)
struct cmp_opt_data cmp_opt
VALUE rb_define_module(const char *name)
VALUE rb_int_ge(VALUE x, VALUE y)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
#define RARRAY_PTR_USE(ary, ptr_name, expr)
VALUE rb_ary_shift(VALUE ary)
#define MEMO_V1_SET(m, v)
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
#define RARRAY_ASET(a, i, v)
RUBY_EXTERN VALUE rb_cInteger
#define WARN_UNUSED_BLOCK(argc)
#define rb_cmpint(cmp, a, b)
#define RBASIC_SET_CLASS(obj, cls)
int rb_obj_respond_to(VALUE, ID, int)
VALUE rb_int_idiv(VALUE x, VALUE y)
int rb_respond_to(VALUE, ID)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ivar_get(VALUE, ID)
VALUE rb_enum_values_pack(int argc, const VALUE *argv)
VALUE rb_int_succ(VALUE num)
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
int rb_hash_add_new_element(VALUE hash, VALUE key, VALUE val)
VALUE rb_fix_plus(VALUE x, VALUE y)
VALUE rb_int_mul(VALUE x, VALUE y)
VALUE rb_ary_tmp_new(long capa)
VALUE rb_ary_sort_bang(VALUE ary)
#define NEW_MEMO_FOR(type, value)
VALUE rb_f_send(int argc, VALUE *argv, VALUE recv)
VALUE rb_ary_push(VALUE ary, VALUE item)
#define DEFINE_ENUMFUNCS(name)
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
VALUE rb_ary_concat(VALUE x, VALUE y)
#define MEMO_NEW(a, b, c)
#define RETURN_ENUMERATOR(obj, argc, argv)
#define RARRAY_AREF(a, i)
struct cmp_opt_data cmp_opt
VALUE rb_big_minus(VALUE x, VALUE y)
VALUE rb_ary_resize(VALUE ary, long len)
expands or shrinks ary to len elements.
void rb_hash_foreach(VALUE hash, rb_foreach_func *func, VALUE farg)
MJIT_STATIC void rb_error_arity(int argc, int min, int max)
#define MEMO_ENUM_NEW(v1)
#define RB_OBJ_WRITE(a, slot, b)
#define CONST_ID(var, str)
#define NEW_CMP_OPT_MEMO(type, value)
VALUE rb_check_array_type(VALUE ary)
VALUE rb_yield_values2(int n, const VALUE *argv)
VALUE rb_big_unpack(unsigned long *buf, long num_longs)
VALUE rb_ary_clear(VALUE ary)
#define ENUM_WANT_SVALUE()
VALUE rb_hash_set_pair(VALUE hash, VALUE arg)
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_ary_new_from_values(long n, const VALUE *elts)
#define OPTIMIZED_CMP(a, b, data)
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
#define STATIC_ID2SYM(id)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
double rb_num2dbl(VALUE)
Converts a Numeric object to double.
VALUE rb_big_plus(VALUE x, VALUE y)
VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE)
#define MEMO_FOR(type, value)
int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
void Init_Enumerable(void)
VALUE rb_ary_dup(VALUE ary)
VALUE rb_ivar_set(VALUE, ID, VALUE)
#define RBASIC_SET_CLASS_RAW(obj, cls)
VALUE rb_yield_force_blockarg(VALUE values)
#define RB_INTEGER_TYPE_P(obj)
VALUE rb_ary_reverse(VALUE ary)
#define MEMO_V2_SET(m, v)
double rb_big2dbl(VALUE x)
void ruby_qsort(void *, const size_t, const size_t, int(*)(const void *, const void *, void *), void *)
#define MEMO_V3_SET(m, v)
VALUE rb_int_plus(VALUE x, VALUE y)
#define UNREACHABLE_RETURN(val)
int rb_block_min_max_arity(int *max)
#define RB_FLOAT_TYPE_P(obj)
VALUE rb_int_minus(VALUE x, VALUE y)
VALUE rb_block_proc(void)