@@ -129,19 +129,22 @@ def nobits?(mask)
129
129
( self & mask ) == 0
130
130
end
131
131
132
- def pow ( e , m = undefined )
133
- return self ** e if Primitive . undefined? ( m )
132
+ def pow ( exponent , modulus = undefined )
133
+ return self ** exponent if Primitive . undefined? ( modulus )
134
134
135
- raise TypeError , '2nd argument not allowed unless a 1st argument is integer' unless Primitive . is_a? ( e , Integer )
136
- raise TypeError , '2nd argument not allowed unless all arguments are integers' unless Primitive . is_a? ( m , Integer )
137
- raise RangeError , '1st argument cannot be negative when 2nd argument specified' if e . negative?
135
+ raise TypeError , '2nd argument not allowed unless a 1st argument is integer' unless Primitive . is_a? ( exponent , Integer )
136
+ raise TypeError , '2nd argument not allowed unless all arguments are integers' unless Primitive . is_a? ( modulus , Integer )
137
+ raise RangeError , '1st argument cannot be negative when 2nd argument specified' if exponent . negative?
138
138
139
- if Primitive . integer_fits_into_long? ( m )
140
- Truffle ::IntegerOperations . modular_exponentiation ( self , e , m )
139
+ # Ruby implementation is much faster than Java implementation for modulus <= 2^32,
140
+ # and Java is much faster for modulus > 2^32.
141
+ if Primitive . integer_fits_into_int? ( modulus )
142
+ Truffle ::IntegerOperations . modular_exponentiation ( self , exponent , modulus )
141
143
else
142
- Primitive . mod_pow ( self , e , m )
144
+ Primitive . mod_pow ( self , exponent , modulus )
143
145
end
144
146
end
147
+ Truffle ::Graal . always_split instance_method ( :pow )
145
148
146
149
def times
147
150
return to_enum ( :times ) { self } unless block_given?
0 commit comments