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/encoding.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/encoding.h')
-rw-r--r-- | include/ruby/encoding.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index 4a5324d62e..7d33e538de 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -91,6 +91,7 @@ void rb_enc_copy(VALUE dst, VALUE src); VALUE rb_enc_str_new(const char*, long, rb_encoding*); VALUE rb_enc_str_new_cstr(const char*, rb_encoding*); +VALUE rb_enc_str_new_static(const char*, long, rb_encoding*); VALUE rb_enc_reg_new(const char*, long, rb_encoding*, int); PRINTF_ARGS(VALUE rb_enc_sprintf(rb_encoding *, const char*, ...), 2, 3); VALUE rb_enc_vsprintf(rb_encoding *, const char*, va_list); @@ -106,10 +107,16 @@ VALUE rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to); VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts); #if defined(__GNUC__) && !defined(__PCC__) +#define rb_enc_str_new(str, len, enc) __extension__ ( \ +{ \ + (__builtin_constant_p(str) && __builtin_constant_p(len)) ? \ + rb_enc_str_new_static((str), (len), (enc)) : \ + rb_enc_str_new((str), (len), (enc)); \ +}) #define rb_enc_str_new_cstr(str, enc) __extension__ ( \ { \ (__builtin_constant_p(str)) ? \ - rb_enc_str_new((str), (long)strlen(str), (enc)) : \ + rb_enc_str_new_static((str), (long)strlen(str), (enc)) : \ rb_enc_str_new_cstr((str), (enc)); \ }) #endif |