From 5ffd0cc80fda095b69660fb4ae72ffd227e9f7b7 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 21 Jul 2008 19:26:18 +0000 Subject: [PATCH] * include/ruby/intern.h (rb_str_buf_new2): optimization for literals. * string.c (str_buf_cat): returns VALUE. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ include/ruby/intern.h | 7 +++++++ string.c | 5 +++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a9f8af46b2..a4b8603323 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Tue Jul 22 04:26:16 2008 Nobuyoshi Nakada + + * 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 * lib/rdoc*: Update to RDoc 2.1.0 r112. diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 29fa2c2a2c..3d63c3877b 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -597,6 +597,13 @@ VALUE rb_str_length(VALUE); 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)) ? \ diff --git a/string.c b/string.c index 13c98ad332..387786fe07 100644 --- a/string.c +++ b/string.c @@ -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 @@ rb_str_resize(VALUE str, long len) 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_str_inspect(VALUE str) { 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);