Object* PackedObject::packed_ivar_delete(STATE, Symbol* sym, bool* removed) { LookupTable* tbl = this->reference_class()->packed_ivar_info(); bool found = false; Fixnum* which = try_as<Fixnum>(tbl->fetch(state, sym, &found)); if(!found) { return del_table_ivar(state, sym, removed); } if(removed) *removed = true; Object* val = body_as_array()[which->to_native()]; body_as_array()[which->to_native()] = Qundef; return val; }
Object* PackedObject::set_packed_ivar(STATE, Symbol* sym, Object* val) { LookupTable* tbl = this->reference_class()->packed_ivar_info(); bool found = false; Fixnum* which = try_as<Fixnum>(tbl->fetch(state, sym, &found)); if(!found) { return set_table_ivar(state, sym, val); } body_as_array()[which->to_native()] = val; if(val->reference_p()) write_barrier(state, val); return val; }
Object* PackedObject::packed_ivar_defined(STATE, Symbol* sym) { LookupTable* tbl = this->reference_class()->packed_ivar_info(); bool found = false; Fixnum* which = try_as<Fixnum>(tbl->fetch(state, sym, &found)); if(!found) { return table_ivar_defined(state, sym); } Object* obj = body_as_array()[which->to_native()]; if(obj == Qundef) return Qfalse; return Qtrue; }
Object* PackedObject::get_packed_ivar(STATE, Symbol* sym) { LookupTable* tbl = this->reference_class()->packed_ivar_info(); assert(tbl && !tbl->nil_p()); Fixnum* which = try_as<Fixnum>(tbl->fetch(state, sym)); if(!which) { return get_table_ivar(state, sym); } Object* obj = body_as_array()[which->to_native()]; if(obj == Qundef) return Qnil; return obj; }
void PackedObject::add_packed_ivars(STATE, Array* ary) { LookupTable* tbl = this->reference_class()->packed_ivar_info(); LookupTable::iterator i(tbl); while(i.advance()) { Object* key = i.key(); if(Fixnum* which = try_as<Fixnum>(tbl->fetch(state, key))) { if(body_as_array()[which->to_native()] != Qundef) { ary->append(state, key); } } } }
void PackedObject::add_packed_ivars(STATE, Array* ary) { LookupTable* tbl = this->reference_class()->packed_ivar_info(); assert(tbl && !tbl->nil_p()); Array* keys = tbl->all_keys(state); for(size_t i = 0; i < keys->size(); i++) { Object* key = keys->get(state, i); if(Fixnum* which = try_as<Fixnum>(tbl->fetch(state, key))) { if(body_as_array()[which->to_native()] != Qundef) { ary->append(state, key); } } } }