From ffe675fea6aabfe3428ebec8ff17863aeec98e5e Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 9 Sep 2021 23:40:23 -0700 Subject: oop: remove repeated code in slot lookup. * struct.c (lookup_slot): Do not repeat the slot lookup logic for the case when the symbol's slot_cache must be boostrapped, which only happens exactly once in the life of a symbol. Just allocate the cache if necessary and fall through to the have-cache case. --- struct.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/struct.c b/struct.c index 004c66d1..992f51bb 100644 --- a/struct.c +++ b/struct.c @@ -1101,7 +1101,14 @@ static loc lookup_slot(val inst, struct struct_inst *si, val sym) slot_cache_set_t *slot_cache = sym->s.slot_cache; cnum id = si->id; - if (slot_cache != 0) { + if (slot_cache == 0) { + slot_cache = coerce(slot_cache_set_t *, + chk_calloc(SLOT_CACHE_SIZE, + sizeof (slot_cache_set_t))); + sym->s.slot_cache = slot_cache; + } + + { slot_cache_set_t *set = &slot_cache[id % SLOT_CACHE_SIZE]; cnum slot = cache_set_lookup(*set, id); @@ -1130,29 +1137,6 @@ static loc lookup_slot(val inst, struct struct_inst *si, val sym) return mkloc(si->slot[slnum], inst); } } - } else { - slot_cache = coerce(slot_cache_set_t *, - chk_calloc(SLOT_CACHE_SIZE, - sizeof (slot_cache_set_t))); - slot_cache_set_t *set = &slot_cache[id % SLOT_CACHE_SIZE]; - val key = cons(sym, num_fast(id)); - val sl = gethash(slot_hash, key); - cnum slnum = coerce(cnum, sl) >> TAG_SHIFT; - - sym->s.slot_cache = slot_cache; - - rcyc_cons(key); - - if (sl) { - cache_set_insert(*set, id, slnum); - if (slnum >= STATIC_SLOT_BASE) { - struct struct_type *st = si->type; - struct stslot *stsl = &st->stslot[slnum - STATIC_SLOT_BASE]; - return stslot_loc(stsl); - } - check_init_lazy_struct(inst, si); - return mkloc(si->slot[slnum], inst); - } } return nulloc; -- cgit v1.2.3