diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-09-09 23:40:23 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-09-09 23:40:23 -0700 |
commit | ffe675fea6aabfe3428ebec8ff17863aeec98e5e (patch) | |
tree | 44e246982a95aeea768213a0e949be530773d8c6 /struct.c | |
parent | 963e1ea9685f0c28a70635f2ef6450f8a4d1c7c6 (diff) | |
download | txr-ffe675fea6aabfe3428ebec8ff17863aeec98e5e.tar.gz txr-ffe675fea6aabfe3428ebec8ff17863aeec98e5e.tar.bz2 txr-ffe675fea6aabfe3428ebec8ff17863aeec98e5e.zip |
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.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 32 |
1 files changed, 8 insertions, 24 deletions
@@ -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; |