summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-26 06:18:28 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-10-26 06:18:28 +0000
commit81c849172d341b9fcae618c33dc44c2c91827b97 (patch)
treef218accf828560d54160c7bb7c17e4f5828f5e9b /hash.c
parent1e83e15ab55c427fe89c7497d7d813b5a884401f (diff)
Simplify conditions [Feature #15251]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/hash.c b/hash.c
index 3f278e0..d872c4b 100644
--- a/hash.c
+++ b/hash.c
@@ -1565,36 +1565,24 @@ hash_aset(st_data_t *key, st_data_t *val, struct update_arg *arg, int existing)
}
static VALUE
-fstring_existing_str(VALUE str)
+fstring_key_str(VALUE str)
{
st_data_t fstr;
st_table *tbl = rb_vm_fstring_table();
- if (st_lookup(tbl, str, &fstr)) {
- if (rb_objspace_garbage_object_p(fstr)) {
- return rb_fstring(str);
- }
- else {
- return (VALUE)fstr;
- }
+ if (st_lookup(tbl, str, &fstr) && !rb_objspace_garbage_object_p(fstr)) {
+ return (VALUE)fstr;
}
else {
- return Qnil;
+ return rb_fstring(str);
}
}
VALUE
rb_hash_key_str(VALUE key)
{
- VALUE k;
- int not_tainted = !RB_OBJ_TAINTED(key);
-
- if (not_tainted &&
- (k = fstring_existing_str(key)) != Qnil) {
- return k;
- }
- else if(not_tainted) {
- return rb_fstring(key);
+ if (!FL_ANY_RAW(key, FL_TAINT|FL_SINGLETON)) {
+ return fstring_key_str(key);
}
else {
return rb_str_new_frozen(key);