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

ruby-changes:19440

From: tadf <ko1@a...>
Date: Sun, 8 May 2011 18:41:45 +0900 (JST)
Subject: [ruby-changes:19440] Ruby:r31480 (trunk): * ext/date/date_{parse,strptime}.c: introduced some macros.

tadf	2011-05-08 18:41:38 +0900 (Sun, 08 May 2011)

  New Revision: 31480

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

  Log:
    * ext/date/date_{parse,strptime}.c: introduced some macros.

  Modified files:
    trunk/ChangeLog
    trunk/ext/date/date_parse.c
    trunk/ext/date/date_strptime.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 31479)
+++ ChangeLog	(revision 31480)
@@ -1,3 +1,7 @@
+Sun May  8 18:40:03 2011  Tadayoshi Funaba  <tadf@d...>
+
+	* ext/date/date_{parse,strptime}.c: introduced some macros.
+
 Sun May  8 17:17:13 2011  Tadayoshi Funaba  <tadf@d...>
 
 	* test/date/*.rb: use skip /w messages.
Index: ext/date/date_strptime.c
===================================================================
--- ext/date/date_strptime.c	(revision 31479)
+++ ext/date/date_strptime.c	(revision 31480)
@@ -52,6 +52,8 @@
 #define f_aref(o,i) rb_funcall(o, rb_intern("[]"), 1, i)
 #define f_end(o,i) rb_funcall(o, rb_intern("end"), 1, i)
 
+#define issign(c) ((c) == '-' || (c) == '+')
+
 static int
 num_pattern_p(const char *s)
 {
@@ -344,7 +346,7 @@
 		    int sign = 1;
 		    size_t osi;
 
-		    if (str[si] == '-' || str[si] == '+') {
+		    if (issign(str[si])) {
 			if (str[si] == '-')
 			    sign = -1;
 			si++;
@@ -526,7 +528,7 @@
 		      VALUE n;
 		      int sign = 1;
 
-		      if (str[si] == '-' || str[si] == '+') {
+		      if (issign(str[si])) {
 			  if (str[si] == '-')
 			      sign = -1;
 			  si++;
Index: ext/date/date_parse.c
===================================================================
--- ext/date/date_parse.c	(revision 31479)
+++ ext/date/date_parse.c	(revision 31480)
@@ -53,6 +53,9 @@
     "jul", "aug", "sep", "oct", "nov", "dec"
 };
 
+#define issign(c) ((c) == '-' || (c) == '+')
+#define asp_string() rb_str_new(" ", 1)
+
 static void
 s3e(VALUE hash, VALUE y, VALUE m, VALUE d, int bc)
 {
@@ -87,12 +90,11 @@
 	size_t l;
 
 	s = RSTRING_PTR(y);
-	while (*s != '-' && *s != '+' && !isdigit(*s))
+	while (!issign(*s) && !isdigit(*s))
 	    s++;
 	bp = s;
-	if (*s == '-' || *s == '+') {
+	if (issign(*s))
 	    s++;
-	}
 	l = strspn(s, "0123456789");
 	ep = s + l;
 	if (*ep) {
@@ -137,10 +139,10 @@
 	VALUE iy;
 
 	s = RSTRING_PTR(y);
-	while (*s != '-' && *s != '+' && !isdigit(*s))
+	while (!issign(*s) && !isdigit(*s))
 	    s++;
 	bp = s;
-	if (*s == '-' || *s == '+') {
+	if (issign(*s)) {
 	    s++;
 	    sign = 1;
 	}
@@ -253,8 +255,7 @@
 
 	be = f_begin(m, INT2FIX(0));
 	en = f_end(m, INT2FIX(0));
-	f_aset2(str, be, LONG2NUM(NUM2LONG(en) - NUM2LONG(be)),
-		rb_str_new(" ", 1));
+	f_aset2(str, be, LONG2NUM(NUM2LONG(en) - NUM2LONG(be)), asp_string());
 	(*cb)(m, hash);
     }
 
@@ -1243,7 +1244,7 @@
 
 	str = rb_str_dup(str);
 	REGCOMP_0(pat);
-	f_gsub_bang(str, pat, rb_str_new(" ", 1));
+	f_gsub_bang(str, pat, asp_string());
     }
 
     hash = rb_hash_new();

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

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