Feature #4257
closedswitch_hitter - an acceleration of date library
Description
=begin
switch_hitter'ed already passed nearly all of tests (except some tests
of class name and some confirmations of format of inspect).
- The constructors may return Date::Light instead of Date.
- as fast as home_run when it represents simple date of proleptic
gregorian of the age of the human race. - keeps compatibility.
- can load ruby 1.9.2 dumped marshal.
- accepts flonum explicitly with limitations.
- If the given offset is flonum, DateTime assumes its precision is
at most second. - If the given +/- argument is flonum, DateTime assumes its
precision is at most nanosecond.
- If the given offset is flonum, DateTime assumes its precision is
I'd like to apply this to trunk in the near future.
I also have a plan of improvement about some format methods.
see also http://redmine.ruby-lang.org/issues/show/4068
=end
Files
Updated by jeremyevans0 (Jeremy Evans) over 14 years ago
=begin
I ran switch_hitter against home_run's test suites. Most of the failures are due to differences between home_run and the standard library. There are a few failures that I think should be addressed in switch_hitter:
-
Operator methods such as >>, <<, +, and - and methods such as next_day and prev_day should return instances that are the same class of the receiver. This could be complicated as subclasses are generally going to subclass Date and DateTime instead of Date::Light and DateTime::Light. I think it's fair to return a Date::Light for a Date or DateTime::Light for a DateTime, but if the receiver is an instance of a subclass of Date or DateTime, the operator method should return an instance the same subclass.
-
Class methods such as civil, new, commercial, ordinal, and jd should return instances of the class. Similar to 1), Date.new can return Date or Date::Light, but a subclass of Date should return an instance of that subclass.
-
Strings returned by Date or DateTime methods should use US-ASCII encoding by default, or the default internal encoding if set.
-
Date parsing methods such as parse, strptime, httpdate, iso8601, etc. are broken (but the DateTime versions are not).
ruby-head :001 > Date.parse '1/1/2011'
ArgumentError: cannot create
from /home/jeremy/.rvm/rubies/ruby-head/lib/ruby/1.9.1/date.rb:803:in new_l!' from /home/jeremy/.rvm/rubies/ruby-head/lib/ruby/1.9.1/date.rb:803:in
new!'
from /home/jeremy/.rvm/rubies/ruby-head/lib/ruby/1.9.1/date.rb:1081:in new_by_frags' from /home/jeremy/.rvm/rubies/ruby-head/lib/ruby/1.9.1/date.rb:1123:in
parse'
from (irb):1
from /home/jeremy/.rvm/rubies/ruby-head/bin/irb:16:in `'
Related to 1) is that with switch_hitter's design, subclasses of Date and DateTime are not going to have optimized performance. A user would have to subclass Date::Light or DateTime::Light if they wanted their subclass to have optimized performance. I don't really see a way around this without having some Date objects use internal type T_DATA and other Date objects use internal type T_OBJECT, and having a ruby class whose objects can differ in internal type is probably not a good idea.
=end
Updated by tadf (tadayoshi funaba) over 14 years ago
- File switch_hitter.patch3 switch_hitter.patch3 added
=begin
i've integrated both.
=end
Updated by jeremyevans0 (Jeremy Evans) over 14 years ago
=begin
Looks good. The only thing I noticed is that DateTime#amjd is broken:
$ ruby -v -r date -e 'DateTime.new.amjd'
ruby 1.9.3dev (2011-01-21 trunk 30620) [x86_64-openbsd4.8]
-e:1:in amjd': undefined method
amjd_r' for #<DateTime[R]: -4712-01-01T00:00:00+00:00 (-1/2,0,2299161)> (NoMethodError)
from -e:1:in `'
=end
Updated by tadf (tadayoshi funaba) about 14 years ago
- File switch_hitter.patch4 switch_hitter.patch4 added
=begin
i'm planning to apply this change within a couple of weeks.
=end
Updated by headius (Charles Nutter) about 14 years ago
=begin
Added http://jira.codehaus.org/browse/JRUBY-5518 to track this. We'll want to implement a Java version of switch_hitter, most likely.
=end
Updated by jeremyevans0 (Jeremy Evans) about 14 years ago
=begin
Looks good, no unexpected failures in home_run's test suite.
=end
Updated by tadf (tadayoshi funaba) about 14 years ago
- Status changed from Open to Closed
=begin
=end