aboutsummaryrefslogtreecommitdiffstats
path: root/internal.h
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-17 12:14:21 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-17 12:14:21 +0000
commita38d1619b487a9b22422e6be5fdf96d7bdc4b703 (patch)
treeff47d04d683438a00f3f406bcd3a4e89d9732072 /internal.h
parent4b5cb8b79ce7d60a15b5edeb22637a8366503bbf (diff)
downloadruby-a38d1619b487a9b22422e6be5fdf96d7bdc4b703.tar.gz
* array.c (rb_ary_max, rb_ary_min): Array#max and Array#min added.
[Feature #12172] * internal.h (OPTIMIZED_CMP): moved from enum.c so that array.c can use it. * test/ruby/test_array.rb (test_max, test_min): tests for Array#max and Array#min. * test/ruby/test_enum.rb (test_max, test_min): revised a bit to test Enumerable#max and #min explicitly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'internal.h')
-rw-r--r--internal.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/internal.h b/internal.h
index 03b1e1c3d9..4a38762266 100644
--- a/internal.h
+++ b/internal.h
@@ -698,6 +698,13 @@ struct cmp_opt_data {
rb_method_basic_definition_p(TOKEN_PASTE(rb_c,type), id_cmp) && \
((data).opt_methods |= CMP_OPTIMIZABLE_BIT(type))))
+#define OPTIMIZED_CMP(a, b, data) \
+ ((FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(data, Fixnum)) ? \
+ (((long)a > (long)b) ? 1 : ((long)a < (long)b) ? -1 : 0) : \
+ (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(data, String)) ? \
+ rb_str_cmp(a, b) : \
+ rb_cmpint(rb_funcallv(a, id_cmp, 1, &b), a, b))
+
/* ment is in method.h */
/* global variable */