ruby-changes:47332
From: nobu <ko1@a...>
Date: Sun, 30 Jul 2017 11:56:36 +0900 (JST)
Subject: [ruby-changes:47332] nobu:r59448 (trunk): string.c: rb_str_initialize
nobu 2017-07-30 11:56:29 +0900 (Sun, 30 Jul 2017) New Revision: 59448 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59448 Log: string.c: rb_str_initialize * string.c (rb_str_initialize): new function to (re)initialize a string with data and encoding. extracted from rb_external_str_new_with_enc. Modified files: trunk/internal.h trunk/string.c Index: internal.h =================================================================== --- internal.h (revision 59447) +++ internal.h (revision 59448) @@ -1630,6 +1630,7 @@ VALUE rb_external_str_with_enc(VALUE str https://github.com/ruby/ruby/blob/trunk/internal.h#L1630 VALUE rb_str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len, rb_encoding *from, int ecflags, VALUE ecopts); VALUE rb_enc_str_scrub(rb_encoding *enc, VALUE str, VALUE repl); +VALUE rb_str_initialize(VALUE str, const char *ptr, long len, rb_encoding *enc); #endif #define STR_NOEMBED FL_USER1 #define STR_SHARED FL_USER2 /* = ELTS_SHARED */ Index: string.c =================================================================== --- string.c (revision 59447) +++ string.c (revision 59448) @@ -932,6 +932,15 @@ rb_str_cat_conv_enc_opts(VALUE newstr, l https://github.com/ruby/ruby/blob/trunk/string.c#L932 ecflags, ecopts); } +VALUE +rb_str_initialize(VALUE str, const char *ptr, long len, rb_encoding *enc) +{ + STR_SET_LEN(str, 0); + rb_enc_associate(str, enc); + rb_str_cat(str, ptr, len); + return str; +} + static VALUE str_cat_conv_enc_opts(VALUE newstr, long ofs, const char *ptr, long len, rb_encoding *from, rb_encoding *to, @@ -1024,9 +1033,7 @@ rb_external_str_new_with_enc(const char https://github.com/ruby/ruby/blob/trunk/string.c#L1033 /* when the conversion failed for some reason, just ignore the * default_internal and result in the given encoding as-is. */ if (NIL_P(rb_str_cat_conv_enc_opts(str, 0, ptr, len, eenc, 0, Qnil))) { - STR_SET_LEN(str, 0); - rb_enc_associate(str, eenc); - rb_str_cat(str, ptr, len); + rb_str_initialize(str, ptr, len, eenc); } return str; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/