diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-19 05:53:00 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-09-19 05:53:00 +0000 |
commit | abac84856448e8a15e941cce8c1e48f891e83a3c (patch) | |
tree | b2e152124af84f23be18ae6e3a18ccfdcafaab35 /include/ruby/intern.h | |
parent | 990845662cd4284a73ecc926c33cd1c8efb82354 (diff) |
string.c: rb_str_new_static
* string.c (rb_str_new_static): create string object with static
buffer. incorporated from mruby.
* string.c (rb_{usascii,utf8,enc}_str_new_static): ditto with
encodings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include/ruby/intern.h')
-rw-r--r-- | include/ruby/intern.h | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/include/ruby/intern.h b/include/ruby/intern.h index ecb4ba7781..b8377bc5b2 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -710,6 +710,9 @@ VALUE rb_usascii_str_new(const char*, long); VALUE rb_usascii_str_new_cstr(const char*); VALUE rb_utf8_str_new(const char*, long); VALUE rb_utf8_str_new_cstr(const char*); +VALUE rb_str_new_static(const char *, long); +VALUE rb_usascii_str_new_static(const char *, long); +VALUE rb_utf8_str_new_static(const char *, long); void rb_str_free(VALUE); void rb_str_shared_replace(VALUE, VALUE); VALUE rb_str_buf_append(VALUE, VALUE); @@ -771,13 +774,32 @@ long rb_str_offset(VALUE, long); size_t rb_str_capacity(VALUE); VALUE rb_str_ellipsize(VALUE, long); VALUE rb_str_scrub(VALUE, VALUE); + #if defined(__GNUC__) && !defined(__PCC__) +#define rb_str_new(str, len) __extension__ ( \ +{ \ + (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \ + rb_str_new_static((str), (len)) : \ + rb_str_new((str), (len)); \ +}) #define rb_str_new_cstr(str) __extension__ ( \ { \ (__builtin_constant_p(str)) ? \ - rb_str_new((str), (long)strlen(str)) : \ + rb_str_new_static((str), (long)strlen(str)) : \ rb_str_new_cstr(str); \ }) +#define rb_usascii_str_new(str, len) __extension__ ( \ +{ \ + (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \ + rb_usascii_str_new_static((str), (len)) : \ + rb_usascii_str_new((str), (len)); \ +}) +#define rb_utf8_str_new(str, len) __extension__ ( \ +{ \ + (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \ + rb_utf8_str_new_static((str), (len)) : \ + rb_utf8_str_new((str), (len)); \ +}) #define rb_tainted_str_new_cstr(str) __extension__ ( \ { \ (__builtin_constant_p(str)) ? \ @@ -787,13 +809,13 @@ VALUE rb_str_scrub(VALUE, VALUE); #define rb_usascii_str_new_cstr(str) __extension__ ( \ { \ (__builtin_constant_p(str)) ? \ - rb_usascii_str_new((str), (long)strlen(str)) : \ + rb_usascii_str_new_static((str), (long)strlen(str)) : \ rb_usascii_str_new_cstr(str); \ }) #define rb_utf8_str_new_cstr(str) __extension__ ( \ { \ (__builtin_constant_p(str)) ? \ - rb_utf8_str_new((str), (long)strlen(str)) : \ + rb_utf8_str_new_static((str), (long)strlen(str)) : \ rb_utf8_str_new_cstr(str); \ }) #define rb_external_str_new_cstr(str) __extension__ ( \ |