ruby-changes:46587
From: nobu <ko1@a...>
Date: Sat, 13 May 2017 22:34:46 +0900 (JST)
Subject: [ruby-changes:46587] nobu:r58703 (trunk): string.c: cut down intermediate string
nobu 2017-05-13 22:34:39 +0900 (Sat, 13 May 2017) New Revision: 58703 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58703 Log: string.c: cut down intermediate string * string.c (rb_external_str_new_with_enc): cut down intermediate string for conversion source, by appending with conversion. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 58702) +++ string.c (revision 58703) @@ -997,10 +997,20 @@ rb_str_conv_enc(VALUE str, rb_encoding * https://github.com/ruby/ruby/blob/trunk/string.c#L997 VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *eenc) { + rb_encoding *ienc; VALUE str; - str = rb_tainted_str_new_with_enc(ptr, len, eenc); - return rb_external_str_with_enc(str, eenc); + if (!eenc || (eenc == rb_ascii8bit_encoding()) || + (eenc == rb_usascii_encoding() && search_nonascii(ptr, ptr + len))) { + return rb_tainted_str_new(ptr, len); + } + ienc = rb_default_internal_encoding(); + if (!ienc || eenc == ienc) { + return rb_tainted_str_new_with_enc(ptr, len, eenc); + } + str = rb_tainted_str_new_with_enc(NULL, len, ienc); + rb_str_cat_conv_enc_opts(str, 0, ptr, len, eenc, 0, Qnil); + return str; } VALUE -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/