Skip to content

Commit 2eb9b01

Browse files
committed
Less checks for Complex(Numeric, Numeric) when both are real numbers
1 parent 0c3745e commit 2eb9b01

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/ruby/truffleruby/core/complex.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ class Complex < Numeric
4141
:round, :step, :truncate, :i, :negative?, :positive?
4242

4343
def self.convert(real, imag = undefined, exception: true)
44+
if check_real?(real) && check_real?(imag)
45+
return new(real, imag)
46+
end
47+
4448
raise_exception = !exception.equal?(false)
4549
if nil.equal?(real) || nil.equal?(imag)
4650
return nil unless raise_exception
4751
raise TypeError, "can't convert nil into Complex"
4852
end
4953
imag = nil if Primitive.undefined?(imag)
5054

51-
if check_real?(real) && check_real?(imag)
52-
return new(real, imag)
53-
end
54-
5555
real = real.to_c if Primitive.object_kind_of?(real, String)
5656
imag = imag.to_c if Primitive.object_kind_of?(imag, String)
5757

0 commit comments

Comments
 (0)