From 9f44b77a18d4d6099174c6044261eb1611a147ea Mon Sep 17 00:00:00 2001 From: shugo Date: Thu, 7 Jan 2016 13:06:23 +0000 Subject: * 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 --- array.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) (limited to 'array.c') 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); } -- cgit v1.2.3