register_fstring: avoid duping the passed string when possible

If the passed string is frozen, bare and not shared, then there
is no need to duplicate it.

Ref: 4ab69ebbd7
Ref: https://bugs.ruby-lang.org/issues/11386
This commit is contained in:
Jean Boussier 2020-08-19 11:29:54 +02:00 committed by Aaron Patterson
parent 7f0ea20581
commit aaf0e33c0a
Notes: git 2020-08-20 00:09:32 +09:00
2 changed files with 18 additions and 1 deletions

View file

@ -305,7 +305,8 @@ fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existi
OBJ_FREEZE_RAW(str);
}
else {
str = str_new_frozen(rb_cString, str);
if (!OBJ_FROZEN(str))
str = str_new_frozen(rb_cString, str);
if (STR_SHARED_P(str)) { /* str should not be shared */
/* shared substring */
str_make_independent(str);