Skip to content

Commit a2bc9a3

Browse files
committedJul 19, 2018
Speed up DateTime.iso8601 by fast pathing similar to cext in our ruby version.
This is not identical. The section after the cext looks different from our code but seemingly all tests pass. The other weird bit is undeprecating + making Date._valid_civil?. Nearly 2x speed up for ```DateTime.iso8601('1999-12-31T19:20:06')```.
1 parent 9892b3c commit a2bc9a3

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed
 

Diff for: ‎core/src/main/java/org/jruby/ext/date/RubyDate.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,7 @@ public static RubyDate today(ThreadContext context, IRubyObject self, IRubyObjec
727727
return new RubyDate(context.runtime, (RubyClass) self, new DateTime(getChronology(context, start, 0)).withTimeAtStartOfDay(), 0, start);
728728
}
729729

730-
@Deprecated // NOTE: should go away once no date.rb is using it
731-
@JRubyMethod(name = "_valid_civil?", meta = true, required = 3, optional = 1, visibility = Visibility.PRIVATE)
730+
@JRubyMethod(name = "_valid_civil?", meta = true, required = 3, optional = 1)
732731
public static IRubyObject _valid_civil_p(ThreadContext context, IRubyObject self, IRubyObject[] args) {
733732
final long sg = args.length > 3 ? val2sg(context, args[3]) : GREGORIAN;
734733
final Long jd = validCivilImpl(args[0], args[1], args[2], sg);

Diff for: ‎lib/ruby/stdlib/date.rb

+15-4
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,21 @@ def self.commercial(y=-4712, w=1, d=1, h=0, min=0, s=0, of=0, sg=ITALY)
684684
def self.new_by_frags(elem, sg) # :nodoc:
685685
raise ArgumentError, 'invalid date' unless elem
686686

687-
elem = rewrite_frags(elem)
688-
elem = complete_frags(elem)
689-
unless (jd = valid_date_frags?(elem, sg)) &&
690-
(fr = valid_time_frags?(elem))
687+
688+
# More work to do if not :civil
689+
if !elem.key?(:jd) && !elem.key?(:yday) &&
690+
(year = elem[:year]) && (mon = elem[:mon]) && (mday = elem[:mday])
691+
jd = Date._valid_civil?(year, mon, mday, sg)
692+
elem[:hour] ||= 0
693+
elem[:min] ||= 0
694+
elem[:sec] ||= 0
695+
elem[:sec] = 59 if elem[:sec] == 60
696+
else
697+
elem = rewrite_frags(elem)
698+
elem = complete_frags(elem)
699+
jd = valid_date_frags?(elem, sg)
700+
end
701+
unless jd && (fr = valid_time_frags?(elem))
691702
raise ArgumentError, 'invalid date'
692703
end
693704
fr += (elem[:sec_fraction] || 0) / 86400

0 commit comments

Comments
 (0)
Please sign in to comment.