ruby-changes:6632
From: nobu <ko1@a...>
Date: Tue, 22 Jul 2008 04:29:20 +0900 (JST)
Subject: [ruby-changes:6632] Ruby:r18148 (trunk): * include/ruby/intern.h (rb_str_buf_new2): optimization for literals.
nobu 2008-07-22 04:26:18 +0900 (Tue, 22 Jul 2008) New Revision: 18148 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18148 Log: * include/ruby/intern.h (rb_str_buf_new2): optimization for literals. * string.c (str_buf_cat): returns VALUE. Modified files: trunk/ChangeLog trunk/include/ruby/intern.h trunk/string.c Index: include/ruby/intern.h =================================================================== --- include/ruby/intern.h (revision 18147) +++ include/ruby/intern.h (revision 18148) @@ -597,6 +597,13 @@ rb_usascii_str_new(str, strlen(str)) : \ rb_usascii_str_new2(str); \ }) +#define rb_str_buf_new2(str) __extension__ ( \ +{ \ + (__builtin_constant_p(str)) ? \ + rb_str_buf_cat(rb_str_buf_new(strlen(str)), \ + str, strlen(str)) : \ + rb_str_buf_new2(str); \ +}) #define rb_str_buf_cat2(str, ptr) __extension__ ( \ { \ (__builtin_constant_p(ptr)) ? \ Index: ChangeLog =================================================================== --- ChangeLog (revision 18147) +++ ChangeLog (revision 18148) @@ -1,3 +1,9 @@ +Tue Jul 22 04:26:16 2008 Nobuyoshi Nakada <nobu@r...> + + * include/ruby/intern.h (rb_str_buf_new2): optimization for literals. + + * string.c (str_buf_cat): returns VALUE. + Tue Jul 22 03:34:01 2008 Eric Hodel <drbrain@s...> * lib/rdoc*: Update to RDoc 2.1.0 r112. Index: string.c =================================================================== --- string.c (revision 18147) +++ string.c (revision 18148) @@ -28,6 +28,7 @@ #undef rb_str_new2 #undef rb_tainted_str_new2 #undef rb_usascii_str_new2 +#undef rb_str_buf_new2 #undef rb_str_buf_cat2 #undef rb_str_cat2 @@ -1400,7 +1401,7 @@ return str; } -static long +static VALUE str_buf_cat(VALUE str, const char *ptr, long len) { long capa, total, off = -1; @@ -3746,7 +3747,7 @@ { rb_encoding *enc = STR_ENC_GET(str); char *p, *pend; - VALUE result = rb_str_buf_new2(""); + VALUE result = rb_str_buf_new(0); if (!rb_enc_asciicompat(enc)) enc = rb_usascii_encoding(); rb_enc_associate(result, enc); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/