summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/ruby/encoding.h9
-rw-r--r--include/ruby/intern.h28
2 files changed, 33 insertions, 4 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
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__ ( \