Feature #12172 » 0001-refactor-a-data-structure-for-CMP_OPTIMIZABLE.patch
array.c | ||
---|---|---|
struct ary_sort_data {
|
||
VALUE ary;
|
||
int opt_methods;
|
||
int opt_inited;
|
||
struct cmp_opt_data cmp_opt;
|
||
};
|
||
static VALUE
|
||
... | ... | |
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
|
||
int n;
|
||
if (FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(data, Fixnum)) {
|
||
if (FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(data->cmp_opt, Fixnum)) {
|
||
if ((long)a > (long)b) return 1;
|
||
if ((long)a < (long)b) return -1;
|
||
return 0;
|
||
}
|
||
if (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(data, String)) {
|
||
if (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(data->cmp_opt, String)) {
|
||
return rb_str_cmp(a, b);
|
||
}
|
||
... | ... | |
RBASIC_CLEAR_CLASS(tmp);
|
||
data.ary = tmp;
|
||
data.opt_methods = 0;
|
||
data.opt_inited = 0;
|
||
data.cmp_opt.opt_methods = 0;
|
||
data.cmp_opt.opt_inited = 0;
|
||
RARRAY_PTR_USE(tmp, ptr, {
|
||
ruby_qsort(ptr, len, sizeof(VALUE),
|
||
rb_block_given_p()?sort_1:sort_2, &data);
|
enum.c | ||
---|---|---|
struct min_t {
|
||
VALUE min;
|
||
int opt_methods;
|
||
int opt_inited;
|
||
struct cmp_opt_data cmp_opt;
|
||
};
|
||
static VALUE
|
||
... | ... | |
memo->min = i;
|
||
}
|
||
else {
|
||
if (OPTIMIZED_CMP(i, memo->min, memo) < 0) {
|
||
if (OPTIMIZED_CMP(i, memo->min, memo->cmp_opt) < 0) {
|
||
memo->min = i;
|
||
}
|
||
}
|
||
... | ... | |
return nmin_run(obj, num, 0, 0);
|
||
m->min = Qundef;
|
||
m->opt_methods = 0;
|
||
m->opt_inited = 0;
|
||
m->cmp_opt.opt_methods = 0;
|
||
m->cmp_opt.opt_inited = 0;
|
||
if (rb_block_given_p()) {
|
||
rb_block_call(obj, id_each, 0, 0, min_ii, memo);
|
||
}
|
||
... | ... | |
struct max_t {
|
||
VALUE max;
|
||
int opt_methods;
|
||
int opt_inited;
|
||
struct cmp_opt_data cmp_opt;
|
||
};
|
||
static VALUE
|
||
... | ... | |
memo->max = i;
|
||
}
|
||
else {
|
||
if (OPTIMIZED_CMP(i, memo->max, memo) > 0) {
|
||
if (OPTIMIZED_CMP(i, memo->max, memo->cmp_opt) > 0) {
|
||
memo->max = i;
|
||
}
|
||
}
|
||
... | ... | |
return nmin_run(obj, num, 0, 1);
|
||
m->max = Qundef;
|
||
m->opt_methods = 0;
|
||
m->opt_inited = 0;
|
||
m->cmp_opt.opt_methods = 0;
|
||
m->cmp_opt.opt_inited = 0;
|
||
if (rb_block_given_p()) {
|
||
rb_block_call(obj, id_each, 0, 0, max_ii, (VALUE)memo);
|
||
}
|
||
... | ... | |
VALUE min;
|
||
VALUE max;
|
||
VALUE last;
|
||
int opt_methods;
|
||
int opt_inited;
|
||
struct cmp_opt_data cmp_opt;
|
||
};
|
||
static void
|
||
... | ... | |
memo->max = j;
|
||
}
|
||
else {
|
||
n = OPTIMIZED_CMP(i, memo->min, memo);
|
||
n = OPTIMIZED_CMP(i, memo->min, memo->cmp_opt);
|
||
if (n < 0) {
|
||
memo->min = i;
|
||
}
|
||
n = OPTIMIZED_CMP(j, memo->max, memo);
|
||
n = OPTIMIZED_CMP(j, memo->max, memo->cmp_opt);
|
||
if (n > 0) {
|
||
memo->max = j;
|
||
}
|
||
... | ... | |
j = memo->last;
|
||
memo->last = Qundef;
|
||
n = OPTIMIZED_CMP(j, i, memo);
|
||
n = OPTIMIZED_CMP(j, i, memo->cmp_opt);
|
||
if (n == 0)
|
||
i = j;
|
||
else if (n < 0) {
|
||
... | ... | |
m->min = Qundef;
|
||
m->last = Qundef;
|
||
m->opt_methods = 0;
|
||
m->opt_inited = 0;
|
||
m->cmp_opt.opt_methods = 0;
|
||
m->cmp_opt.opt_inited = 0;
|
||
if (rb_block_given_p()) {
|
||
rb_block_call(obj, id_each, 0, 0, minmax_ii, memo);
|
||
if (m->last != Qundef)
|
internal.h | ||
---|---|---|
cmp_optimizable_count
|
||
};
|
||
struct cmp_opt_data {
|
||
int opt_methods;
|
||
int opt_inited;
|
||
};
|
||
#define CMP_OPTIMIZABLE_BIT(type) (1U << TOKEN_PASTE(cmp_opt_,type))
|
||
#define CMP_OPTIMIZABLE(data, type) \
|
||
(((data)->opt_inited & CMP_OPTIMIZABLE_BIT(type)) ? \
|
||
((data)->opt_methods & CMP_OPTIMIZABLE_BIT(type)) : \
|
||
(((data)->opt_inited |= CMP_OPTIMIZABLE_BIT(type)), \
|
||
(((data).opt_inited & CMP_OPTIMIZABLE_BIT(type)) ? \
|
||
((data).opt_methods & CMP_OPTIMIZABLE_BIT(type)) : \
|
||
(((data).opt_inited |= CMP_OPTIMIZABLE_BIT(type)), \
|
||
rb_method_basic_definition_p(TOKEN_PASTE(rb_c,type), id_cmp) && \
|
||
((data)->opt_methods |= CMP_OPTIMIZABLE_BIT(type))))
|
||
((data).opt_methods |= CMP_OPTIMIZABLE_BIT(type))))
|
||
/* ment is in method.h */
|
||