Unverified Commit 9c252410 authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto Committed by GitHub

Merge pull request #4368 from shuujii/use-mrb_immediate_p-in-mrb_obj_freeze-and-mrb_obj_frozen

Use `mrb_immediate_p()` in `mrb_obj_freeze()` and `mrb_obj_frozen()`
parents 4776ac50 7b0ebed0
...@@ -167,6 +167,7 @@ mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f) ...@@ -167,6 +167,7 @@ mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f)
v.value.p = mrb_obj_alloc(mrb, MRB_TT_FLOAT, mrb->float_class); v.value.p = mrb_obj_alloc(mrb, MRB_TT_FLOAT, mrb->float_class);
v.value.fp->f = f; v.value.fp->f = f;
MRB_SET_FROZEN_FLAG(v.value.bp);
return v; return v;
} }
...@@ -177,6 +178,7 @@ mrb_word_boxing_float_pool(mrb_state *mrb, mrb_float f) ...@@ -177,6 +178,7 @@ mrb_word_boxing_float_pool(mrb_state *mrb, mrb_float f)
nf->tt = MRB_TT_FLOAT; nf->tt = MRB_TT_FLOAT;
nf->c = mrb->float_class; nf->c = mrb->float_class;
nf->f = f; nf->f = f;
MRB_SET_FROZEN_FLAG(nf);
return mrb_obj_value(nf); return mrb_obj_value(nf);
} }
#endif /* MRB_WITHOUT_FLOAT */ #endif /* MRB_WITHOUT_FLOAT */
......
...@@ -434,51 +434,19 @@ mrb_obj_extend_m(mrb_state *mrb, mrb_value self) ...@@ -434,51 +434,19 @@ mrb_obj_extend_m(mrb_state *mrb, mrb_value self)
static mrb_value static mrb_value
mrb_obj_freeze(mrb_state *mrb, mrb_value self) mrb_obj_freeze(mrb_state *mrb, mrb_value self)
{ {
struct RBasic *b; if (!mrb_immediate_p(self)) {
struct RBasic *b = mrb_basic_ptr(self);
switch (mrb_type(self)) {
case MRB_TT_FALSE:
case MRB_TT_TRUE:
case MRB_TT_FIXNUM:
case MRB_TT_SYMBOL:
#ifndef MRB_WITHOUT_FLOAT
case MRB_TT_FLOAT:
#endif
return self;
default:
break;
}
b = mrb_basic_ptr(self);
if (!MRB_FROZEN_P(b)) { if (!MRB_FROZEN_P(b)) {
MRB_SET_FROZEN_FLAG(b); MRB_SET_FROZEN_FLAG(b);
} }
}
return self; return self;
} }
static mrb_value static mrb_value
mrb_obj_frozen(mrb_state *mrb, mrb_value self) mrb_obj_frozen(mrb_state *mrb, mrb_value self)
{ {
struct RBasic *b; return mrb_bool_value(mrb_immediate_p(self) || MRB_FROZEN_P(mrb_basic_ptr(self)));
switch (mrb_type(self)) {
case MRB_TT_FALSE:
case MRB_TT_TRUE:
case MRB_TT_FIXNUM:
case MRB_TT_SYMBOL:
#ifndef MRB_WITHOUT_FLOAT
case MRB_TT_FLOAT:
#endif
return mrb_true_value();
default:
break;
}
b = mrb_basic_ptr(self);
if (!MRB_FROZEN_P(b)) {
return mrb_false_value();
}
return mrb_true_value();
} }
/* 15.3.1.3.15 */ /* 15.3.1.3.15 */
......
...@@ -247,6 +247,23 @@ assert('Kernel#freeze') do ...@@ -247,6 +247,23 @@ assert('Kernel#freeze') do
assert_equal obj, obj.freeze assert_equal obj, obj.freeze
assert_equal 0, 0.freeze assert_equal 0, 0.freeze
assert_equal :a, :a.freeze assert_equal :a, :a.freeze
assert_equal true, true.freeze
assert_equal false, false.freeze
assert_equal nil, nil.freeze
skip unless Object.const_defined?(:Float)
assert_equal 0.0, 0.0.freeze
end
assert('Kernel#frozen?') do
assert_false "".frozen?
assert_true "".freeze.frozen?
assert_true 0.frozen?
assert_true :a.frozen?
assert_true true.frozen?
assert_true false.frozen?
assert_true nil.frozen?
skip unless Object.const_defined?(:Float)
assert_true 0.0.frozen?
end end
assert('Kernel#global_variables', '15.3.1.3.14') do assert('Kernel#global_variables', '15.3.1.3.14') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment