From 47c5f0cc3285fd4d6e95cad0f72c8491a101c275 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sat, 24 Jun 2017 23:33:43 +0900 Subject: 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. --- string.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'string.c') 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); -- cgit v1.2.3