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

ruby-changes:33275

From: nobu <ko1@a...>
Date: Mon, 17 Mar 2014 13:57:22 +0900 (JST)
Subject: [ruby-changes:33275] nobu:r45355 (trunk): complex.c: remove f_inspect and f_to_s

nobu	2014-03-17 13:57:17 +0900 (Mon, 17 Mar 2014)

  New Revision: 45355

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

  Log:
    complex.c: remove f_inspect and f_to_s
    
    * complex.c (nucomp_to_s): use rb_String.
    
    * complex.c (nucomp_inspect): use rb_inspect.
    
    * complex.c: use PRIsVALUE flag not to use an intermediate string
      which can be collected by GC.

  Modified files:
    trunk/complex.c
Index: complex.c
===================================================================
--- complex.c	(revision 45354)
+++ complex.c	(revision 45355)
@@ -20,8 +20,8 @@ VALUE rb_cComplex; https://github.com/ruby/ruby/blob/trunk/complex.c#L20
 
 static ID id_abs, id_arg, id_convert,
     id_denominator, id_eqeq_p, id_expt, id_fdiv,
-    id_inspect, id_negate, id_numerator, id_quo,
-    id_real_p, id_to_f, id_to_i, id_to_r, id_to_s,
+    id_negate, id_numerator, id_quo,
+    id_real_p, id_to_f, id_to_i, id_to_r,
     id_i_real, id_i_imag;
 
 #define f_boolcast(x) ((x) ? Qtrue : Qfalse)
@@ -130,7 +130,6 @@ f_sub(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/complex.c#L130
 fun1(abs)
 fun1(arg)
 fun1(denominator)
-fun1(inspect)
 fun1(negate)
 fun1(numerator)
 fun1(real_p)
@@ -151,7 +150,6 @@ f_to_f(VALUE x) https://github.com/ruby/ruby/blob/trunk/complex.c#L150
 }
 
 fun1(to_r)
-fun1(to_s)
 
 inline static VALUE
 f_eqeq_p(VALUE x, VALUE y)
@@ -1241,7 +1239,7 @@ f_format(VALUE self, VALUE (*func)(VALUE https://github.com/ruby/ruby/blob/trunk/complex.c#L1239
 static VALUE
 nucomp_to_s(VALUE self)
 {
-    return f_format(self, f_to_s);
+    return f_format(self, rb_String);
 }
 
 /*
@@ -1262,7 +1260,7 @@ nucomp_inspect(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1260
     VALUE s;
 
     s = rb_usascii_str_new2("(");
-    rb_str_concat(s, f_format(self, f_inspect));
+    rb_str_concat(s, f_format(self, rb_inspect));
     rb_str_cat2(s, ")");
 
     return s;
@@ -1359,9 +1357,8 @@ nucomp_to_i(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1357
     get_dat1(self);
 
     if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
-	VALUE s = f_to_s(self);
-	rb_raise(rb_eRangeError, "can't convert %s into Integer",
-		 StringValuePtr(s));
+	rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Integer",
+		 self);
     }
     return f_to_i(dat->real);
 }
@@ -1383,9 +1380,8 @@ nucomp_to_f(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1380
     get_dat1(self);
 
     if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
-	VALUE s = f_to_s(self);
-	rb_raise(rb_eRangeError, "can't convert %s into Float",
-		 StringValuePtr(s));
+	rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Float",
+		 self);
     }
     return f_to_f(dat->real);
 }
@@ -1409,9 +1405,8 @@ nucomp_to_r(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1405
     get_dat1(self);
 
     if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
-	VALUE s = f_to_s(self);
-	rb_raise(rb_eRangeError, "can't convert %s into Rational",
-		 StringValuePtr(s));
+	rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
+		 self);
     }
     return f_to_r(dat->real);
 }
@@ -1437,9 +1432,8 @@ nucomp_rationalize(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/complex.c#L1432
     rb_scan_args(argc, argv, "01", NULL);
 
     if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
-       VALUE s = f_to_s(self);
-       rb_raise(rb_eRangeError, "can't convert %s into Rational",
-                StringValuePtr(s));
+       rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
+                self);
     }
     return rb_funcall2(dat->real, rb_intern("rationalize"), argc, argv);
 }
@@ -1768,9 +1762,8 @@ string_to_c_strict(VALUE self) https://github.com/ruby/ruby/blob/trunk/complex.c#L1762
 	s = (char *)"";
 
     if (!parse_comp(s, 1, &num)) {
-	VALUE ins = f_inspect(self);
-	rb_raise(rb_eArgError, "invalid value for convert(): %s",
-		 StringValuePtr(ins));
+	rb_raise(rb_eArgError, "invalid value for convert(): %+"PRIsVALUE,
+		 self);
     }
 
     return num;
@@ -2053,7 +2046,6 @@ Init_Complex(void) https://github.com/ruby/ruby/blob/trunk/complex.c#L2046
     id_eqeq_p = rb_intern("==");
     id_expt = rb_intern("**");
     id_fdiv = rb_intern("fdiv");
-    id_inspect = rb_intern("inspect");
     id_negate = rb_intern("-@");
     id_numerator = rb_intern("numerator");
     id_quo = rb_intern("quo");
@@ -2061,7 +2053,6 @@ Init_Complex(void) https://github.com/ruby/ruby/blob/trunk/complex.c#L2053
     id_to_f = rb_intern("to_f");
     id_to_i = rb_intern("to_i");
     id_to_r = rb_intern("to_r");
-    id_to_s = rb_intern("to_s");
     id_i_real = rb_intern("@real");
     id_i_imag = rb_intern("@image"); /* @image, not @imag */
 

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

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