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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45355 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6224216294
commit
77f3da02a0
37
complex.c
37
complex.c
@ -20,8 +20,8 @@ VALUE rb_cComplex;
|
|||||||
|
|
||||||
static ID id_abs, id_arg, id_convert,
|
static ID id_abs, id_arg, id_convert,
|
||||||
id_denominator, id_eqeq_p, id_expt, id_fdiv,
|
id_denominator, id_eqeq_p, id_expt, id_fdiv,
|
||||||
id_inspect, id_negate, id_numerator, id_quo,
|
id_negate, id_numerator, id_quo,
|
||||||
id_real_p, id_to_f, id_to_i, id_to_r, id_to_s,
|
id_real_p, id_to_f, id_to_i, id_to_r,
|
||||||
id_i_real, id_i_imag;
|
id_i_real, id_i_imag;
|
||||||
|
|
||||||
#define f_boolcast(x) ((x) ? Qtrue : Qfalse)
|
#define f_boolcast(x) ((x) ? Qtrue : Qfalse)
|
||||||
@ -130,7 +130,6 @@ f_sub(VALUE x, VALUE y)
|
|||||||
fun1(abs)
|
fun1(abs)
|
||||||
fun1(arg)
|
fun1(arg)
|
||||||
fun1(denominator)
|
fun1(denominator)
|
||||||
fun1(inspect)
|
|
||||||
fun1(negate)
|
fun1(negate)
|
||||||
fun1(numerator)
|
fun1(numerator)
|
||||||
fun1(real_p)
|
fun1(real_p)
|
||||||
@ -151,7 +150,6 @@ f_to_f(VALUE x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun1(to_r)
|
fun1(to_r)
|
||||||
fun1(to_s)
|
|
||||||
|
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
f_eqeq_p(VALUE x, VALUE y)
|
f_eqeq_p(VALUE x, VALUE y)
|
||||||
@ -1241,7 +1239,7 @@ f_format(VALUE self, VALUE (*func)(VALUE))
|
|||||||
static VALUE
|
static VALUE
|
||||||
nucomp_to_s(VALUE self)
|
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)
|
|||||||
VALUE s;
|
VALUE s;
|
||||||
|
|
||||||
s = rb_usascii_str_new2("(");
|
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, ")");
|
rb_str_cat2(s, ")");
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@ -1359,9 +1357,8 @@ nucomp_to_i(VALUE self)
|
|||||||
get_dat1(self);
|
get_dat1(self);
|
||||||
|
|
||||||
if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
|
if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
|
||||||
VALUE s = f_to_s(self);
|
rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Integer",
|
||||||
rb_raise(rb_eRangeError, "can't convert %s into Integer",
|
self);
|
||||||
StringValuePtr(s));
|
|
||||||
}
|
}
|
||||||
return f_to_i(dat->real);
|
return f_to_i(dat->real);
|
||||||
}
|
}
|
||||||
@ -1383,9 +1380,8 @@ nucomp_to_f(VALUE self)
|
|||||||
get_dat1(self);
|
get_dat1(self);
|
||||||
|
|
||||||
if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
|
if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
|
||||||
VALUE s = f_to_s(self);
|
rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Float",
|
||||||
rb_raise(rb_eRangeError, "can't convert %s into Float",
|
self);
|
||||||
StringValuePtr(s));
|
|
||||||
}
|
}
|
||||||
return f_to_f(dat->real);
|
return f_to_f(dat->real);
|
||||||
}
|
}
|
||||||
@ -1409,9 +1405,8 @@ nucomp_to_r(VALUE self)
|
|||||||
get_dat1(self);
|
get_dat1(self);
|
||||||
|
|
||||||
if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
|
if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
|
||||||
VALUE s = f_to_s(self);
|
rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
|
||||||
rb_raise(rb_eRangeError, "can't convert %s into Rational",
|
self);
|
||||||
StringValuePtr(s));
|
|
||||||
}
|
}
|
||||||
return f_to_r(dat->real);
|
return f_to_r(dat->real);
|
||||||
}
|
}
|
||||||
@ -1437,9 +1432,8 @@ nucomp_rationalize(int argc, VALUE *argv, VALUE self)
|
|||||||
rb_scan_args(argc, argv, "01", NULL);
|
rb_scan_args(argc, argv, "01", NULL);
|
||||||
|
|
||||||
if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
|
if (k_inexact_p(dat->imag) || f_nonzero_p(dat->imag)) {
|
||||||
VALUE s = f_to_s(self);
|
rb_raise(rb_eRangeError, "can't convert %"PRIsVALUE" into Rational",
|
||||||
rb_raise(rb_eRangeError, "can't convert %s into Rational",
|
self);
|
||||||
StringValuePtr(s));
|
|
||||||
}
|
}
|
||||||
return rb_funcall2(dat->real, rb_intern("rationalize"), argc, argv);
|
return rb_funcall2(dat->real, rb_intern("rationalize"), argc, argv);
|
||||||
}
|
}
|
||||||
@ -1768,9 +1762,8 @@ string_to_c_strict(VALUE self)
|
|||||||
s = (char *)"";
|
s = (char *)"";
|
||||||
|
|
||||||
if (!parse_comp(s, 1, &num)) {
|
if (!parse_comp(s, 1, &num)) {
|
||||||
VALUE ins = f_inspect(self);
|
rb_raise(rb_eArgError, "invalid value for convert(): %+"PRIsVALUE,
|
||||||
rb_raise(rb_eArgError, "invalid value for convert(): %s",
|
self);
|
||||||
StringValuePtr(ins));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return num;
|
return num;
|
||||||
@ -2053,7 +2046,6 @@ Init_Complex(void)
|
|||||||
id_eqeq_p = rb_intern("==");
|
id_eqeq_p = rb_intern("==");
|
||||||
id_expt = rb_intern("**");
|
id_expt = rb_intern("**");
|
||||||
id_fdiv = rb_intern("fdiv");
|
id_fdiv = rb_intern("fdiv");
|
||||||
id_inspect = rb_intern("inspect");
|
|
||||||
id_negate = rb_intern("-@");
|
id_negate = rb_intern("-@");
|
||||||
id_numerator = rb_intern("numerator");
|
id_numerator = rb_intern("numerator");
|
||||||
id_quo = rb_intern("quo");
|
id_quo = rb_intern("quo");
|
||||||
@ -2061,7 +2053,6 @@ Init_Complex(void)
|
|||||||
id_to_f = rb_intern("to_f");
|
id_to_f = rb_intern("to_f");
|
||||||
id_to_i = rb_intern("to_i");
|
id_to_i = rb_intern("to_i");
|
||||||
id_to_r = rb_intern("to_r");
|
id_to_r = rb_intern("to_r");
|
||||||
id_to_s = rb_intern("to_s");
|
|
||||||
id_i_real = rb_intern("@real");
|
id_i_real = rb_intern("@real");
|
||||||
id_i_imag = rb_intern("@image"); /* @image, not @imag */
|
id_i_imag = rb_intern("@image"); /* @image, not @imag */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user