diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | include/ruby/intern.h | 23 |
2 files changed, 22 insertions, 6 deletions
@@ -1,7 +1,8 @@ -Sat Jun 28 20:50:35 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> +Sat Jun 28 21:15:43 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> * include/ruby/intern.h (rb_str_new2, rb_tainted_str_new2, - rb_usascii_str_new2): use inline versions for gcc 4 or lator. + rb_usascii_str_new2): use inline versions only for constant + literals. Sat Jun 28 13:12:06 2008 Tanaka Akira <akr@fsij.org> diff --git a/include/ruby/intern.h b/include/ruby/intern.h index f109cf75ef..734bdfa7a8 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -535,10 +535,25 @@ VALUE rb_str_buf_new2(const char*); VALUE rb_str_tmp_new(long); VALUE rb_usascii_str_new(const char*, long); VALUE rb_usascii_str_new2(const char*); -#if __GNUC__ >= 4 && defined __OPTIMIZE__ && __OPTIMIZE__ -#define rb_str_new2(str) ({const char *_s = (str); rb_str_new(_s, strlen(_s));}) -#define rb_tainted_str_new2(str) ({const char *_s = (str); rb_tainted_str_new(_s, strlen(_s));}) -#define rb_usascii_str_new2(str) ({const char *_s = (str); rb_usascii_str_new(_s, strlen(_s));}) +#if defined __GNUC__ +#define rb_str_new2(str) ( \ +{ \ + (__builtin_constant_p(str)) ? \ + rb_str_new(str, strlen(str)) : \ + rb_str_new2(str); \ +}) +#define rb_tainted_str_new2(str) ( \ +{ \ + (__builtin_constant_p(str)) ? \ + rb_tainted_str_new(str, strlen(str)) : \ + rb_tainted_str_new2(str); \ +}) +#define rb_usascii_str_new2(str) ( \ +{ \ + (__builtin_constant_p(str)) ? \ + rb_usascii_str_new(str, strlen(str)) : \ + rb_usascii_str_new2(str); \ +}) #endif void rb_str_free(VALUE); void rb_str_shared_replace(VALUE, VALUE); |