ruby-changes:39826
From: nobu <ko1@a...>
Date: Sun, 20 Sep 2015 10:17:41 +0900 (JST)
Subject: [ruby-changes:39826] nobu:r51907 (trunk): string.c: separate resetting code range
nobu 2015-09-20 10:17:25 +0900 (Sun, 20 Sep 2015) New Revision: 51907 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51907 Log: string.c: separate resetting code range * string.c (rb_str_setbyte): separate resetting code range by each code range, and remove unnecessary branches. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 51906) +++ string.c (revision 51907) @@ -4721,38 +4721,30 @@ rb_str_setbyte(VALUE str, VALUE index, V https://github.com/ruby/ruby/blob/trunk/string.c#L4721 switch (cr) { case ENC_CODERANGE_7BIT: left = ptr; - width = 1; - break; + *ptr = byte; + if (ISASCII(byte)) break; + nlen = rb_enc_precise_mbclen(left, head+len, enc); + if (!MBCLEN_CHARFOUND_P(nlen)) + ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN); + else + ENC_CODERANGE_SET(str, ENC_CODERANGE_VALID); + goto end; case ENC_CODERANGE_VALID: left = rb_enc_left_char_head(head, ptr, head+len, enc); width = rb_enc_precise_mbclen(left, head+len, enc); - break; - default: - ENC_CODERANGE_CLEAR(str); + *ptr = byte; + nlen = rb_enc_precise_mbclen(left, head+len, enc); + if (!MBCLEN_CHARFOUND_P(nlen)) + ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN); + else if (MBCLEN_CHARFOUND_LEN(nlen) != width || ISASCII(byte)) + ENC_CODERANGE_CLEAR(str); + goto end; } } - else { - ENC_CODERANGE_CLEAR(str); - } - + ENC_CODERANGE_CLEAR(str); *ptr = byte; - switch (cr) { - case ENC_CODERANGE_7BIT: - if (ISASCII(byte)) break; - case ENC_CODERANGE_VALID: - nlen = rb_enc_precise_mbclen(left, head+len, enc); - if (!MBCLEN_CHARFOUND_P(nlen)) - ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN); - else if (cr == ENC_CODERANGE_7BIT) - ENC_CODERANGE_SET(str, ENC_CODERANGE_VALID); - else if (MBCLEN_CHARFOUND_LEN(nlen) != width) - ENC_CODERANGE_CLEAR(str); - else if (ISASCII(byte)) /* may become 7BIT */ - ENC_CODERANGE_CLEAR(str); - break; - } - + end: return value; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/