зеркало из https://github.com/github/ruby.git
Simplify setting instance variables
Since T_OBJECT objects come to life as embedded objects, that means that ROBJECT_NUMIV will always return a _minimum_ of ROBJECT_EMBED_LEN_MAX. If ivup.index is *greater* than ROBJECT_NUMIV, then we know that the object *must not* be an embedded object. Thus we can skip the ROBJECT_EMBED_LEN_MAX check as well as initializing internals of embedded objects.
This commit is contained in:
Родитель
a8581ce673
Коммит
70680feeea
11
variable.c
11
variable.c
|
@ -1407,7 +1407,7 @@ obj_ivar_set(VALUE obj, ID id, VALUE val)
|
|||
{
|
||||
VALUE klass = rb_obj_class(obj);
|
||||
struct ivar_update ivup;
|
||||
uint32_t i, len;
|
||||
uint32_t len;
|
||||
ivup.iv_extended = 0;
|
||||
ivup.u.iv_index_tbl = iv_index_tbl_make(obj, klass);
|
||||
|
||||
|
@ -1420,14 +1420,6 @@ obj_ivar_set(VALUE obj, ID id, VALUE val)
|
|||
len = ROBJECT_NUMIV(obj);
|
||||
if (len <= ivup.index) {
|
||||
VALUE *ptr = ROBJECT_IVPTR(obj);
|
||||
if (ivup.index < ROBJECT_EMBED_LEN_MAX) {
|
||||
RBASIC(obj)->flags |= ROBJECT_EMBED;
|
||||
ptr = ROBJECT(obj)->as.ary;
|
||||
for (i = 0; i < ROBJECT_EMBED_LEN_MAX; i++) {
|
||||
ptr[i] = Qundef;
|
||||
}
|
||||
}
|
||||
else {
|
||||
VALUE *newptr;
|
||||
uint32_t newsize = iv_index_tbl_newsize(&ivup);
|
||||
|
||||
|
@ -1447,7 +1439,6 @@ obj_ivar_set(VALUE obj, ID id, VALUE val)
|
|||
ROBJECT(obj)->as.heap.numiv = newsize;
|
||||
ROBJECT(obj)->as.heap.iv_index_tbl = ivup.u.iv_index_tbl;
|
||||
}
|
||||
}
|
||||
RB_OBJ_WRITE(obj, &ROBJECT_IVPTR(obj)[ivup.index], val);
|
||||
|
||||
return val;
|
||||
|
|
Загрузка…
Ссылка в новой задаче