aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-07 13:06:23 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-01-07 13:06:23 +0000
commit9f44b77a18d4d6099174c6044261eb1611a147ea (patch)
tree4d218c733f53d9c2fd9d53ad8a43d8a2080b0c08 /array.c
parenta1115a1b4758900790e9cb4f36a4dccf3e2149b8 (diff)
downloadruby-9f44b77a18d4d6099174c6044261eb1611a147ea.tar.gz
* enum.c (enum_minmax): optimize object comparison in
Enumerable#minmax. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c20
1 files changed, 2 insertions, 18 deletions
diff --git a/array.c b/array.c
index dd14837b76..e31f67467f 100644
--- a/array.c
+++ b/array.c
@@ -2368,22 +2368,6 @@ struct ary_sort_data {
int opt_inited;
};
-enum {
- sort_opt_Fixnum,
- sort_opt_String,
- sort_optimizable_count
-};
-
-#define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString)
-
-#define SORT_OPTIMIZABLE_BIT(type) (1U << TOKEN_PASTE(sort_opt_,type))
-#define SORT_OPTIMIZABLE(data, type) \
- (((data)->opt_inited & SORT_OPTIMIZABLE_BIT(type)) ? \
- ((data)->opt_methods & SORT_OPTIMIZABLE_BIT(type)) : \
- (((data)->opt_inited |= SORT_OPTIMIZABLE_BIT(type)), \
- rb_method_basic_definition_p(TOKEN_PASTE(rb_c,type), id_cmp) && \
- ((data)->opt_methods |= SORT_OPTIMIZABLE_BIT(type))))
-
static VALUE
sort_reentered(VALUE ary)
{
@@ -2415,12 +2399,12 @@ sort_2(const void *ap, const void *bp, void *dummy)
VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
int n;
- if (FIXNUM_P(a) && FIXNUM_P(b) && SORT_OPTIMIZABLE(data, Fixnum)) {
+ if (FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(data, Fixnum)) {
if ((long)a > (long)b) return 1;
if ((long)a < (long)b) return -1;
return 0;
}
- if (STRING_P(a) && STRING_P(b) && SORT_OPTIMIZABLE(data, String)) {
+ if (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(data, String)) {
return rb_str_cmp(a, b);
}