summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2022-07-21 09:23:58 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2022-07-21 09:42:04 -0700
commit5b21e94bebed90180d8ff63dad03b8b948361089 (patch)
treef9f7196d84b51b7a3a8001658e4391a63b71c396 /enumerator.c
parent3ff53c8e04ecc91e0190de6d5950ecce2a2ea188 (diff)
downloadruby-5b21e94bebed90180d8ff63dad03b8b948361089.tar.gz
Expand tabs [ci skip]
[Misc #18891]
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c442
1 files changed, 221 insertions, 221 deletions
diff --git a/enumerator.c b/enumerator.c
index be469ee38b..89abf4b888 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -240,9 +240,9 @@ enumerator_memsize(const void *p)
static const rb_data_type_t enumerator_data_type = {
"enumerator",
{
- enumerator_mark,
- enumerator_free,
- enumerator_memsize,
+ enumerator_mark,
+ enumerator_free,
+ enumerator_memsize,
enumerator_compact,
},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
@@ -255,7 +255,7 @@ enumerator_ptr(VALUE obj)
TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, ptr);
if (!ptr || ptr->obj == Qundef) {
- rb_raise(rb_eArgError, "uninitialized enumerator");
+ rb_raise(rb_eArgError, "uninitialized enumerator");
}
return ptr;
}
@@ -287,9 +287,9 @@ proc_entry_memsize(const void *p)
static const rb_data_type_t proc_entry_data_type = {
"proc_entry",
{
- proc_entry_mark,
- proc_entry_free,
- proc_entry_memsize,
+ proc_entry_mark,
+ proc_entry_free,
+ proc_entry_memsize,
proc_entry_compact,
},
};
@@ -371,12 +371,12 @@ obj_to_enum(int argc, VALUE *argv, VALUE obj)
VALUE enumerator, meth = sym_each;
if (argc > 0) {
- --argc;
- meth = *argv++;
+ --argc;
+ meth = *argv++;
}
enumerator = rb_enumeratorize_with_size(obj, meth, argc, argv, 0);
if (rb_block_given_p()) {
- enumerator_ptr(enumerator)->size = rb_block_proc();
+ enumerator_ptr(enumerator)->size = rb_block_proc();
}
return enumerator;
}
@@ -402,7 +402,7 @@ enumerator_init(VALUE enum_obj, VALUE obj, VALUE meth, int argc, const VALUE *ar
TypedData_Get_Struct(enum_obj, struct enumerator, &enumerator_data_type, ptr);
if (!ptr) {
- rb_raise(rb_eArgError, "unallocated enumerator");
+ rb_raise(rb_eArgError, "unallocated enumerator");
}
ptr->obj = obj;
@@ -482,14 +482,14 @@ enumerator_init_copy(VALUE obj, VALUE orig)
if (!OBJ_INIT_COPY(obj, orig)) return obj;
ptr0 = enumerator_ptr(orig);
if (ptr0->fib) {
- /* Fibers cannot be copied */
- rb_raise(rb_eTypeError, "can't copy execution context");
+ /* Fibers cannot be copied */
+ rb_raise(rb_eTypeError, "can't copy execution context");
}
TypedData_Get_Struct(obj, struct enumerator, &enumerator_data_type, ptr1);
if (!ptr1) {
- rb_raise(rb_eArgError, "unallocated enumerator");
+ rb_raise(rb_eArgError, "unallocated enumerator");
}
ptr1->obj = ptr0->obj;
@@ -547,8 +547,8 @@ enumerator_block_call(VALUE obj, rb_block_call_func *func, VALUE arg)
ID meth = e->meth;
if (e->args) {
- argc = RARRAY_LENINT(e->args);
- argv = RARRAY_CONST_PTR(e->args);
+ argc = RARRAY_LENINT(e->args);
+ argv = RARRAY_CONST_PTR(e->args);
}
return rb_block_call_kw(e->obj, meth, argc, argv, func, arg, e->kw_splat);
}
@@ -593,20 +593,20 @@ static VALUE
enumerator_each(int argc, VALUE *argv, VALUE obj)
{
if (argc > 0) {
- struct enumerator *e = enumerator_ptr(obj = rb_obj_dup(obj));
- VALUE args = e->args;
- if (args) {
+ struct enumerator *e = enumerator_ptr(obj = rb_obj_dup(obj));
+ VALUE args = e->args;
+ if (args) {
#if SIZEOF_INT < SIZEOF_LONG
- /* check int range overflow */
- rb_long2int(RARRAY_LEN(args) + argc);
+ /* check int range overflow */
+ rb_long2int(RARRAY_LEN(args) + argc);
#endif
- args = rb_ary_dup(args);
- rb_ary_cat(args, argv, argc);
- }
- else {
- args = rb_ary_new4(argc, argv);
- }
- e->args = args;
+ args = rb_ary_dup(args);
+ rb_ary_cat(args, argv, argc);
+ }
+ else {
+ args = rb_ary_new4(argc, argv);
+ }
+ e->args = args;
e->size = Qnil;
e->size_fn = 0;
}
@@ -622,7 +622,7 @@ enumerator_with_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, m))
MEMO_V1_SET(memo, rb_int_succ(idx));
if (argc <= 1)
- return rb_yield_values(2, val, idx);
+ return rb_yield_values(2, val, idx);
return rb_yield_values(2, rb_ary_new4(argc, argv), idx);
}
@@ -679,7 +679,7 @@ static VALUE
enumerator_with_object_i(RB_BLOCK_CALL_FUNC_ARGLIST(val, memo))
{
if (argc <= 1)
- return rb_yield_values(2, val, memo);
+ return rb_yield_values(2, val, memo);
return rb_yield_values(2, rb_ary_new4(argc, argv), memo);
}
@@ -764,21 +764,21 @@ get_next_values(VALUE obj, struct enumerator *e)
VALUE curr, vs;
if (e->stop_exc)
- rb_exc_raise(e->stop_exc);
+ rb_exc_raise(e->stop_exc);
curr = rb_fiber_current();
if (!e->fib || !rb_fiber_alive_p(e->fib)) {
- next_init(obj, e);
+ next_init(obj, e);
}
vs = rb_fiber_resume(e->fib, 1, &curr);
if (e->stop_exc) {
- e->fib = 0;
- e->dst = Qnil;
- e->lookahead = Qundef;
- e->feedvalue = Qundef;
- rb_exc_raise(e->stop_exc);
+ e->fib = 0;
+ e->dst = Qnil;
+ e->lookahead = Qundef;
+ e->feedvalue = Qundef;
+ rb_exc_raise(e->stop_exc);
}
return vs;
}
@@ -1020,7 +1020,7 @@ enumerator_feed(VALUE obj, VALUE v)
struct enumerator *e = enumerator_ptr(obj);
if (e->feedvalue != Qundef) {
- rb_raise(rb_eTypeError, "feed value already set");
+ rb_raise(rb_eTypeError, "feed value already set");
}
e->feedvalue = v;
@@ -1065,36 +1065,36 @@ inspect_enumerator(VALUE obj, VALUE dummy, int recur)
cname = rb_obj_class(obj);
if (!e || e->obj == Qundef) {
- return rb_sprintf("#<%"PRIsVALUE": uninitialized>", rb_class_path(cname));
+ return rb_sprintf("#<%"PRIsVALUE": uninitialized>", rb_class_path(cname));
}
if (recur) {
- str = rb_sprintf("#<%"PRIsVALUE": ...>", rb_class_path(cname));
- return str;
+ str = rb_sprintf("#<%"PRIsVALUE": ...>", rb_class_path(cname));
+ return str;
}
if (e->procs) {
- long i;
-
- eobj = generator_ptr(e->obj)->obj;
- /* In case procs chained enumerator traversing all proc entries manually */
- if (rb_obj_class(eobj) == cname) {
- str = rb_inspect(eobj);
- }
- else {
- str = rb_sprintf("#<%"PRIsVALUE": %+"PRIsVALUE">", rb_class_path(cname), eobj);
- }
- for (i = 0; i < RARRAY_LEN(e->procs); i++) {
- str = rb_sprintf("#<%"PRIsVALUE": %"PRIsVALUE, cname, str);
- append_method(RARRAY_AREF(e->procs, i), str, e->meth, e->args);
- rb_str_buf_cat2(str, ">");
- }
- return str;
+ long i;
+
+ eobj = generator_ptr(e->obj)->obj;
+ /* In case procs chained enumerator traversing all proc entries manually */
+ if (rb_obj_class(eobj) == cname) {
+ str = rb_inspect(eobj);
+ }
+ else {
+ str = rb_sprintf("#<%"PRIsVALUE": %+"PRIsVALUE">", rb_class_path(cname), eobj);
+ }
+ for (i = 0; i < RARRAY_LEN(e->procs); i++) {
+ str = rb_sprintf("#<%"PRIsVALUE": %"PRIsVALUE, cname, str);
+ append_method(RARRAY_AREF(e->procs, i), str, e->meth, e->args);
+ rb_str_buf_cat2(str, ">");
+ }
+ return str;
}
eobj = rb_attr_get(obj, id_receiver);
if (NIL_P(eobj)) {
- eobj = e->obj;
+ eobj = e->obj;
}
/* (1..100).each_cons(2) => "#<Enumerator: 1..100:each_cons(2)>" */
@@ -1129,48 +1129,48 @@ append_method(VALUE obj, VALUE str, ID default_method, VALUE default_args)
method = rb_attr_get(obj, id_method);
if (method != Qfalse) {
- if (!NIL_P(method)) {
- Check_Type(method, T_SYMBOL);
- method = rb_sym2str(method);
- }
- else {
- method = rb_id2str(default_method);
- }
- rb_str_buf_cat2(str, ":");
- rb_str_buf_append(str, method);
+ if (!NIL_P(method)) {
+ Check_Type(method, T_SYMBOL);
+ method = rb_sym2str(method);
+ }
+ else {
+ method = rb_id2str(default_method);
+ }
+ rb_str_buf_cat2(str, ":");
+ rb_str_buf_append(str, method);
}
eargs = rb_attr_get(obj, id_arguments);
if (NIL_P(eargs)) {
- eargs = default_args;
+ eargs = default_args;
}
if (eargs != Qfalse) {
- long argc = RARRAY_LEN(eargs);
- const VALUE *argv = RARRAY_CONST_PTR(eargs); /* WB: no new reference */
+ long argc = RARRAY_LEN(eargs);
+ const VALUE *argv = RARRAY_CONST_PTR(eargs); /* WB: no new reference */
- if (argc > 0) {
- VALUE kwds = Qnil;
+ if (argc > 0) {
+ VALUE kwds = Qnil;
- rb_str_buf_cat2(str, "(");
+ rb_str_buf_cat2(str, "(");
if (RB_TYPE_P(argv[argc-1], T_HASH) && !RHASH_EMPTY_P(argv[argc-1])) {
- int all_key = TRUE;
- rb_hash_foreach(argv[argc-1], key_symbol_p, (VALUE)&all_key);
- if (all_key) kwds = argv[--argc];
- }
+ int all_key = TRUE;
+ rb_hash_foreach(argv[argc-1], key_symbol_p, (VALUE)&all_key);
+ if (all_key) kwds = argv[--argc];
+ }
- while (argc--) {
- VALUE arg = *argv++;
+ while (argc--) {
+ VALUE arg = *argv++;
- rb_str_append(str, rb_inspect(arg));
- rb_str_buf_cat2(str, ", ");
- }
- if (!NIL_P(kwds)) {
- rb_hash_foreach(kwds, kwd_append, str);
- }
- rb_str_set_len(str, RSTRING_LEN(str)-2);
- rb_str_buf_cat2(str, ")");
- }
+ rb_str_append(str, rb_inspect(arg));
+ rb_str_buf_cat2(str, ", ");
+ }
+ if (!NIL_P(kwds)) {
+ rb_hash_foreach(kwds, kwd_append, str);
+ }
+ rb_str_set_len(str, RSTRING_LEN(str)-2);
+ rb_str_buf_cat2(str, ")");
+ }
}
return str;
@@ -1209,28 +1209,28 @@ enumerator_size(VALUE obj)
VALUE size;
if (e->procs) {
- struct generator *g = generator_ptr(e->obj);
- VALUE receiver = rb_check_funcall(g->obj, id_size, 0, 0);
- long i = 0;
-
- for (i = 0; i < RARRAY_LEN(e->procs); i++) {
- VALUE proc = RARRAY_AREF(e->procs, i);
- struct proc_entry *entry = proc_entry_ptr(proc);
- lazyenum_size_func *size_fn = entry->fn->size;
- if (!size_fn) {
- return Qnil;
- }
- receiver = (*size_fn)(proc, receiver);
- }
- return receiver;
+ struct generator *g = generator_ptr(e->obj);
+ VALUE receiver = rb_check_funcall(g->obj, id_size, 0, 0);
+ long i = 0;
+
+ for (i = 0; i < RARRAY_LEN(e->procs); i++) {
+ VALUE proc = RARRAY_AREF(e->procs, i);
+ struct proc_entry *entry = proc_entry_ptr(proc);
+ lazyenum_size_func *size_fn = entry->fn->size;
+ if (!size_fn) {
+ return Qnil;
+ }
+ receiver = (*size_fn)(proc, receiver);
+ }
+ return receiver;
}
if (e->size_fn) {
- return (*e->size_fn)(e->obj, e->args, obj);
+ return (*e->size_fn)(e->obj, e->args, obj);
}
if (e->args) {
- argc = (int)RARRAY_LEN(e->args);
- argv = RARRAY_CONST_PTR(e->args);
+ argc = (int)RARRAY_LEN(e->args);
+ argv = RARRAY_CONST_PTR(e->args);
}
size = rb_check_funcall_kw(e->size, id_call, argc, argv, e->kw_splat);
if (size != Qundef) return size;
@@ -1265,9 +1265,9 @@ yielder_memsize(const void *p)
static const rb_data_type_t yielder_data_type = {
"yielder",
{
- yielder_mark,
- yielder_free,
- yielder_memsize,
+ yielder_mark,
+ yielder_free,
+ yielder_memsize,
yielder_compact,
},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
@@ -1280,7 +1280,7 @@ yielder_ptr(VALUE obj)
TypedData_Get_Struct(obj, struct yielder, &yielder_data_type, ptr);
if (!ptr || ptr->proc == Qundef) {
- rb_raise(rb_eArgError, "uninitialized yielder");
+ rb_raise(rb_eArgError, "uninitialized yielder");
}
return ptr;
}
@@ -1306,7 +1306,7 @@ yielder_init(VALUE obj, VALUE proc)
TypedData_Get_Struct(obj, struct yielder, &yielder_data_type, ptr);
if (!ptr) {
- rb_raise(rb_eArgError, "unallocated yielder");
+ rb_raise(rb_eArgError, "unallocated yielder");
}
ptr->proc = proc;
@@ -1405,9 +1405,9 @@ generator_memsize(const void *p)
static const rb_data_type_t generator_data_type = {
"generator",
{
- generator_mark,
- generator_free,
- generator_memsize,
+ generator_mark,
+ generator_free,
+ generator_memsize,
generator_compact,
},
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
@@ -1420,7 +1420,7 @@ generator_ptr(VALUE obj)
TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr);
if (!ptr || ptr->proc == Qundef) {
- rb_raise(rb_eArgError, "uninitialized generator");
+ rb_raise(rb_eArgError, "uninitialized generator");
}
return ptr;
}
@@ -1447,7 +1447,7 @@ generator_init(VALUE obj, VALUE proc)
TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr);
if (!ptr) {
- rb_raise(rb_eArgError, "unallocated generator");
+ rb_raise(rb_eArgError, "unallocated generator");
}
ptr->proc = proc;
@@ -1462,21 +1462,21 @@ generator_initialize(int argc, VALUE *argv, VALUE obj)
VALUE proc;
if (argc == 0) {
- rb_need_block();
+ rb_need_block();
- proc = rb_block_proc();
+ proc = rb_block_proc();
}
else {
- rb_scan_args(argc, argv, "1", &proc);
+ rb_scan_args(argc, argv, "1", &proc);
- if (!rb_obj_is_proc(proc))
- rb_raise(rb_eTypeError,
- "wrong argument type %"PRIsVALUE" (expected Proc)",
- rb_obj_class(proc));
+ if (!rb_obj_is_proc(proc))
+ rb_raise(rb_eTypeError,
+ "wrong argument type %"PRIsVALUE" (expected Proc)",
+ rb_obj_class(proc));
- if (rb_block_given_p()) {
- rb_warn("given block not used");
- }
+ if (rb_block_given_p()) {
+ rb_warn("given block not used");
+ }
}
return generator_init(obj, proc);
@@ -1495,7 +1495,7 @@ generator_init_copy(VALUE obj, VALUE orig)
TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr1);
if (!ptr1) {
- rb_raise(rb_eArgError, "unallocated generator");
+ rb_raise(rb_eArgError, "unallocated generator");
}
ptr1->proc = ptr0->proc;
@@ -1512,7 +1512,7 @@ generator_each(int argc, VALUE *argv, VALUE obj)
rb_ary_push(args, yielder_new());
if (argc > 0) {
- rb_ary_cat(args, argv, argc);
+ rb_ary_cat(args, argv, argc);
}
return rb_proc_call_kw(ptr->proc, args, RB_PASS_CALLED_KEYWORDS);
@@ -1539,22 +1539,22 @@ lazy_init_iterator(RB_BLOCK_CALL_FUNC_ARGLIST(val, m))
{
VALUE result;
if (argc == 1) {
- VALUE args[2];
- args[0] = m;
- args[1] = val;
- result = rb_yield_values2(2, args);
+ VALUE args[2];
+ args[0] = m;
+ args[1] = val;
+ result = rb_yield_values2(2, args);
}
else {
- VALUE args;
- int len = rb_long2int((long)argc + 1);
- VALUE *nargv = ALLOCV_N(VALUE, args, len);
+ VALUE args;
+ int len = rb_long2int((long)argc + 1);
+ VALUE *nargv = ALLOCV_N(VALUE, args, len);
- nargv[0] = m;
- if (argc > 0) {
- MEMCPY(nargv + 1, argv, VALUE, argc);
- }
- result = rb_yield_values2(len, nargv);
- ALLOCV_END(args);
+ nargv[0] = m;
+ if (argc > 0) {
+ MEMCPY(nargv + 1, argv, VALUE, argc);
+ }
+ result = rb_yield_values2(len, nargv);
+ ALLOCV_END(args);
}
if (result == Qundef) rb_iter_break();
return Qnil;
@@ -1590,7 +1590,7 @@ lazy_init_yielder(RB_BLOCK_CALL_FUNC_ARGLIST(_, m))
struct MEMO *result;
result = MEMO_NEW(m, rb_enum_values_pack(argc, argv),
- argc > 1 ? LAZY_MEMO_PACKED : 0);
+ argc > 1 ? LAZY_MEMO_PACKED : 0);
return lazy_yielder_result(result, yielder, procs_array, memos, 0);
}
@@ -1615,19 +1615,19 @@ lazy_yielder_result(struct MEMO *result, VALUE yielder, VALUE procs_array, VALUE
int cont = 1;
for (; i < RARRAY_LEN(procs_array); i++) {
- VALUE proc = RARRAY_AREF(procs_array, i);
- struct proc_entry *entry = proc_entry_ptr(proc);
- if (!(*entry->fn->proc)(proc, result, memos, i)) {
- cont = 0;
- break;
- }
+ VALUE proc = RARRAY_AREF(procs_array, i);
+ struct proc_entry *entry = proc_entry_ptr(proc);
+ if (!(*entry->fn->proc)(proc, result, memos, i)) {
+ cont = 0;
+ break;
+ }
}
if (cont) {
- rb_funcall2(yielder, idLTLT, 1, &(result->memo_value));
+ rb_funcall2(yielder, idLTLT, 1, &(result->memo_value));
}
if (LAZY_MEMO_BREAK_P(result)) {
- rb_iter_break();
+ rb_iter_break();
}
return result->memo_value;
}
@@ -1639,7 +1639,7 @@ lazy_init_block(RB_BLOCK_CALL_FUNC_ARGLIST(val, m))
rb_ivar_set(val, id_memo, rb_ary_new2(RARRAY_LEN(procs)));
rb_block_call(RARRAY_AREF(m, 0), id_each, 0, 0,
- lazy_init_yielder, rb_ary_new3(2, val, procs));
+ lazy_init_yielder, rb_ary_new3(2, val, procs));
return Qnil;
}
@@ -1652,17 +1652,17 @@ lazy_generator_init(VALUE enumerator, VALUE procs)
struct enumerator *e = enumerator_ptr(enumerator);
if (RARRAY_LEN(procs) > 0) {
- struct generator *old_gen_ptr = generator_ptr(e->obj);
- obj = old_gen_ptr->obj;
+ struct generator *old_gen_ptr = generator_ptr(e->obj);
+ obj = old_gen_ptr->obj;
}
else {
- obj = enumerator;
+ obj = enumerator;
}
generator = generator_allocate(rb_cGenerator);
rb_block_call(generator, id_initialize, 0, 0,
- lazy_init_block, rb_ary_new3(2, obj, procs));
+ lazy_init_block, rb_ary_new3(2, obj, procs));
gen_ptr = generator_ptr(generator);
gen_ptr->obj = obj;
@@ -1767,11 +1767,11 @@ lazy_initialize(int argc, VALUE *argv, VALUE self)
rb_check_arity(argc, 1, 2);
if (!rb_block_given_p()) {
- rb_raise(rb_eArgError, "tried to call lazy new without a block");
+ rb_raise(rb_eArgError, "tried to call lazy new without a block");
}
obj = argv[0];
if (argc > 1) {
- size = argv[1];
+ size = argv[1];
}
generator = generator_allocate(rb_cGenerator);
rb_block_call(generator, id_initialize, 0, 0, lazy_init_block_i, obj);
@@ -1801,11 +1801,11 @@ lazy_set_args(VALUE lazy, VALUE args)
ID id = rb_frame_this_func();
rb_ivar_set(lazy, id_method, ID2SYM(id));
if (NIL_P(args)) {
- /* Qfalse indicates that the arguments are empty */
- rb_ivar_set(lazy, id_arguments, Qfalse);
+ /* Qfalse indicates that the arguments are empty */
+ rb_ivar_set(lazy, id_arguments, Qfalse);
}
else {
- rb_ivar_set(lazy, id_arguments, args);
+ rb_ivar_set(lazy, id_arguments, args);
}
}
@@ -1822,7 +1822,7 @@ lazy_set_method(VALUE lazy, VALUE args, rb_enumerator_size_func *size_fn)
static VALUE
lazy_add_method(VALUE obj, int argc, VALUE *argv, VALUE args, VALUE memo,
- const lazyenum_funcs *fn)
+ const lazyenum_funcs *fn)
{
struct enumerator *new_e;
VALUE new_obj;
@@ -1831,9 +1831,9 @@ lazy_add_method(VALUE obj, int argc, VALUE *argv, VALUE args, VALUE memo,
struct enumerator *e = enumerator_ptr(obj);
struct proc_entry *entry;
VALUE entry_obj = TypedData_Make_Struct(rb_cObject, struct proc_entry,
- &proc_entry_data_type, entry);
+ &proc_entry_data_type, entry);
if (rb_block_given_p()) {
- entry->proc = rb_block_proc();
+ entry->proc = rb_block_proc();
}
entry->fn = fn;
entry->memo = args;
@@ -1850,11 +1850,11 @@ lazy_add_method(VALUE obj, int argc, VALUE *argv, VALUE args, VALUE memo,
new_e->procs = new_procs;
if (argc > 0) {
- new_e->meth = rb_to_id(*argv++);
- --argc;
+ new_e->meth = rb_to_id(*argv++);
+ --argc;
}
else {
- new_e->meth = id_each;
+ new_e->meth = id_each;
}
new_e->args = rb_ary_new4(argc, argv);
return new_obj;
@@ -1934,15 +1934,15 @@ lazy_to_enum(int argc, VALUE *argv, VALUE self)
VALUE lazy, meth = sym_each, super_meth;
if (argc > 0) {
- --argc;
- meth = *argv++;
+ --argc;
+ meth = *argv++;
}
if (RTEST((super_meth = rb_hash_aref(lazy_use_super_method, meth)))) {
meth = super_meth;
}
lazy = lazy_to_enum_i(self, meth, argc, argv, 0, rb_keyword_given_p());
if (rb_block_given_p()) {
- enumerator_ptr(lazy)->size = rb_block_proc();
+ enumerator_ptr(lazy)->size = rb_block_proc();
}
return lazy;
}
@@ -1981,9 +1981,9 @@ lazyenum_yield_values(VALUE proc_entry, struct MEMO *result)
int argc = 1;
const VALUE *argv = &result->memo_value;
if (LAZY_MEMO_PACKED_P(result)) {
- const VALUE args = *argv;
- argc = RARRAY_LENINT(args);
- argv = RARRAY_CONST_PTR(args);
+ const VALUE args = *argv;
+ argc = RARRAY_LENINT(args);
+ argv = RARRAY_CONST_PTR(args);
}
return rb_proc_call_with_block(entry->proc, argc, argv, Qnil);
}
@@ -2024,7 +2024,7 @@ static VALUE
lazy_map(VALUE obj)
{
if (!rb_block_given_p()) {
- rb_raise(rb_eArgError, "tried to call lazy map without a block");
+ rb_raise(rb_eArgError, "tried to call lazy map without a block");
}
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_map_funcs);
@@ -2109,7 +2109,7 @@ static VALUE
lazy_flat_map(VALUE obj)
{
if (!rb_block_given_p()) {
- rb_raise(rb_eArgError, "tried to call lazy flat_map without a block");
+ rb_raise(rb_eArgError, "tried to call lazy flat_map without a block");
}
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_flat_map_funcs);
@@ -2139,7 +2139,7 @@ static VALUE
lazy_select(VALUE obj)
{
if (!rb_block_given_p()) {
- rb_raise(rb_eArgError, "tried to call lazy select without a block");
+ rb_raise(rb_eArgError, "tried to call lazy select without a block");
}
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_select_funcs);
@@ -2202,7 +2202,7 @@ static VALUE
lazy_reject(VALUE obj)
{
if (!rb_block_given_p()) {
- rb_raise(rb_eArgError, "tried to call lazy reject without a block");
+ rb_raise(rb_eArgError, "tried to call lazy reject without a block");
}
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_reject_funcs);
@@ -2251,7 +2251,7 @@ static VALUE
lazy_grep(VALUE obj, VALUE pattern)
{
const lazyenum_funcs *const funcs = rb_block_given_p() ?
- &lazy_grep_iter_funcs : &lazy_grep_funcs;
+ &lazy_grep_iter_funcs : &lazy_grep_funcs;
return lazy_add_method(obj, 0, 0, pattern, rb_ary_new3(1, pattern), funcs);
}
@@ -2325,7 +2325,7 @@ lazy_zip_arrays_func(VALUE proc_entry, struct MEMO *result, VALUE memos, long me
ary = rb_ary_new2(RARRAY_LEN(arrays) + 1);
rb_ary_push(ary, result->memo_value);
for (i = 0; i < RARRAY_LEN(arrays); i++) {
- rb_ary_push(ary, rb_ary_entry(RARRAY_AREF(arrays, i), count));
+ rb_ary_push(ary, rb_ary_entry(RARRAY_AREF(arrays, i), count));
}
LAZY_MEMO_SET_VALUE(result, ary);
LAZY_MEMO_SET_PACKED(result);
@@ -2343,19 +2343,19 @@ lazy_zip_func(VALUE proc_entry, struct MEMO *result, VALUE memos, long memo_inde
long i;
if (NIL_P(arg)) {
- arg = rb_ary_new2(RARRAY_LEN(zip_args));
- for (i = 0; i < RARRAY_LEN(zip_args); i++) {
- rb_ary_push(arg, rb_funcall(RARRAY_AREF(zip_args, i), id_to_enum, 0));
- }
- rb_ary_store(memos, memo_index, arg);
+ arg = rb_ary_new2(RARRAY_LEN(zip_args));
+ for (i = 0; i < RARRAY_LEN(zip_args); i++) {
+ rb_ary_push(arg, rb_funcall(RARRAY_AREF(zip_args, i), id_to_enum, 0));
+ }
+ rb_ary_store(memos, memo_index, arg);
}
ary = rb_ary_new2(RARRAY_LEN(arg) + 1);
rb_ary_push(ary, result->memo_value);
for (i = 0; i < RARRAY_LEN(arg); i++) {
- v = rb_rescue2(call_next, RARRAY_AREF(arg, i), next_stopped, 0,
- rb_eStopIteration, (VALUE)0);
- rb_ary_push(ary, v);
+ v = rb_rescue2(call_next, RARRAY_AREF(arg, i), next_stopped, 0,
+ rb_eStopIteration, (VALUE)0);
+ rb_ary_push(ary, v);
}
LAZY_MEMO_SET_VALUE(result, ary);
LAZY_MEMO_SET_PACKED(result);
@@ -2383,24 +2383,24 @@ lazy_zip(int argc, VALUE *argv, VALUE obj)
const lazyenum_funcs *funcs = &lazy_zip_funcs[1];
if (rb_block_given_p()) {
- return rb_call_super(argc, argv);
+ return rb_call_super(argc, argv);
}
ary = rb_ary_new2(argc);
for (i = 0; i < argc; i++) {
- v = rb_check_array_type(argv[i]);
- if (NIL_P(v)) {
- for (; i < argc; i++) {
- if (!rb_respond_to(argv[i], id_each)) {
- rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (must respond to :each)",
- rb_obj_class(argv[i]));
- }
- }
- ary = rb_ary_new4(argc, argv);
- funcs = &lazy_zip_funcs[0];
- break;
- }
- rb_ary_push(ary, v);
+ v = rb_check_array_type(argv[i]);
+ if (NIL_P(v)) {
+ for (; i < argc; i++) {
+ if (!rb_respond_to(argv[i], id_each)) {
+ rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (must respond to :each)",
+ rb_obj_class(argv[i]));
+ }
+ }
+ ary = rb_ary_new4(argc, argv);
+ funcs = &lazy_zip_funcs[0];
+ break;
+ }
+ rb_ary_push(ary, v);
}
return lazy_add_method(obj, 0, 0, ary, ary, funcs);
@@ -2414,16 +2414,16 @@ lazy_take_proc(VALUE proc_entry, struct MEMO *result, VALUE memos, long memo_ind
VALUE memo = rb_ary_entry(memos, memo_index);
if (NIL_P(memo)) {
- memo = entry->memo;
+ memo = entry->memo;
}
remain = NUM2LONG(memo);
if (remain == 0) {
- LAZY_MEMO_SET_BREAK(result);
+ LAZY_MEMO_SET_BREAK(result);
}
else {
- if (--remain == 0) LAZY_MEMO_SET_BREAK(result);
- rb_ary_store(memos, memo_index, LONG2NUM(remain));
+ if (--remain == 0) LAZY_MEMO_SET_BREAK(result);
+ rb_ary_store(memos, memo_index, LONG2NUM(remain));
}
return result;
}
@@ -2433,7 +2433,7 @@ lazy_take_size(VALUE entry, VALUE receiver)
{
long len = NUM2LONG(RARRAY_AREF(rb_ivar_get(entry, id_arguments), 0));
if (NIL_P(receiver) || (FIXNUM_P(receiver) && FIX2LONG(receiver) < len))
- return receiver;
+ return receiver;
return LONG2NUM(len);
}
@@ -2456,7 +2456,7 @@ lazy_take(VALUE obj, VALUE n)
VALUE argv[2];
if (len < 0) {
- rb_raise(rb_eArgError, "attempt to take negative size");
+ rb_raise(rb_eArgError, "attempt to take negative size");
}
if (len == 0) {
@@ -2473,8 +2473,8 @@ lazy_take_while_proc(VALUE proc_entry, struct MEMO *result, VALUE memos, long me
{
VALUE take = lazyenum_yield_values(proc_entry, result);
if (!RTEST(take)) {
- LAZY_MEMO_SET_BREAK(result);
- return 0;
+ LAZY_MEMO_SET_BREAK(result);
+ return 0;
}
return result;
}
@@ -2494,7 +2494,7 @@ static VALUE
lazy_take_while(VALUE obj)
{
if (!rb_block_given_p()) {
- rb_raise(rb_eArgError, "tried to call lazy take_while without a block");
+ rb_raise(rb_eArgError, "tried to call lazy take_while without a block");
}
return lazy_add_method(obj, 0, 0, Qnil, Qnil, &lazy_take_while_funcs);
@@ -2505,10 +2505,10 @@ lazy_drop_size(VALUE proc_entry, VALUE receiver)
{
long len = NUM2LONG(RARRAY_AREF(rb_ivar_get(proc_entry, id_arguments), 0));
if (NIL_P(receiver))
- return receiver;
+ return receiver;
if (FIXNUM_P(receiver)) {
- len = FIX2LONG(receiver) - len;
- return LONG2FIX(len < 0 ? 0 : len);
+ len = FIX2LONG(receiver) - len;
+ return LONG2FIX(len < 0 ? 0 : len);
}
return rb_funcall(receiver, '-', 1, LONG2NUM(len));
}
@@ -2521,13 +2521,13 @@ lazy_drop_proc(VALUE proc_entry, struct MEMO *result, VALUE memos, long memo_ind
VALUE memo = rb_ary_entry(memos, memo_index);
if (NIL_P(memo)) {
- memo = entry->memo;
+ memo = entry->memo;
}
remain = NUM2LONG(memo);
if (remain > 0) {
- --remain;
- rb_ary_store(memos, memo_index, LONG2NUM(remain));
- return 0;
+ --remain;
+ rb_ary_store(memos, memo_index, LONG2NUM(remain));
+ return 0;
}
return result;
@@ -2553,7 +2553,7 @@ lazy_drop(VALUE obj, VALUE n)
argv[1] = n;
if (len < 0) {
- rb_raise(rb_eArgError, "attempt to drop negative size");
+ rb_raise(rb_eArgError, "attempt to drop negative size");
}
return lazy_add_method(obj, 2, argv, n, rb_ary_new3(1, n), &lazy_drop_funcs);
@@ -2566,13 +2566,13 @@ lazy_drop_while_proc(VALUE proc_entry, struct MEMO* result, VALUE memos, long me
VALUE memo = rb_ary_entry(memos, memo_index);
if (NIL_P(memo)) {
- memo = entry->memo;
+ memo = entry->memo;
}
if (!RTEST(memo)) {
- VALUE drop = lazyenum_yield_values(proc_entry, result);
- if (RTEST(drop)) return 0;
- rb_ary_store(memos, memo_index, Qtrue);
+ VALUE drop = lazyenum_yield_values(proc_entry, result);
+ if (RTEST(drop)) return 0;
+ rb_ary_store(memos, memo_index, Qtrue);
}
return result;
}
@@ -2592,7 +2592,7 @@ static VALUE
lazy_drop_while(VALUE obj)
{
if (!rb_block_given_p()) {
- rb_raise(rb_eArgError, "tried to call lazy drop_while without a block");
+ rb_raise(rb_eArgError, "tried to call lazy drop_while without a block");
}
return lazy_add_method(obj, 0, 0, Qfalse, Qnil, &lazy_drop_while_funcs);