diff --git a/autoload.cpp b/autoload.cpp index 639eeca3d..0bae1a265 100644 --- a/autoload.cpp +++ b/autoload.cpp @@ -8,7 +8,7 @@ The classes responsible for autoloading functions and completions. #include "wutil.h" #include -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 result = {0}; @@ -93,14 +93,18 @@ bool lru_cache_impl_t::add_node(lru_node_t *node) { if (! node_set.insert(node).second) return false; - /* Update the count */ - node_count++; - /* Add the node after the mouth */ node->next = mouth.next; node->prev = &mouth; mouth.next = node; + /* Update the count */ + node_count++; + + /* Evict */ + while (node_count > kLRULimit) + evict_last_node(); + /* Success */ return true; } diff --git a/function.cpp b/function.cpp index 474640fbf..ee9c508af 100644 --- a/function.cpp +++ b/function.cpp @@ -70,7 +70,7 @@ static bool function_remove_ignore_autoload(const wcstring &name); /** Callback when an autoloaded function is removed */ void function_autoload_t::command_removed(const wcstring &cmd) { - function_remove(cmd); + function_remove_ignore_autoload(cmd); } /* Helper macro for vomiting */