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

ruby-changes:4310

From: ko1@a...
Date: Wed, 19 Mar 2008 14:53:30 +0900 (JST)
Subject: [ruby-changes:4310] nobu - Ruby:r15800 (trunk): * complex.c (nucomp_to_s, nucomp_inspect): get rid of making

nobu	2008-03-19 14:53:11 +0900 (Wed, 19 Mar 2008)

  New Revision: 15800

  Modified files:
    trunk/ChangeLog
    trunk/complex.c
    trunk/rational.c

  Log:
    * complex.c (nucomp_to_s, nucomp_inspect): get rid of making
      unnecessary intermediate objects.
    
    * complex.c (make_patterns, string_to_c): do not treat successive
      underscores as a part of numeric like as literals.  [ruby-dev:34085]
    
    * rational.c (make_patterns, string_to_r): ditto.


  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/complex.c?r1=15800&r2=15799&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=15800&r2=15799&diff_format=u
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/rational.c?r1=15800&r2=15799&diff_format=u

Index: complex.c
===================================================================
--- complex.c	(revision 15799)
+++ complex.c	(revision 15800)
@@ -202,6 +202,7 @@
   }
 }
 
+#if 0
 static VALUE
 nucomp_s_canonicalize(int argc, VALUE *argv, VALUE klass)
 {
@@ -235,6 +236,7 @@
 
   return nucomp_s_canonicalize_internal(klass, real, image);
 }
+#endif
 
 static VALUE
 nucomp_s_new(int argc, VALUE *argv, VALUE klass)
@@ -459,6 +461,7 @@
   return DOUBLE2NUM(atan2(RFLOAT_VALUE(y), RFLOAT_VALUE(x)));
 }
 
+#if 0
 static VALUE
 m_hypot(VALUE x, VALUE y)
 {
@@ -466,6 +469,7 @@
   return DOUBLE2NUM(hypot(RFLOAT_VALUE(x), RFLOAT_VALUE(y)));
 }
 #endif
+#endif
 
 static VALUE
 nucomp_s_polar(VALUE klass, VALUE abs, VALUE arg)
@@ -626,6 +630,7 @@
 			      f_to_r(dat->image)), other);
 }
 
+#if 0
 static VALUE
 nucomp_fdiv(VALUE self, VALUE other)
 {
@@ -635,6 +640,7 @@
 			      f_to_f(dat->real),
 			      f_to_f(dat->image)), other);
 }
+#endif
 
 static VALUE
 nucomp_expt(VALUE self, VALUE other)
@@ -788,6 +794,7 @@
   return f_complex_new2(CLASS_OF(self), dat->real, f_negate(dat->image));
 }
 
+#if 0
 static VALUE
 nucomp_real_p(VALUE self)
 {
@@ -812,6 +819,7 @@
 {
   return f_boolcast(!nucomp_exact_p(self));
 }
+#endif
 
 inline static long
 i_gcd(long x, long y)
@@ -978,17 +986,17 @@
     s = rb_str_new2("");
   else {
     s = f_to_s(dat->real);
-    rb_str_concat(s, rb_str_new2(!impos ? "-" : "+"));
+    rb_str_cat2(s, (!impos ? "-" : "+"));
   }
 
   if (k_rational_p(dat->image) &&
       !f_one_p(f_denominator(dat->image))) {
-    rb_str_concat(s, rb_str_new2("("));
+    rb_str_cat2(s, "(");
     rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image)));
-    rb_str_concat(s, rb_str_new2(")i"));
+    rb_str_cat2(s, ")i");
   } else {
     rb_str_concat(s, f_to_s(rezero ? dat->image : f_abs(dat->image)));
-    rb_str_concat(s, rb_str_new2("i"));
+    rb_str_cat2(s, "i");
   }
 
   return s;
@@ -1003,9 +1011,9 @@
 
   s = rb_str_new2("Complex(");
   rb_str_concat(s, f_inspect(dat->real));
-  rb_str_concat(s, rb_str_new2(", "));
+  rb_str_cat2(s, ", ");
   rb_str_concat(s, f_inspect(dat->image));
-  rb_str_concat(s, rb_str_new2(")"));
+  rb_str_cat2(s, ")");
 
   return s;
 }
@@ -1109,7 +1117,7 @@
 }
 
 static VALUE comp_pat1, comp_pat2, a_slash, a_dot_and_an_e,
-  image_garbages_pat, null_string, underscores_pat, an_underscore;
+    image_garbages_pat, null_string;
 
 #define DIGITS "(?:\\d(?:_\\d|\\d)*)"
 #define NUMERATOR "(?:" DIGITS "?\\.)?" DIGITS "(?:[eE][-+]?" DIGITS ")?"
@@ -1122,15 +1130,15 @@
 static void
 make_patterns(void)
 {
-  static char *comp_pat1_source = PATTERN1;
-  static char *comp_pat2_source = PATTERN2;
-  static char *image_garbages_pat_source = "[+\\(\\)iIjJ]";
-  static char *underscores_pat_source = "_+";
+  static const char comp_pat1_source[] = PATTERN1;
+  static const char comp_pat2_source[] = PATTERN2;
+  static const char image_garbages_pat_source[] = "[+\\(\\)iIjJ]";
+#define REG_NEW(s) rb_reg_new(s, sizeof(s) - 1, 0)
 
-  comp_pat1 = rb_reg_new(comp_pat1_source, strlen(comp_pat1_source), 0);
+  comp_pat1 = REG_NEW(comp_pat1_source);
   rb_global_variable(&comp_pat1);
 
-  comp_pat2 = rb_reg_new(comp_pat2_source, strlen(comp_pat2_source), 0);
+  comp_pat2 = REG_NEW(comp_pat2_source);
   rb_global_variable(&comp_pat2);
 
   a_slash = rb_str_new2("/");
@@ -1139,19 +1147,13 @@
   a_dot_and_an_e = rb_str_new2(".eE");
   rb_global_variable(&a_dot_and_an_e);
 
-  image_garbages_pat = rb_reg_new(image_garbages_pat_source,
-				  strlen(image_garbages_pat_source), 0);
+  image_garbages_pat = REG_NEW(image_garbages_pat_source);
   rb_global_variable(&image_garbages_pat);
 
   null_string = rb_str_new2("");
   rb_global_variable(&null_string);
 
-  underscores_pat = rb_reg_new(underscores_pat_source,
-			       strlen(underscores_pat_source), 0);
-  rb_global_variable(&underscores_pat);
-
-  an_underscore = rb_str_new2("_");
-  rb_global_variable(&an_underscore);
+#undef REG_NEW
 }
 
 #define id_strip rb_intern("strip")
@@ -1246,8 +1248,7 @@
 static VALUE
 string_to_c(VALUE self)
 {
-  VALUE s = f_gsub(self, underscores_pat, an_underscore);
-  VALUE a = string_to_c_internal(s);
+  VALUE a = string_to_c_internal(self);
   if (!NIL_P(RARRAY_PTR(a)[0]))
     return RARRAY_PTR(a)[0];
   return rb_complex_new1(INT2FIX(0));
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 15799)
+++ ChangeLog	(revision 15800)
@@ -1,3 +1,13 @@
+Wed Mar 19 14:53:03 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* complex.c (nucomp_to_s, nucomp_inspect): get rid of making
+	  unnecessary intermediate objects.
+
+	* complex.c (make_patterns, string_to_c): do not treat successive
+	  underscores as a part of numeric like as literals.  [ruby-dev:34085]
+
+	* rational.c (make_patterns, string_to_r): ditto.
+
 Wed Mar 19 14:36:40 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* bignum.c (rb_cstr_to_inum): treat successive underscores as
Index: rational.c
===================================================================
--- rational.c	(revision 15799)
+++ rational.c	(revision 15800)
@@ -230,6 +230,7 @@
     return nurat_s_new_internal(klass, num, den);
 }
 
+#if 0
 static VALUE
 nurat_s_canonicalize(int argc, VALUE *argv, VALUE klass)
 {
@@ -259,6 +260,7 @@
 
   return nurat_s_canonicalize_internal(klass, num, den);
 }
+#endif
 
 static VALUE
 nurat_s_new(int argc, VALUE *argv, VALUE klass)
@@ -584,11 +586,14 @@
   return rb_assoc_new(val, f_sub(self, f_mul(other, val)));
 }
 
+#if 0
 static VALUE
 nurat_quot(VALUE self, VALUE other)
 {
   return f_truncate(f_div(self, other));
 }
+#endif
+
 static VALUE
 nurat_rem(VALUE self, VALUE other)
 {
@@ -596,12 +601,14 @@
   return f_sub(self, f_mul(other, val));
 }
 
+#if 0
 static VALUE
 nurat_quotrem(VALUE self, VALUE other)
 {
   VALUE val = f_truncate(f_div(self, other));
   return rb_assoc_new(val, f_sub(self, f_mul(other, val)));
 }
+#endif
 
 static VALUE
 nurat_abs(VALUE self)
@@ -612,11 +619,13 @@
     return f_negate(self);
 }
 
+#if 0
 static VALUE
 nurat_true(VALUE self)
 {
   return Qtrue;
 }
+#endif
 
 static VALUE
 nurat_floor(VALUE self)
@@ -774,7 +783,7 @@
   return f_mul(RARRAY_PTR(a)[0], f_expt(INT2FIX(FLT_RADIX), RARRAY_PTR(a)[1]));
 }
 
-static VALUE rat_pat, an_e_pat, a_dot_pat, underscores_pat, an_underscore;
+static VALUE rat_pat, an_e_pat, a_dot_pat;
 
 #define DIGITS "(?:\\d(?:_\\d|\\d)*)"
 #define NUMERATOR "(?:" DIGITS "?\\.)?" DIGITS "(?:[eE][-+]?" DIGITS ")?"
@@ -784,26 +793,21 @@
 static void
 make_patterns(void)
 {
-  static char *rat_pat_source = PATTERN;
-  static char *an_e_pat_source = "[eE]";
-  static char *a_dot_pat_source = "\\.";
-  static char *underscores_pat_source = "_+";
+  static const char rat_pat_source[] = PATTERN;
+  static const char an_e_pat_source[] = "[eE]";
+  static const char a_dot_pat_source[] = "\\.";
+#define REG_NEW(s) rb_reg_new(s, sizeof(s) - 1, 0)
 
-  rat_pat = rb_reg_new(rat_pat_source, strlen(rat_pat_source), 0);
+  rat_pat = REG_NEW(rat_pat_source);
   rb_global_variable(&rat_pat);
 
-  an_e_pat = rb_reg_new(an_e_pat_source, strlen(an_e_pat_source), 0);
+  an_e_pat = REG_NEW(an_e_pat_source);
   rb_global_variable(&an_e_pat);
 
-  a_dot_pat = rb_reg_new(a_dot_pat_source, strlen(a_dot_pat_source), 0);
+  a_dot_pat = REG_NEW(a_dot_pat_source);
   rb_global_variable(&a_dot_pat);
 
-  underscores_pat = rb_reg_new(underscores_pat_source,
-			       strlen(underscores_pat_source), 0);
-  rb_global_variable(&underscores_pat);
-
-  an_underscore = rb_str_new2("_");
-  rb_global_variable(&an_underscore);
+#undef REG_NEW
 }
 
 #define id_strip rb_intern("strip")
@@ -908,8 +912,7 @@
 static VALUE
 string_to_r(VALUE self)
 {
-  VALUE s = f_gsub(self, underscores_pat, an_underscore);
-  VALUE a = string_to_r_internal(s);
+  VALUE a = string_to_r_internal(self);
   if (!NIL_P(RARRAY_PTR(a)[0]))
     return RARRAY_PTR(a)[0];
   return rb_rational_new1(INT2FIX(0));

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

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