ruby-changes:42808
From: nobu <ko1@a...>
Date: Mon, 2 May 2016 12:01:51 +0900 (JST)
Subject: [ruby-changes:42808] nobu:r54882 (trunk): string.c: shortcut
nobu 2016-05-02 12:58:28 +0900 (Mon, 02 May 2016) New Revision: 54882 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54882 Log: string.c: shortcut * string.c (rb_str_concat): shortcut concatenation to ASCII-8BIT as well as US-ASCII. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 54881) +++ string.c (revision 54882) @@ -2742,6 +2742,7 @@ rb_str_concat(VALUE str1, VALUE str2) https://github.com/ruby/ruby/blob/trunk/string.c#L2742 { 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) https://github.com/ruby/ruby/blob/trunk/string.c#L2758 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) https://github.com/ruby/ruby/blob/trunk/string.c#L2767 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); } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/