style fixups

This commit is contained in:
Kurtis Rader 2017-01-29 17:56:03 -08:00
parent e52a04e341
commit 973097f025
4 changed files with 18 additions and 26 deletions

View file

@ -27,10 +27,7 @@ file_access_attempt_t access_file(const wcstring &path, int mode);
struct autoload_function_t { struct autoload_function_t {
explicit autoload_function_t(bool placeholder) explicit autoload_function_t(bool placeholder)
: access(), : access(), is_loaded(false), is_placeholder(placeholder), is_internalized(false) {}
is_loaded(false),
is_placeholder(placeholder),
is_internalized(false) {}
/// The last access attempt recorded /// The last access attempt recorded
file_access_attempt_t access; file_access_attempt_t access;
@ -82,7 +79,6 @@ class autoload_t : public lru_cache_t<autoload_t, autoload_function_t> {
virtual void command_removed(const wcstring &cmd) { UNUSED(cmd); } virtual void command_removed(const wcstring &cmd) { UNUSED(cmd); }
public: public:
// CRTP override // CRTP override
void entry_was_evicted(wcstring key, autoload_function_t node); void entry_was_evicted(wcstring key, autoload_function_t node);

View file

@ -1128,9 +1128,7 @@ class test_lru_t : public lru_cache_t<test_lru_t, int> {
std::vector<std::pair<wcstring, int>> evicted; std::vector<std::pair<wcstring, int>> evicted;
void entry_was_evicted(wcstring key, int val) { void entry_was_evicted(wcstring key, int val) { evicted.push_back({key, val}); }
evicted.push_back({key, val});
}
}; };
static void test_lru(void) { static void test_lru(void) {

View file

@ -155,8 +155,8 @@ class history_lru_item_t {
class history_lru_cache_t : public lru_cache_t<history_lru_cache_t, history_lru_item_t> { class history_lru_cache_t : public lru_cache_t<history_lru_cache_t, history_lru_item_t> {
typedef lru_cache_t<history_lru_cache_t, history_lru_item_t> super; typedef lru_cache_t<history_lru_cache_t, history_lru_item_t> super;
public:
public:
using super::super; using super::super;
/// Function to add a history item. /// Function to add a history item.

View file

@ -8,19 +8,19 @@
#include "common.h" #include "common.h"
// Least-recently-used cache class // Least-recently-used cache class.
//
// This a map from wcstring to CONTENTS, that will evict entries when the count exceeds the maximum. // This a map from wcstring to CONTENTS, that will evict entries when the count exceeds the maximum.
// It uses CRTP to inform clients when entries are evicted. This uses the classic LRU cache structure: // It uses CRTP to inform clients when entries are evicted. This uses the classic LRU cache
// a dictionary mapping keys to nodes, where the nodes also form a linked list. Our linked list is // structure: a dictionary mapping keys to nodes, where the nodes also form a linked list. Our
// circular and has a sentinel node (the "mouth" - picture a snake swallowing its tail). This simplifies // linked list is circular and has a sentinel node (the "mouth" - picture a snake swallowing its
// the logic: no pointer is ever NULL! It also works well with C++'s iterator since the sentinel node // tail). This simplifies the logic: no pointer is ever NULL! It also works well with C++'s iterator
// is a natural value for end(). Our nodes also have the unusual property of having a "back pointer": // since the sentinel node is a natural value for end(). Our nodes also have the unusual property of
// they store an iterator to the entry in the map containing the node. This allows us, given a node, to // having a "back pointer": they store an iterator to the entry in the map containing the node. This
// immediately locate the node and its key in the dictionary. This allows us to avoid duplicating the key // allows us, given a node, to immediately locate the node and its key in the dictionary. This
// in the node. // allows us to avoid duplicating the key in the node.
template <class DERIVED, class CONTENTS> template <class DERIVED, class CONTENTS>
class lru_cache_t { class lru_cache_t {
struct lru_node_t; struct lru_node_t;
typedef typename std::map<wcstring, lru_node_t>::iterator node_iter_t; typedef typename std::map<wcstring, lru_node_t>::iterator node_iter_t;
@ -44,12 +44,9 @@ class lru_cache_t {
// The value from the client // The value from the client
CONTENTS value; CONTENTS value;
explicit lru_node_t(CONTENTS v) : explicit lru_node_t(CONTENTS v) : value(std::move(v)) {}
value(std::move(v))
{}
}; };
// Max node count. This may be (transiently) exceeded by add_node_without_eviction, which is // Max node count. This may be (transiently) exceeded by add_node_without_eviction, which is
// used from background threads. // used from background threads.
const size_t max_node_count; const size_t max_node_count;
@ -190,6 +187,7 @@ class lru_cache_t {
// Iterator for walking nodes, from least recently used to most. // Iterator for walking nodes, from least recently used to most.
class iterator { class iterator {
lru_link_t *node; lru_link_t *node;
public: public:
typedef std::pair<const wcstring &, const CONTENTS &> value_type; typedef std::pair<const wcstring &, const CONTENTS &> value_type;