summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-20 01:17:25 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-09-20 01:17:25 (GMT)
commit6177abcbf079c1f398c8bb681dc339af24d52d91 (patch)
tree8ca1bb3b0361bb3bdce428c4b7249f31330a1005 /string.c
parent9bc67e1efad5ec6c54d34d290057268a89886a4c (diff)
string.c: separate resetting code range
* string.c (rb_str_setbyte): separate resetting code range by each code range, and remove unnecessary branches. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c42
1 files changed, 17 insertions, 25 deletions
diff --git a/string.c b/string.c
index fd86b8b..e93af5c 100644
--- a/string.c
+++ b/string.c
@@ -4721,38 +4721,30 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value)
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;
}