ruby-changes:41662
From: nobu <ko1@a...>
Date: Thu, 4 Feb 2016 15:35:36 +0900 (JST)
Subject: [ruby-changes:41662] nobu:r53736 (trunk): fstring_enc_new
nobu 2016-02-04 15:35:34 +0900 (Thu, 04 Feb 2016) New Revision: 53736 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53736 Log: fstring_enc_new * 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. Modified files: trunk/ChangeLog trunk/internal.h trunk/re.c trunk/string.c Index: internal.h =================================================================== --- internal.h (revision 53735) +++ internal.h (revision 53736) @@ -1135,6 +1135,20 @@ VALUE rb_fstring_cstr(const char *str); https://github.com/ruby/ruby/blob/trunk/internal.h#L1135 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); Index: string.c =================================================================== --- string.c (revision 53735) +++ string.c (revision 53736) @@ -49,6 +49,7 @@ https://github.com/ruby/ruby/blob/trunk/string.c#L49 #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 https://github.com/ruby/ruby/blob/trunk/string.c#L361 } 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) { Index: re.c =================================================================== --- re.c (revision 53735) +++ re.c (revision 53736) @@ -2580,7 +2580,7 @@ rb_reg_initialize(VALUE obj, const char https://github.com/ruby/ruby/blob/trunk/re.c#L2580 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; } Index: ChangeLog =================================================================== --- ChangeLog (revision 53735) +++ ChangeLog (revision 53736) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Feb 4 15:35:29 2016 Nobuyoshi Nakada <nobu@r...> + + * 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@i...> * common.mk: Added Unicode data file SpecialCasing.txt to be additionally -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/