From c353ec0c9e8e941f49910a51f7dc10cf3d3cdd17 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 2 May 2016 03:58:28 +0000 Subject: [PATCH] string.c: shortcut * string.c (rb_str_concat): shortcut concatenation to ASCII-8BIT as well as US-ASCII. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54882 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/string.c b/string.c index a22505f592..35e53f7306 100644 --- a/string.c +++ b/string.c @@ -2742,6 +2742,7 @@ rb_str_concat(VALUE str1, VALUE str2) { unsigned int code; rb_encoding *enc = STR_ENC_GET(str1); + int encidx; if (FIXNUM_P(str2) || RB_TYPE_P(str2, T_BIGNUM)) { if (rb_num_to_uint(str2, &code) == 0) { @@ -2757,7 +2758,8 @@ rb_str_concat(VALUE str1, VALUE str2) return rb_str_append(str1, str2); } - if (enc == rb_usascii_encoding()) { + encidx = rb_enc_to_index(enc); + if (encidx == ENCINDEX_ASCII || encidx == ENCINDEX_US_ASCII) { /* US-ASCII automatically extended to ASCII-8BIT */ char buf[1]; buf[0] = (char)code; @@ -2765,8 +2767,8 @@ rb_str_concat(VALUE str1, VALUE str2) rb_raise(rb_eRangeError, "%u out of char range", code); } rb_str_cat(str1, buf, 1); - if (code > 127) { - rb_enc_associate_index(str1, rb_ascii8bit_encindex()); + if (encidx == ENCINDEX_US_ASCII && code > 127) { + rb_enc_associate_index(str1, ENCINDEX_ASCII); ENC_CODERANGE_SET(str1, ENC_CODERANGE_VALID); } }