Have to remember to evict nodes from our LRU cache

This commit is contained in:
ridiculousfish 2012-01-25 18:51:26 -08:00
parent 26b375a0de
commit d6545588a3
2 changed files with 9 additions and 5 deletions

View file

@ -8,7 +8,7 @@ The classes responsible for autoloading functions and completions.
#include "wutil.h" #include "wutil.h"
#include <assert.h> #include <assert.h>
const size_t kLRULimit = 256; static const size_t kLRULimit = 16;
file_access_attempt_t access_file(const wcstring &path, int mode) { file_access_attempt_t access_file(const wcstring &path, int mode) {
file_access_attempt_t result = {0}; file_access_attempt_t result = {0};
@ -93,14 +93,18 @@ bool lru_cache_impl_t::add_node(lru_node_t *node) {
if (! node_set.insert(node).second) if (! node_set.insert(node).second)
return false; return false;
/* Update the count */
node_count++;
/* Add the node after the mouth */ /* Add the node after the mouth */
node->next = mouth.next; node->next = mouth.next;
node->prev = &mouth; node->prev = &mouth;
mouth.next = node; mouth.next = node;
/* Update the count */
node_count++;
/* Evict */
while (node_count > kLRULimit)
evict_last_node();
/* Success */ /* Success */
return true; return true;
} }

View file

@ -70,7 +70,7 @@ static bool function_remove_ignore_autoload(const wcstring &name);
/** Callback when an autoloaded function is removed */ /** Callback when an autoloaded function is removed */
void function_autoload_t::command_removed(const wcstring &cmd) { void function_autoload_t::command_removed(const wcstring &cmd) {
function_remove(cmd); function_remove_ignore_autoload(cmd);
} }
/* Helper macro for vomiting */ /* Helper macro for vomiting */