mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-05 00:01:15 -03:00
Implemented LRU cache for autoloading.
This commit is contained in:
14
autoload.h
14
autoload.h
@@ -84,13 +84,10 @@ class lru_node_t {
|
||||
/** Constructor */
|
||||
lru_node_t(const wcstring &keyVar) : prev(NULL), next(NULL), key(keyVar) { }
|
||||
bool operator<(const lru_node_t &other) const { return key < other.key; }
|
||||
|
||||
/** Callback when the node is evicted from an LRU cache */
|
||||
virtual void evicted(void) { }
|
||||
};
|
||||
|
||||
class lru_cache_impl_t {
|
||||
private:
|
||||
private:
|
||||
void promote_node(lru_node_t *);
|
||||
void evict_node(lru_node_t *node);
|
||||
void evict_last_node(void);
|
||||
@@ -105,7 +102,11 @@ class lru_cache_impl_t {
|
||||
/** Head of the linked list */
|
||||
lru_node_t mouth;
|
||||
|
||||
public:
|
||||
protected:
|
||||
/** Overridable callback for when a node is evicted */
|
||||
virtual void node_was_evicted(lru_node_t *node);
|
||||
|
||||
public:
|
||||
/** Constructor */
|
||||
lru_cache_impl_t();
|
||||
|
||||
@@ -128,6 +129,9 @@ class lru_cache_t : public lru_cache_impl_t {
|
||||
public:
|
||||
node_type_t *get_node(const wcstring &key) { return static_cast<node_type_t>(lru_cache_impl_t::get_node(key)); }
|
||||
bool add_node(node_type_t *node) { return lru_cache_impl_t::add_node(node); }
|
||||
protected:
|
||||
virtual void node_was_evicted(lru_node_t *node) { this->node_was_evicted(static_cast<node_type_t *>(node)); }
|
||||
virtual void node_was_evicted(node_type_t *node) { }
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user