1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Mark some Integer methods as inline (#3264)

This commit is contained in:
Takashi Kokubun 2020-06-27 10:07:47 -07:00 committed by GitHub
parent 247dd8743e
commit 0703e01471
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
Notes: git 2020-06-28 02:08:14 +09:00
Merged-By: k0kubun <takashikkbn@gmail.com>
4 changed files with 104 additions and 94 deletions

View file

@ -1,21 +0,0 @@
type: lib/benchmark_driver/runner/mjit
prelude: |
def mjit_zero?(int)
int.zero?
end
def mjit_eq_0(int)
int == 0
end
benchmark:
- name: 0.zero?
script: mjit_zero?(0)
- name: 1.zero?
script: mjit_zero?(1)
- name: 0 == 0
script: mjit_eq_0(0)
- name: 1 == 0
script: mjit_eq_0(1)
loop_count: 40000000

View file

@ -0,0 +1,26 @@
type: lib/benchmark_driver/runner/mjit
prelude: |
def mjit_abs(int) int.abs end
def mjit_bit_length(int) int.bit_length end
def mjit_even?(int) int.even? end
def mjit_integer?(int) int.integer? end
def mjit_magnitude(int) int.magnitude end
def mjit_odd?(int) int.odd? end
def mjit_ord(int) int.ord end
def mjit_to_i(int) int.to_i end
def mjit_to_int(int) int.to_int end
def mjit_zero?(int) int.zero? end
benchmark:
- mjit_abs(-1)
- mjit_bit_length(100)
- mjit_even?(2)
- mjit_integer?(0)
- mjit_magnitude(-1)
- mjit_odd?(1)
- mjit_ord(1)
- mjit_to_i(1)
- mjit_to_int(1)
- mjit_zero?(0)
loop_count: 40000000

View file

@ -1,4 +1,82 @@
class Integer
def abs
Primitive.attr! 'inline'
Primitive.cexpr! 'rb_int_abs(self)'
end
def bit_length
Primitive.attr! 'inline'
Primitive.cexpr! 'rb_int_bit_length(self)'
end
# call-seq:
# int.even? -> true or false
#
# Returns +true+ if +int+ is an even number.
def even?
Primitive.attr! 'inline'
Primitive.cexpr! 'int_even_p(self)'
end
# call-seq:
# int.integer? -> true
#
# Since +int+ is already an Integer, this always returns +true+.
def integer?
Primitive.attr! 'inline'
Primitive.cexpr! 'Qtrue'
end
def magnitude
Primitive.attr! 'inline'
Primitive.cexpr! 'rb_int_abs(self)'
end
# call-seq:
# int.odd? -> true or false
#
# Returns +true+ if +int+ is an odd number.
def odd?
Primitive.attr! 'inline'
Primitive.cexpr! 'rb_int_odd_p(self)'
end
# call-seq:
# int.ord -> self
#
# Returns the +int+ itself.
#
# 97.ord #=> 97
#
# This method is intended for compatibility to character literals
# in Ruby 1.9.
#
# For example, <code>?a.ord</code> returns 97 both in 1.8 and 1.9.
def ord
Primitive.attr! 'inline'
Primitive.cexpr! 'self'
end
# call-seq:
# int.to_i -> integer
#
# Since +int+ is already an Integer, returns +self+.
#
# #to_int is an alias for #to_i.
def to_i
Primitive.attr! 'inline'
Primitive.cexpr! 'self'
end
# call-seq:
# int.to_int -> integer
#
# Since +int+ is already an Integer, returns +self+.
def to_int
Primitive.attr! 'inline'
Primitive.cexpr! 'self'
end
# call-seq:
# int.zero? -> true or false
#

View file

@ -3217,42 +3217,6 @@ rb_num2ull(VALUE val)
*
*/
/*
* call-seq:
* int.to_i -> integer
* int.to_int -> integer
*
* Since +int+ is already an Integer, returns +self+.
*
* #to_int is an alias for #to_i.
*/
static VALUE
int_to_i(VALUE num)
{
return num;
}
/*
* call-seq:
* int.integer? -> true
*
* Since +int+ is already an Integer, this always returns +true+.
*/
static VALUE
int_int_p(VALUE num)
{
return Qtrue;
}
/*
* call-seq:
* int.odd? -> true or false
*
* Returns +true+ if +int+ is an odd number.
*/
VALUE
rb_int_odd_p(VALUE num)
{
@ -3268,13 +3232,6 @@ rb_int_odd_p(VALUE num)
}
}
/*
* call-seq:
* int.even? -> true or false
*
* Returns +true+ if +int+ is an even number.
*/
static VALUE
int_even_p(VALUE num)
{
@ -3467,26 +3424,6 @@ int_chr(int argc, VALUE *argv, VALUE num)
return rb_enc_uint_chr(i, enc);
}
/*
* call-seq:
* int.ord -> self
*
* Returns the +int+ itself.
*
* 97.ord #=> 97
*
* This method is intended for compatibility to character literals
* in Ruby 1.9.
*
* For example, <code>?a.ord</code> returns 97 both in 1.8 and 1.9.
*/
static VALUE
int_ord(VALUE num)
{
return num;
}
/*
* Fixnum
*/
@ -5644,9 +5581,6 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "to_s", int_to_s, -1);
rb_define_alias(rb_cInteger, "inspect", "to_s");
rb_define_method(rb_cInteger, "integer?", int_int_p, 0);
rb_define_method(rb_cInteger, "odd?", rb_int_odd_p, 0);
rb_define_method(rb_cInteger, "even?", int_even_p, 0);
rb_define_method(rb_cInteger, "allbits?", int_allbits_p, 1);
rb_define_method(rb_cInteger, "anybits?", int_anybits_p, 1);
rb_define_method(rb_cInteger, "nobits?", int_nobits_p, 1);
@ -5657,9 +5591,6 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "next", int_succ, 0);
rb_define_method(rb_cInteger, "pred", int_pred, 0);
rb_define_method(rb_cInteger, "chr", int_chr, -1);
rb_define_method(rb_cInteger, "ord", int_ord, 0);
rb_define_method(rb_cInteger, "to_i", int_to_i, 0);
rb_define_method(rb_cInteger, "to_int", int_to_i, 0);
rb_define_method(rb_cInteger, "to_f", int_to_f, 0);
rb_define_method(rb_cInteger, "floor", int_floor, -1);
rb_define_method(rb_cInteger, "ceil", int_ceil, -1);
@ -5682,9 +5613,6 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "pow", rb_int_powm, -1); /* in bignum.c */
rb_define_method(rb_cInteger, "abs", rb_int_abs, 0);
rb_define_method(rb_cInteger, "magnitude", rb_int_abs, 0);
rb_define_method(rb_cInteger, "===", rb_int_equal, 1);
rb_define_method(rb_cInteger, "==", rb_int_equal, 1);
rb_define_method(rb_cInteger, ">", rb_int_gt, 1);
@ -5702,7 +5630,6 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, ">>", rb_int_rshift, 1);
rb_define_method(rb_cInteger, "size", int_size, 0);
rb_define_method(rb_cInteger, "bit_length", rb_int_bit_length, 0);
rb_define_method(rb_cInteger, "digits", rb_int_digits, -1);
/* An obsolete class, use Integer */