diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-13 13:34:39 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-13 13:34:39 +0000 |
commit | 67e1600c1974bc91c49f058bb93495ea6db9439c (patch) | |
tree | c2a1a953c74f515e01e40ff6e1585e211063d519 /string.c | |
parent | 233e4689a3da0ea6d7b70abdbae5dd67f2eebb06 (diff) | |
download | ruby-67e1600c1974bc91c49f058bb93495ea6db9439c.tar.gz |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -997,10 +997,20 @@ rb_str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to) 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 |