[前][次][番号順一覧][スレッド一覧]

ruby-changes:3524

From: ko1@a...
Date: Sun, 13 Jan 2008 15:38:14 +0900 (JST)
Subject: [ruby-changes:3524] tadf - Ruby:r15002 (ruby_1_8): * lib/date.rb, lib/date/format.rb: tuning for performance.

tadf	2008-01-12 12:04:50 +0900 (Sat, 12 Jan 2008)

  New Revision: 15002

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/lib/date/format.rb
    branches/ruby_1_8/lib/date.rb

  Log:
    * lib/date.rb, lib/date/format.rb: tuning for performance.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/ChangeLog?r1=15002&r2=15001&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/date.rb?r1=15002&r2=15001&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/branches/ruby_1_8/lib/date/format.rb?r1=15002&r2=15001&diff_format=u

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 15001)
+++ ruby_1_8/ChangeLog	(revision 15002)
@@ -1,3 +1,7 @@
+Sat Jan 12 12:04:14 2008  Tadayoshi Funaba  <tadf@d...>
+
+	* lib/date.rb, lib/date/format.rb: tuning for performance.
+
 Fri Jan 11 12:35:56 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* configure.in: moved broken syscall checks from process.c etc.
Index: ruby_1_8/lib/date/format.rb
===================================================================
--- ruby_1_8/lib/date/format.rb	(revision 15001)
+++ ruby_1_8/lib/date/format.rb	(revision 15002)
@@ -1,5 +1,5 @@
 # format.rb: Written by Tadayoshi Funaba 1999-2008
-# $Id: format.rb,v 2.41 2008-01-06 08:42:17+09 tadf Exp $
+# $Id: format.rb,v 2.42 2008-01-12 10:54:29+09 tadf Exp $
 
 require 'rational'
 
@@ -297,9 +297,9 @@
 	t = $1.size
 	sign = if offset < 0 then -1 else +1 end
 	fr = offset.abs
-	hh, fr = fr.divmod(HOURS_IN_DAY)
-	mm, fr = fr.divmod(MINUTES_IN_DAY)
-	ss, fr = fr.divmod(SECONDS_IN_DAY)
+	ss = fr.div(SECONDS_IN_DAY) # 4p
+	hh, ss = ss.divmod(3600)
+	mm, ss = ss.divmod(60)
 	if t == 3
 	  if    ss.nonzero? then t =  2
 	  elsif mm.nonzero? then t =  1
Index: ruby_1_8/lib/date.rb
===================================================================
--- ruby_1_8/lib/date.rb	(revision 15001)
+++ ruby_1_8/lib/date.rb	(revision 15002)
@@ -6,7 +6,7 @@
 # Documentation: William Webber <william@w...>
 #
 #--
-# $Id: date.rb,v 2.35 2008-01-06 08:42:17+09 tadf Exp $
+# $Id: date.rb,v 2.36 2008-01-12 10:54:29+09 tadf Exp $
 #++
 #
 # == Overview
@@ -505,9 +505,9 @@
   # Convert a fractional day +fr+ to [hours, minutes, seconds,
   # fraction_of_a_second]
   def self.day_fraction_to_time(fr)
-    h,   fr = fr.divmod(HOURS_IN_DAY)
-    min, fr = fr.divmod(MINUTES_IN_DAY)
-    s,   fr = fr.divmod(SECONDS_IN_DAY)
+    ss,  fr = fr.divmod(SECONDS_IN_DAY) # 4p
+    h,   ss = ss.divmod(3600)
+    min, s  = ss.divmod(60)
     return h, min, s, fr
   end
 
@@ -517,11 +517,15 @@
     Rational(Rational(1, 2), 2) # a challenge
 
     def self.time_to_day_fraction(h, min, s)
-      Rational(h, 24) + Rational(min, 1440) + Rational(s, 86400)
+      Rational(h * 3600 + min * 60 + s, 86400) # 4p
     end
   rescue
     def self.time_to_day_fraction(h, min, s)
-      h.to_r/24 + min.to_r/1440 + s.to_r/86400
+	if Integer === h && Integer === min && Integer === s
+	  Rational(h * 3600 + min * 60 + s, 86400) # 4p
+	else
+	  h.to_r/24 + min.to_r/1440 + s.to_r/86400
+	end
     end
   end
 
@@ -1373,7 +1377,7 @@
   # Return the date as a human-readable string.
   #
   # The format used is YYYY-MM-DD.
-  def to_s() strftime end
+  def to_s() format('%.4d-%02d-%02d', year, mon, mday) end # 4p
 
   # Dump to Marshal format.
   def _dump(limit) Marshal.dump([@ajd, @of, @sg], -1) end
@@ -1617,6 +1621,11 @@
   public :hour, :min, :sec, :sec_fraction, :zone, :offset, :new_offset
 #	 :minute, :second, :second_fraction
 
+  def to_s # 4p
+    format('%.4d-%02d-%02dT%02d:%02d:%02d%s',
+	   year, mon, mday, hour, min, sec, zone)
+  end
+
 end
 
 class Time

--
ML: ruby-changes@q...
Info: 

[前][次][番号順一覧][スレッド一覧]