From d00e7deb5c780d75e4edd3afa3e26ea02c296d8c Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Sat, 23 Jan 2021 10:15:22 +0100 Subject: [PATCH] Use rb_enc_interned_str in ibf_load_object_string --- compile.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compile.c b/compile.c index 898b02e6ff..ce50168cb2 100644 --- a/compile.c +++ b/compile.c @@ -11389,17 +11389,20 @@ ibf_load_object_string(const struct ibf_load *load, const struct ibf_object_head const long len = (long)ibf_load_small_value(load, &reading_pos); const char *ptr = load->current_buffer->buff + reading_pos; - VALUE str = rb_str_new(ptr, len); - if (encindex > RUBY_ENCINDEX_BUILTIN_MAX) { VALUE enc_name_str = ibf_load_object(load, encindex - RUBY_ENCINDEX_BUILTIN_MAX); encindex = rb_enc_find_index(RSTRING_PTR(enc_name_str)); } - rb_enc_associate_index(str, encindex); - if (header->internal) rb_obj_hide(str); - if (header->frozen) str = rb_fstring(str); + VALUE str; + if (header->frozen && !header->internal) { + str = rb_enc_interned_str(ptr, len, rb_enc_from_index(encindex)); + } else { + str = rb_enc_str_new(ptr, len, rb_enc_from_index(encindex)); + if (header->internal) rb_obj_hide(str); + if (header->frozen) str = rb_fstring(str); + } return str; }