summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authortmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-04 04:05:13 +0000
committertmm1 <tmm1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-04 04:05:13 +0000
commit753fe47175c0a4d5b8a88498ade2eaa521b91b8f (patch)
treec406a5d7798a46872f22c115109579c8dd93aacd /string.c
parent2dc478cbc2b778f761a3d7d300e21d47ba362b0a (diff)
* string.c (fstr_update_callback): Improve implementation in r43968
based on feedback from @nagachika. In the existing case, we can return ST_STOP to prevent any hash modification. In the !existing case, set both key and value to the fstr. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43986 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/string.c b/string.c
index 0f05656c66..a85676f482 100644
--- a/string.c
+++ b/string.c
@@ -137,23 +137,24 @@ fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existi
{
VALUE *fstr = (VALUE *)arg;
if (existing) {
- /* because of lazy sweep, str may be unmaked already and swept
+ /* because of lazy sweep, str may be unmarked already and swept
* at next time */
rb_gc_resurrect(*fstr = *key);
- } else {
- VALUE str = *key;
- if (STR_SHARED_P(str)) {
- /* str should not be shared */
- str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), STR_ENC_GET(str));
- OBJ_FREEZE(str);
- }
- else {
- str = rb_str_new_frozen(str);
- }
- RBASIC(str)->flags |= RSTRING_FSTR;
- *fstr = *key = str;
+ return ST_STOP;
+ }
+
+ VALUE str = *key;
+ if (STR_SHARED_P(str)) {
+ /* str should not be shared */
+ str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), STR_ENC_GET(str));
+ OBJ_FREEZE(str);
+ }
+ else {
+ str = rb_str_new_frozen(str);
}
+ RBASIC(str)->flags |= RSTRING_FSTR;
+ *key = *value = *fstr = str;
return ST_CONTINUE;
}