Skip to content

Commit d709c3b

Browse files
committed
Refactor Time#from_array and get rid of recursive call
1 parent 99d3a03 commit d709c3b

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

src/main/java/org/truffleruby/core/time/TimeNodes.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -527,22 +527,6 @@ protected RubyTime timeSFromArray(
527527
return buildTime(language, timeClass, sec, min, hour, mday, month, year, nsec, isdst, isutc, utcoffset);
528528
}
529529

530-
@Specialization(guards = "!isInteger(sec) || !isInteger(nsec)")
531-
protected Object timeSFromArrayFallback(
532-
RubyClass timeClass,
533-
Object sec,
534-
int min,
535-
int hour,
536-
int mday,
537-
int month,
538-
int year,
539-
Object nsec,
540-
int isdst,
541-
boolean isutc,
542-
Object utcoffset) {
543-
return FAILURE;
544-
}
545-
546530
@TruffleBoundary
547531
private RubyTime buildTime(RubyLanguage language, RubyClass timeClass, int sec, int min, int hour, int mday,
548532
int month,

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,7 @@ def from_array(sec, min, hour, mday, month, year, nsec, is_dst, is_utc, utc_offs
380380
Primitive.rb_num2int(month)
381381
Primitive.rb_num2int(year)
382382

383-
time = Primitive.time_s_from_array(self, sec, min, hour, mday, month, year, nsec, is_dst, is_utc, utc_offset)
384-
return time unless Primitive.undefined?(time)
385-
383+
# handle sec and nsec
386384
if Primitive.is_a?(sec, String)
387385
sec = sec.to_i
388386
elsif nsec
@@ -401,10 +399,8 @@ def from_array(sec, min, hour, mday, month, year, nsec, is_dst, is_utc, utc_offs
401399
end
402400

403401
nsec ||= 0
404-
sec += nsec / 1_000_000_000
405-
nsec %= 1_000_000_000
406402

407-
from_array(sec, min, hour, mday, month, year, nsec, is_dst, is_utc, utc_offset)
403+
Primitive.time_s_from_array(self, sec, min, hour, mday, month, year, nsec, is_dst, is_utc, utc_offset)
408404
end
409405
private :from_array
410406

0 commit comments

Comments
 (0)