avoid unnecessary string duplications by checking the frozen flag

This commit is contained in:
Kazuho Oku
2015-09-10 22:50:01 +09:00
parent 44eb1492be
commit 8256d77c7f
+3 -4
View File
@@ -104,12 +104,11 @@ static void mrb_hash_modify(mrb_state *mrb, mrb_value hash);
static inline mrb_value
mrb_hash_ht_key(mrb_state *mrb, mrb_value key)
{
if (mrb_string_p(key)) {
if (mrb_string_p(key) && !RSTR_FROZEN_P(mrb_str_ptr(key))) {
key = mrb_str_dup(mrb, key);
RSTR_SET_FROZEN_FLAG(mrb_str_ptr(key));
return key;
} else
return key;
}
return key;
}
#define KEY(key) mrb_hash_ht_key(mrb, key)