ruby-changes:9022
From: yugui <ko1@a...>
Date: Fri, 5 Dec 2008 22:36:00 +0900 (JST)
Subject: [ruby-changes:9022] Ruby:r20558 (ruby_1_9_1): merges r20547 from trunk into ruby_1_9_1.
yugui 2008-12-05 22:35:06 +0900 (Fri, 05 Dec 2008) New Revision: 20558 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20558 Log: merges r20547 from trunk into ruby_1_9_1. * rational.c (nurat_{to_s,inspect}): performance improvement. Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/rational.c Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20557) +++ ruby_1_9_1/ChangeLog (revision 20558) @@ -1,3 +1,7 @@ +Fri Dec 5 21:45:45 2008 Tadayoshi Funaba <tadf@d...> + + * rational.c (nurat_{to_s,inspect}): performance improvement. + Fri Dec 5 21:42:44 2008 Tadayoshi Funaba <tadf@d...> * complex.c: inpsect should not depend on to_s. Index: ruby_1_9_1/rational.c =================================================================== --- ruby_1_9_1/rational.c (revision 20557) +++ ruby_1_9_1/rational.c (revision 20558) @@ -27,8 +27,8 @@ VALUE rb_cRational; static ID id_abs, id_cmp, id_convert, id_equal_p, id_expt, id_floor, - id_format, id_hash, id_idiv, id_inspect, id_integer_p, id_negate, - id_to_f, id_to_i, id_to_s, id_truncate; + id_hash, id_idiv, id_inspect, id_integer_p, id_negate, id_to_f, + id_to_i, id_to_s, id_truncate; #define f_boolcast(x) ((x) ? Qtrue : Qfalse) @@ -1111,19 +1111,34 @@ } static VALUE -nurat_to_s(VALUE self) +nurat_format(VALUE self, VALUE (*func)(VALUE)) { + VALUE s; get_dat1(self); - return rb_funcall(rb_mKernel, id_format, 3, - rb_str_new2("%d/%d"), dat->num, dat->den); + + s = (*func)(dat->num); + rb_str_cat2(s, "/"); + rb_str_concat(s, (*func)(dat->den)); + + return s; } static VALUE +nurat_to_s(VALUE self) +{ + return nurat_format(self, f_to_s); +} + +static VALUE nurat_inspect(VALUE self) { - get_dat1(self); - return rb_funcall(rb_mKernel, id_format, 3, - rb_str_new2("(%d/%d)"), dat->num, dat->den); + VALUE s; + + s = rb_str_new2("("); + rb_str_concat(s, nurat_format(self, f_inspect)); + rb_str_cat2(s, ")"); + + return s; } static VALUE @@ -1484,7 +1499,6 @@ id_equal_p = rb_intern("=="); id_expt = rb_intern("**"); id_floor = rb_intern("floor"); - id_format = rb_intern("format"); id_hash = rb_intern("hash"); id_idiv = rb_intern("div"); id_inspect = rb_intern("inspect"); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/