aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-06-24 23:33:43 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-06-26 15:23:03 +0900
commit47c5f0cc3285fd4d6e95cad0f72c8491a101c275 (patch)
treeddec9b40f2faf1eea1727ded6918e9be77d2db70
parentd9e4b1c9bb179466743d941dc45de5993a027599 (diff)
downloadruby-47c5f0cc3285fd4d6e95cad0f72c8491a101c275.tar.gz
string.c: preserve coderange in #setbyte
Do not clear the coderange when 1) the string is heap-allocated, 2) the current coderange is 7bit, 3) the new byte is an ASCII character.
-rw-r--r--string.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/string.c b/string.c
index 22664febfd..2012a281d6 100644
--- a/string.c
+++ b/string.c
@@ -5279,13 +5279,13 @@ rb_str_setbyte(VALUE str, VALUE index, VALUE value)
enc = STR_ENC_GET(str);
head = RSTRING_PTR(str);
ptr = &head[pos];
- if (!STR_EMBEDDABLE_P(len, rb_enc_mbminlen(enc))) {
+ if (!STR_EMBED_P(str)) {
cr = ENC_CODERANGE(str);
switch (cr) {
case ENC_CODERANGE_7BIT:
left = ptr;
*ptr = byte;
- if (ISASCII(byte)) break;
+ if (ISASCII(byte)) goto end;
nlen = rb_enc_precise_mbclen(left, head+len, enc);
if (!MBCLEN_CHARFOUND_P(nlen))
ENC_CODERANGE_SET(str, ENC_CODERANGE_BROKEN);