summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-13 13:34:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-05-13 13:34:39 +0000
commit7678c0d702663acb326ba9dc9b69f0622a9c0398 (patch)
treec2a1a953c74f515e01e40ff6e1585e211063d519 /string.c
parent7d52ad9e177b32008aba54ae067749d246113e6b (diff)
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.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/string.c b/string.c
index 1d30a153cb..91c262eca9 100644
--- a/string.c
+++ b/string.c
@@ -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