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

ruby-changes:20291

From: tadf <ko1@a...>
Date: Fri, 1 Jul 2011 03:24:57 +0900 (JST)
Subject: [ruby-changes:20291] tadf:r32339 (trunk): * ext/date/date_core.c: mathn still alive (should die soon).

tadf	2011-07-01 03:24:50 +0900 (Fri, 01 Jul 2011)

  New Revision: 32339

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32339

  Log:
    * ext/date/date_core.c: mathn still alive (should die soon).

  Modified files:
    trunk/ChangeLog
    trunk/ext/date/date_core.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32338)
+++ ChangeLog	(revision 32339)
@@ -1,3 +1,7 @@
+Fri Jul  1 03:24:03 2011  Tadayoshi Funaba  <tadf@d...>
+
+	* ext/date/date_core.c: mathn still alive (should die soon).
+
 Thu Jun 30 23:50:00 2011  Kenta Murata  <mrkn@m...>
 
 	* misc/ruby-mode.el (ruby-indent-beg-re): Fix broken regular
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 32338)
+++ ext/date/date_core.c	(revision 32339)
@@ -417,7 +417,7 @@
     (x)->jd = (y)->jd;\
     (x)->sg = (sg_cast)((y)->sg);\
     (x)->year = (y)->year;\
-    (x)->pc = PACK5(EX_MON((y)->pc), EX_MDAY((y)->pc), 0, 0, 0);\
+    (x)->pc = PACK2(EX_MON((y)->pc), EX_MDAY((y)->pc));\
     (x)->flags = (y)->flags;\
 }
 #endif
@@ -1904,6 +1904,12 @@
     return f_kind_of_p(x, rb_cNumeric);
 }
 
+inline static VALUE
+k_rational_p(VALUE x)
+{
+    return f_kind_of_p(x, rb_cRational);
+}
+
 #ifndef NDEBUG
 static void
 civil_to_jd(VALUE y, int m, int d, double sg,
@@ -2280,14 +2286,32 @@
 	if (!k_numeric_p(vof))
 	    rb_raise(rb_eTypeError, "expected numeric");
 	vof = f_to_r(vof);
+#ifdef CANONICALIZATION_FOR_MATHN
+	if (!k_rational_p(vof))
+	    return offset_to_sec(vof, rof);
+#endif
 	/* fall through */
       case T_RATIONAL:
 	{
-	    VALUE vs = day_to_sec(vof);
-	    VALUE vn = RRATIONAL(vs)->num;
-	    VALUE vd = RRATIONAL(vs)->den;
+	    VALUE vs, vn, vd;
 	    long n;
 
+	    vs = day_to_sec(vof);
+
+#ifdef CANONICALIZATION_FOR_MATHN
+	    if (!k_rational_p(vs)) {
+		vn = vs;
+		vd = INT2FIX(1);
+	    }
+	    else {
+		vn = RRATIONAL(vs)->num;
+		vd = RRATIONAL(vs)->den;
+	    }
+#else
+	    vn = RRATIONAL(vs)->num;
+	    vd = RRATIONAL(vs)->den;
+#endif
+
 	    if (FIXNUM_P(vn) && FIXNUM_P(vd) && (FIX2LONG(vd) == 1))
 		n = FIX2LONG(vn);
 	    else {
@@ -5671,6 +5695,10 @@
 	if (!k_numeric_p(other))
 	    rb_raise(rb_eTypeError, "expected numeric");
 	other = f_to_r(other);
+#ifdef CANONICALIZATION_FOR_MATHN
+	if (!k_rational_p(other))
+	    return d_lite_plus(self, other);
+#endif
 	/* fall through */
       case T_RATIONAL:
 	{
@@ -8323,11 +8351,10 @@
 static VALUE
 iso8601_timediv(VALUE self, VALUE n)
 {
-    VALUE f, fmt;
+    VALUE fmt;
 
-    if (f_lt_p(n, INT2FIX(1)))
-	f = rb_usascii_str_new2("");
-    else {
+    fmt = rb_usascii_str_new2("T%H:%M:%S");
+    if (f_gt_p(n, INT2FIX(0))) {
 	VALUE argv[3];
 
 	get_d1(self);
@@ -8337,11 +8364,9 @@
 	argv[2] = f_round(f_quo(m_sf_in_sec(dat),
 			    f_quo(INT2FIX(1),
 				  f_expt(INT2FIX(10), n))));
-	f = rb_f_sprintf(3, argv);
+	rb_str_append(fmt, rb_f_sprintf(3, argv));
     }
-    fmt = f_add3(rb_usascii_str_new2("T%H:%M:%S"),
-		 f,
-		 rb_usascii_str_new2("%:z"));
+    rb_str_append(fmt, rb_usascii_str_new2("%:z"));
     return strftimev(RSTRING_PTR(fmt), self, set_tmx);
 }
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

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