mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
object.c: rb_obj_copy_ivar
* object.c (rb_obj_copy_ivar): extract function to copy instance variables only for T_OBJECT from init_copy. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
972046f084
commit
cf3890205f
3 changed files with 31 additions and 19 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Mon Jun 23 11:32:59 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* object.c (rb_obj_copy_ivar): extract function to copy instance
|
||||||
|
variables only for T_OBJECT from init_copy.
|
||||||
|
|
||||||
Mon Jun 23 11:11:16 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Jun 23 11:11:16 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* signal.c (check_stack_overflow): drop the last tag too close to
|
* signal.c (check_stack_overflow): drop the last tag too close to
|
||||||
|
|
|
@ -733,6 +733,7 @@ rb_float_new_inline(double d)
|
||||||
#define rb_float_new(d) rb_float_new_inline(d)
|
#define rb_float_new(d) rb_float_new_inline(d)
|
||||||
|
|
||||||
/* object.c */
|
/* object.c */
|
||||||
|
void rb_obj_copy_ivar(VALUE dest, VALUE obj);
|
||||||
VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
|
VALUE rb_obj_equal(VALUE obj1, VALUE obj2);
|
||||||
VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
|
VALUE rb_class_search_ancestor(VALUE klass, VALUE super);
|
||||||
|
|
||||||
|
|
44
object.c
44
object.c
|
@ -255,6 +255,30 @@ rb_obj_singleton_class(VALUE obj)
|
||||||
return rb_singleton_class(obj);
|
return rb_singleton_class(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_obj_copy_ivar(VALUE dest, VALUE obj)
|
||||||
|
{
|
||||||
|
if (!(RBASIC(dest)->flags & ROBJECT_EMBED) && ROBJECT_IVPTR(dest)) {
|
||||||
|
xfree(ROBJECT_IVPTR(dest));
|
||||||
|
ROBJECT(dest)->as.heap.ivptr = 0;
|
||||||
|
ROBJECT(dest)->as.heap.numiv = 0;
|
||||||
|
ROBJECT(dest)->as.heap.iv_index_tbl = 0;
|
||||||
|
}
|
||||||
|
if (RBASIC(obj)->flags & ROBJECT_EMBED) {
|
||||||
|
MEMCPY(ROBJECT(dest)->as.ary, ROBJECT(obj)->as.ary, VALUE, ROBJECT_EMBED_LEN_MAX);
|
||||||
|
RBASIC(dest)->flags |= ROBJECT_EMBED;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
long len = ROBJECT(obj)->as.heap.numiv;
|
||||||
|
VALUE *ptr = ALLOC_N(VALUE, len);
|
||||||
|
MEMCPY(ptr, ROBJECT(obj)->as.heap.ivptr, VALUE, len);
|
||||||
|
ROBJECT(dest)->as.heap.ivptr = ptr;
|
||||||
|
ROBJECT(dest)->as.heap.numiv = len;
|
||||||
|
ROBJECT(dest)->as.heap.iv_index_tbl = ROBJECT(obj)->as.heap.iv_index_tbl;
|
||||||
|
RBASIC(dest)->flags &= ~ROBJECT_EMBED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_copy(VALUE dest, VALUE obj)
|
init_copy(VALUE dest, VALUE obj)
|
||||||
{
|
{
|
||||||
|
@ -266,25 +290,7 @@ init_copy(VALUE dest, VALUE obj)
|
||||||
rb_copy_generic_ivar(dest, obj);
|
rb_copy_generic_ivar(dest, obj);
|
||||||
rb_gc_copy_finalizer(dest, obj);
|
rb_gc_copy_finalizer(dest, obj);
|
||||||
if (RB_TYPE_P(obj, T_OBJECT)) {
|
if (RB_TYPE_P(obj, T_OBJECT)) {
|
||||||
if (!(RBASIC(dest)->flags & ROBJECT_EMBED) && ROBJECT_IVPTR(dest)) {
|
rb_obj_copy_ivar(dest, obj);
|
||||||
xfree(ROBJECT_IVPTR(dest));
|
|
||||||
ROBJECT(dest)->as.heap.ivptr = 0;
|
|
||||||
ROBJECT(dest)->as.heap.numiv = 0;
|
|
||||||
ROBJECT(dest)->as.heap.iv_index_tbl = 0;
|
|
||||||
}
|
|
||||||
if (RBASIC(obj)->flags & ROBJECT_EMBED) {
|
|
||||||
MEMCPY(ROBJECT(dest)->as.ary, ROBJECT(obj)->as.ary, VALUE, ROBJECT_EMBED_LEN_MAX);
|
|
||||||
RBASIC(dest)->flags |= ROBJECT_EMBED;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
long len = ROBJECT(obj)->as.heap.numiv;
|
|
||||||
VALUE *ptr = ALLOC_N(VALUE, len);
|
|
||||||
MEMCPY(ptr, ROBJECT(obj)->as.heap.ivptr, VALUE, len);
|
|
||||||
ROBJECT(dest)->as.heap.ivptr = ptr;
|
|
||||||
ROBJECT(dest)->as.heap.numiv = len;
|
|
||||||
ROBJECT(dest)->as.heap.iv_index_tbl = ROBJECT(obj)->as.heap.iv_index_tbl;
|
|
||||||
RBASIC(dest)->flags &= ~ROBJECT_EMBED;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue