1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

Cheaper fluid-ref cache

* libguile/cache-internal.h (struct scm_cache_entry): Add needs_flush
  member.
  (scm_cache_evict_1): Clear needs_flush on newly evicted entry.
  (scm_cache_insert): Propagate needs_flush to new entry.
* libguile/fluids.c (restore_dynamic_state): Mark all restored entries
  as needing a flush.
  (save_dynamic_state): Only cons on "needs_flush" entries to the
  resulting dynamic state.  The result is the same as before but
  avoiding the refq on the weak table.
  (fluid_set_x): Propagate needs_flush down to the cache.
  (fluid_ref): When adding entry to cache, use needs_flush==0.
  (scm_fluid_set_x, scm_fluid_unset_x, scm_swap_fluid, swap_fluid): Use
  needs_flush==1.
This commit is contained in:
Andy Wingo 2017-02-16 10:38:15 +01:00
parent 4706d69824
commit cd3ff33a31
2 changed files with 22 additions and 14 deletions

View file

@ -37,6 +37,7 @@ struct scm_cache_entry
{
scm_t_bits key;
scm_t_bits value;
int needs_flush;
};
#define SCM_CACHE_SIZE 8
@ -73,6 +74,7 @@ scm_cache_evict_1 (struct scm_cache *cache, struct scm_cache_entry *evicted)
sizeof (cache->entries[0]) * idx);
cache->entries[0].key = 0;
cache->entries[0].value = 0;
cache->entries[0].needs_flush = 0;
}
static inline struct scm_cache_entry*
@ -89,7 +91,7 @@ scm_cache_lookup (struct scm_cache *cache, SCM k)
static inline void
scm_cache_insert (struct scm_cache *cache, SCM k, SCM v,
struct scm_cache_entry *evicted)
struct scm_cache_entry *evicted, int needs_flush)
{
struct scm_cache_entry *entry;
@ -99,6 +101,7 @@ scm_cache_insert (struct scm_cache *cache, SCM k, SCM v,
if (entry->key == SCM_UNPACK (k))
{
entry->value = SCM_UNPACK (v);
entry->needs_flush = needs_flush;
return;
}
memmove (cache->entries,
@ -106,6 +109,7 @@ scm_cache_insert (struct scm_cache *cache, SCM k, SCM v,
(entry - cache->entries) * sizeof (*entry));
entry->key = SCM_UNPACK (k);
entry->value = SCM_UNPACK (v);
entry->needs_flush = needs_flush;
}
#endif /* SCM_CACHE_INTERNAL_H */