Skip to content

Commit 5614700

Browse files
committed
Move MEMO_NEW to imemo.c and rename to rb_imemo_memo_new
1 parent da89f7f commit 5614700

File tree

5 files changed

+34
-33
lines changed

5 files changed

+34
-33
lines changed

enum.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static VALUE
127127
enum_grep0(VALUE obj, VALUE pat, VALUE test)
128128
{
129129
VALUE ary = rb_ary_new();
130-
struct MEMO *memo = MEMO_NEW(pat, ary, test);
130+
struct MEMO *memo = rb_imemo_memo_new(pat, ary, test);
131131
rb_block_call_func_t fn;
132132
if (rb_block_given_p()) {
133133
fn = grep_iter_i;
@@ -317,7 +317,7 @@ enum_count(int argc, VALUE *argv, VALUE obj)
317317
func = count_i;
318318
}
319319

320-
memo = MEMO_NEW(item, 0, 0);
320+
memo = rb_imemo_memo_new(item, 0, 0);
321321
rb_block_call(obj, id_each, 0, 0, func, (VALUE)memo);
322322
return imemo_count_value(memo);
323323
}
@@ -382,7 +382,7 @@ enum_find(int argc, VALUE *argv, VALUE obj)
382382

383383
if_none = rb_check_arity(argc, 0, 1) ? argv[0] : Qnil;
384384
RETURN_ENUMERATOR(obj, argc, argv);
385-
memo = MEMO_NEW(Qundef, 0, 0);
385+
memo = rb_imemo_memo_new(Qundef, 0, 0);
386386
if (rb_block_pair_yield_optimizable())
387387
rb_block_call2(obj, id_each, 0, 0, find_i_fast, (VALUE)memo, RB_BLOCK_NO_USE_PACKED_ARGS);
388388
else
@@ -467,7 +467,7 @@ enum_find_index(int argc, VALUE *argv, VALUE obj)
467467
func = find_index_i;
468468
}
469469

470-
memo = MEMO_NEW(Qnil, condition_value, 0);
470+
memo = rb_imemo_memo_new(Qnil, condition_value, 0);
471471
rb_block_call(obj, id_each, 0, 0, func, (VALUE)memo);
472472
return memo->v1;
473473
}
@@ -1084,7 +1084,7 @@ enum_inject(int argc, VALUE *argv, VALUE obj)
10841084
return ary_inject_op(obj, init, op);
10851085
}
10861086

1087-
memo = MEMO_NEW(init, Qnil, op);
1087+
memo = rb_imemo_memo_new(init, Qnil, op);
10881088
rb_block_call(obj, id_each, 0, 0, iter, (VALUE)memo);
10891089
if (UNDEF_P(memo->v1)) return Qnil;
10901090
return memo->v1;
@@ -1142,7 +1142,7 @@ enum_partition(VALUE obj)
11421142

11431143
RETURN_SIZED_ENUMERATOR(obj, 0, 0, enum_size);
11441144

1145-
memo = MEMO_NEW(rb_ary_new(), rb_ary_new(), 0);
1145+
memo = rb_imemo_memo_new(rb_ary_new(), rb_ary_new(), 0);
11461146
rb_block_call(obj, id_each, 0, 0, partition_i, (VALUE)memo);
11471147

11481148
return rb_assoc_new(memo->v1, memo->v2);
@@ -1345,7 +1345,7 @@ enum_first(int argc, VALUE *argv, VALUE obj)
13451345
return enum_take(obj, argv[0]);
13461346
}
13471347
else {
1348-
memo = MEMO_NEW(Qnil, 0, 0);
1348+
memo = rb_imemo_memo_new(Qnil, 0, 0);
13491349
rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)memo);
13501350
return memo->v1;
13511351
}
@@ -1722,7 +1722,7 @@ enum_sort_by(VALUE obj)
17221722
RBASIC_CLEAR_CLASS(ary);
17231723
buf = rb_ary_hidden_new(SORT_BY_BUFSIZE*2);
17241724
rb_ary_store(buf, SORT_BY_BUFSIZE*2-1, Qnil);
1725-
memo = MEMO_NEW(0, 0, 0);
1725+
memo = rb_imemo_memo_new(0, 0, 0);
17261726
data = (struct sort_by_data *)&memo->v1;
17271727
RB_OBJ_WRITE(memo, &data->ary, ary);
17281728
RB_OBJ_WRITE(memo, &data->buf, buf);
@@ -1766,7 +1766,7 @@ enum_sort_by(VALUE obj)
17661766
#define ENUM_BLOCK_CALL(name) \
17671767
rb_block_call2(obj, id_each, 0, 0, ENUMFUNC(name), (VALUE)memo, rb_block_given_p() && rb_block_pair_yield_optimizable() ? RB_BLOCK_NO_USE_PACKED_ARGS : 0);
17681768

1769-
#define MEMO_ENUM_NEW(v1) (rb_check_arity(argc, 0, 1), MEMO_NEW((v1), (argc ? *argv : 0), 0))
1769+
#define MEMO_ENUM_NEW(v1) (rb_check_arity(argc, 0, 1), rb_imemo_memo_new((v1), (argc ? *argv : 0), 0))
17701770

17711771
#define DEFINE_ENUMFUNCS(name) \
17721772
static VALUE enum_##name##_func(VALUE result, struct MEMO *memo); \
@@ -2754,7 +2754,7 @@ enum_min_by(int argc, VALUE *argv, VALUE obj)
27542754
if (argc && !NIL_P(num = argv[0]))
27552755
return rb_nmin_run(obj, num, 1, 0, 0);
27562756

2757-
memo = MEMO_NEW(Qundef, Qnil, 0);
2757+
memo = rb_imemo_memo_new(Qundef, Qnil, 0);
27582758
rb_block_call(obj, id_each, 0, 0, min_by_i, (VALUE)memo);
27592759
return memo->v2;
27602760
}
@@ -2828,7 +2828,7 @@ enum_max_by(int argc, VALUE *argv, VALUE obj)
28282828
if (argc && !NIL_P(num = argv[0]))
28292829
return rb_nmin_run(obj, num, 1, 1, 0);
28302830

2831-
memo = MEMO_NEW(Qundef, Qnil, 0);
2831+
memo = rb_imemo_memo_new(Qundef, Qnil, 0);
28322832
rb_block_call(obj, id_each, 0, 0, max_by_i, (VALUE)memo);
28332833
return memo->v2;
28342834
}
@@ -2979,7 +2979,7 @@ member_i(RB_BLOCK_CALL_FUNC_ARGLIST(iter, args))
29792979
static VALUE
29802980
enum_member(VALUE obj, VALUE val)
29812981
{
2982-
struct MEMO *memo = MEMO_NEW(val, Qfalse, 0);
2982+
struct MEMO *memo = rb_imemo_memo_new(val, Qfalse, 0);
29832983

29842984
rb_block_call(obj, id_each, 0, 0, member_i, (VALUE)memo);
29852985
return memo->v2;
@@ -3231,7 +3231,7 @@ enum_each_slice(VALUE obj, VALUE n)
32313231
size = limit_by_enum_size(obj, size);
32323232
ary = rb_ary_new2(size);
32333233
arity = rb_block_arity();
3234-
memo = MEMO_NEW(ary, dont_recycle_block_arg(arity), size);
3234+
memo = rb_imemo_memo_new(ary, dont_recycle_block_arg(arity), size);
32353235
rb_block_call(obj, id_each, 0, 0, each_slice_i, (VALUE)memo);
32363236
ary = memo->v1;
32373237
if (RARRAY_LEN(ary) > 0) rb_yield(ary);
@@ -3307,7 +3307,7 @@ enum_each_cons(VALUE obj, VALUE n)
33073307
RETURN_SIZED_ENUMERATOR(obj, 1, &n, enum_each_cons_size);
33083308
arity = rb_block_arity();
33093309
if (enum_size_over_p(obj, size)) return obj;
3310-
memo = MEMO_NEW(rb_ary_new2(size), dont_recycle_block_arg(arity), size);
3310+
memo = rb_imemo_memo_new(rb_ary_new2(size), dont_recycle_block_arg(arity), size);
33113311
rb_block_call(obj, id_each, 0, 0, each_cons_i, (VALUE)memo);
33123312

33133313
return obj;
@@ -3536,7 +3536,7 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
35363536
}
35373537

35383538
/* TODO: use NODE_DOT2 as memo(v, v, -) */
3539-
memo = MEMO_NEW(result, args, 0);
3539+
memo = rb_imemo_memo_new(result, args, 0);
35403540
rb_block_call(obj, id_each, 0, 0, allary ? zip_ary : zip_i, (VALUE)memo);
35413541

35423542
return result;
@@ -3579,7 +3579,7 @@ enum_take(VALUE obj, VALUE n)
35793579

35803580
if (len == 0) return rb_ary_new2(0);
35813581
result = rb_ary_new2(len);
3582-
memo = MEMO_NEW(result, 0, len);
3582+
memo = rb_imemo_memo_new(result, 0, len);
35833583
rb_block_call(obj, id_each, 0, 0, take_i, (VALUE)memo);
35843584
return result;
35853585
}
@@ -3667,7 +3667,7 @@ enum_drop(VALUE obj, VALUE n)
36673667
}
36683668

36693669
result = rb_ary_new();
3670-
memo = MEMO_NEW(result, 0, len);
3670+
memo = rb_imemo_memo_new(result, 0, len);
36713671
rb_block_call(obj, id_each, 0, 0, drop_i, (VALUE)memo);
36723672
return result;
36733673
}
@@ -3726,7 +3726,7 @@ enum_drop_while(VALUE obj)
37263726

37273727
RETURN_ENUMERATOR(obj, 0, 0);
37283728
result = rb_ary_new();
3729-
memo = MEMO_NEW(result, 0, FALSE);
3729+
memo = rb_imemo_memo_new(result, 0, FALSE);
37303730
rb_block_call(obj, id_each, 0, 0, drop_while_i, (VALUE)memo);
37313731
return result;
37323732
}

enumerator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj)
671671
rb_check_arity(argc, 0, 1);
672672
RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_enum_size);
673673
memo = (!argc || NIL_P(memo = argv[0])) ? INT2FIX(0) : rb_to_int(memo);
674-
return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)MEMO_NEW(memo, 0, 0));
674+
return enumerator_block_call(obj, enumerator_with_index_i, (VALUE)rb_imemo_memo_new(memo, 0, 0));
675675
}
676676

677677
/*
@@ -1613,7 +1613,7 @@ lazy_init_yielder(RB_BLOCK_CALL_FUNC_ARGLIST(_, m))
16131613
VALUE memos = rb_attr_get(yielder, id_memo);
16141614
struct MEMO *result;
16151615

1616-
result = MEMO_NEW(m, rb_enum_values_pack(argc, argv),
1616+
result = rb_imemo_memo_new(m, rb_enum_values_pack(argc, argv),
16171617
argc > 1 ? LAZY_MEMO_PACKED : 0);
16181618
return lazy_yielder_result(result, yielder, procs_array, memos, 0);
16191619
}

imemo.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ rb_free_tmp_buffer(volatile VALUE *store)
9797
}
9898
}
9999

100+
struct MEMO *
101+
rb_imemo_memo_new(VALUE a, VALUE b, VALUE c)
102+
{
103+
struct MEMO *memo = IMEMO_NEW(struct MEMO, imemo_memo, 0);
104+
*((VALUE *)&memo->v1) = a;
105+
*((VALUE *)&memo->v2) = b;
106+
*((VALUE *)&memo->u3.value) = c;
107+
108+
return memo;
109+
}
110+
100111
static VALUE
101112
imemo_fields_new(VALUE owner, size_t capa, bool shareable)
102113
{

internal/imemo.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ typedef struct rb_imemo_tmpbuf_struct rb_imemo_tmpbuf_t;
134134
#endif
135135
VALUE rb_imemo_new(enum imemo_type type, VALUE v0, size_t size, bool is_shareable);
136136
VALUE rb_imemo_tmpbuf_new(void);
137+
struct MEMO *rb_imemo_memo_new(VALUE a, VALUE b, VALUE c);
137138
struct vm_ifunc *rb_vm_ifunc_new(rb_block_call_func_t func, const void *data, int min_argc, int max_argc);
138139
static inline enum imemo_type imemo_type(VALUE imemo);
139140
static inline int imemo_type_p(VALUE imemo, enum imemo_type imemo_type);
@@ -152,17 +153,6 @@ RUBY_SYMBOL_EXPORT_BEGIN
152153
const char *rb_imemo_name(enum imemo_type type);
153154
RUBY_SYMBOL_EXPORT_END
154155

155-
static inline struct MEMO *
156-
MEMO_NEW(VALUE a, VALUE b, VALUE c)
157-
{
158-
struct MEMO *memo = IMEMO_NEW(struct MEMO, imemo_memo, 0);
159-
*((VALUE *)&memo->v1) = a;
160-
*((VALUE *)&memo->v2) = b;
161-
*((VALUE *)&memo->u3.value) = c;
162-
163-
return memo;
164-
}
165-
166156
static inline enum imemo_type
167157
imemo_type(VALUE imemo)
168158
{

re.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,7 @@ match_named_captures(int argc, VALUE *argv, VALUE match)
24692469
}
24702470

24712471
hash = rb_hash_new();
2472-
memo = MEMO_NEW(hash, match, symbolize_names);
2472+
memo = rb_imemo_memo_new(hash, match, symbolize_names);
24732473

24742474
onig_foreach_name(RREGEXP(RMATCH(match)->regexp)->ptr, match_named_captures_iter, (void*)memo);
24752475

@@ -2508,7 +2508,7 @@ match_deconstruct_keys(VALUE match, VALUE keys)
25082508
h = rb_hash_new_with_size(onig_number_of_names(RREGEXP_PTR(RMATCH(match)->regexp)));
25092509

25102510
struct MEMO *memo;
2511-
memo = MEMO_NEW(h, match, 1);
2511+
memo = rb_imemo_memo_new(h, match, 1);
25122512

25132513
onig_foreach_name(RREGEXP_PTR(RMATCH(match)->regexp), match_named_captures_iter, (void*)memo);
25142514

0 commit comments

Comments
 (0)