summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2020-08-19 11:29:54 +0200
committerAaron Patterson <aaron.patterson@gmail.com>2020-08-19 08:08:56 -0700
commitaaf0e33c0a45e13d27e1009c7298fcb0a57c0d4f (patch)
tree46893bf3c8748d669a59ae430d940a0c5fa26140 /string.c
parent7f0ea20581082f627c2569fde3c69dc14a663b37 (diff)
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: 4ab69ebbd7cef8539f687e1f948845d076461dc6 Ref: https://bugs.ruby-lang.org/issues/11386
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3430
Diffstat (limited to 'string.c')
-rw-r--r--string.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/string.c b/string.c
index 1a1b9fd6ed..df7e81410a 100644
--- a/string.c
+++ b/string.c
@@ -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);