diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | internal.h | 14 | ||||
-rw-r--r-- | re.c | 2 | ||||
-rw-r--r-- | string.c | 14 |
4 files changed, 36 insertions, 1 deletions
@@ -1,3 +1,10 @@ +Thu Feb 4 15:35:29 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * string.c (rb_fstring_enc_new, rb_fstring_enc_cstr): functions to + make fstring with encoding. + + * re.c (rb_reg_initialize): make fstring without copying. + Thu Feb 4 14:42:29 2016 Martin Duerst <duerst@it.aoyama.ac.jp> * common.mk: Added Unicode data file SpecialCasing.txt to be additionally diff --git a/internal.h b/internal.h index 0ebda869c6..637ef1619b 100644 --- a/internal.h +++ b/internal.h @@ -1135,6 +1135,20 @@ VALUE rb_fstring_cstr(const char *str); rb_fstring_cstr(str); \ }) #endif +#ifdef RUBY_ENCODING_H +VALUE rb_fstring_enc_new(const char *ptr, long len, rb_encoding *enc); +#define rb_fstring_enc_lit(str, enc) rb_fstring_enc_new((str), rb_strlen_lit(str), (enc)) +#define rb_fstring_enc_literal(str, enc) rb_fstring_enc_lit(str, enc) +VALUE rb_fstring_enc_cstr(const char *ptr, rb_encoding *enc); +#if defined(__GNUC__) && !defined(__PCC__) +#define rb_fstring_enc_cstr(str, enc) __extension__ ( \ +{ \ + (__builtin_constant_p(str)) ? \ + rb_fstring_enc_new((str), (long)strlen(str), (enc)) : \ + rb_fstring_enc_cstr(str, enc); \ +}) +#endif +#endif int rb_str_buf_cat_escaped_char(VALUE result, unsigned int c, int unicode_p); int rb_str_symname_p(VALUE); VALUE rb_str_quote_unprintable(VALUE); @@ -2580,7 +2580,7 @@ rb_reg_initialize(VALUE obj, const char *s, long len, rb_encoding *enc, options & ARG_REG_OPTION_MASK, err, sourcefile, sourceline); if (!re->ptr) return -1; - RB_OBJ_WRITE(obj, &re->src, rb_fstring(rb_enc_str_new(s, len, enc))); + RB_OBJ_WRITE(obj, &re->src, rb_fstring_enc_new(s, len, enc)); RB_GC_GUARD(unescaped); return 0; } @@ -49,6 +49,7 @@ #undef rb_str_cat2 #undef rb_str_cat_cstr #undef rb_fstring_cstr +#undef rb_fstring_enc_cstr static VALUE rb_str_clear(VALUE str); @@ -360,11 +361,24 @@ rb_fstring_new(const char *ptr, long len) } VALUE +rb_fstring_enc_new(const char *ptr, long len, rb_encoding *enc) +{ + struct RString fake_str; + return register_fstring(rb_setup_fake_str(&fake_str, ptr, len, enc)); +} + +VALUE rb_fstring_cstr(const char *ptr) { return rb_fstring_new(ptr, strlen(ptr)); } +VALUE +rb_fstring_enc_cstr(const char *ptr, rb_encoding *enc) +{ + return rb_fstring_enc_new(ptr, strlen(ptr), enc); +} + static int fstring_set_class_i(st_data_t key, st_data_t val, st_data_t arg) { |