This commit is contained in:
Jacob Dufault 2017-12-05 08:24:37 -08:00
parent 905a4ab2b1
commit dbeb4eb511
2 changed files with 12 additions and 11 deletions

View File

@ -18,7 +18,7 @@ std::string GetCachedBaseFileName(Config* config,
size_t len = config->projectRoot.size();
if (StartsWith(source_file, config->projectRoot)) {
cache_file = EscapeFileName(config->projectRoot) + '/' +
EscapeFileName(source_file.substr(len));
EscapeFileName(source_file.substr(len));
} else
cache_file = EscapeFileName(source_file);
@ -32,8 +32,8 @@ std::unique_ptr<IndexFile> LoadCachedIndex(Config* config,
if (!config->enableCacheRead)
return nullptr;
optional<std::string> file_content = ReadContent(
GetCachedBaseFileName(config, filename) + ".json");
optional<std::string> file_content =
ReadContent(GetCachedBaseFileName(config, filename) + ".json");
if (!file_content)
return nullptr;
@ -52,8 +52,7 @@ void WriteToCache(Config* config, IndexFile& file) {
if (!config->enableCacheWrite)
return;
std::string cache_basename =
GetCachedBaseFileName(config, file.path);
std::string cache_basename = GetCachedBaseFileName(config, file.path);
if (file.file_contents_.empty()) {
LOG_S(ERROR) << "No cached file contents; performing potentially stale "

View File

@ -9,7 +9,8 @@ template <typename TKey, typename TValue>
struct LruCache {
explicit LruCache(int max_entries);
// Fetches an entry for |key|. If it does not exist, |allocator| will be invoked to create one.
// Fetches an entry for |key|. If it does not exist, |allocator| will be
// invoked to create one.
template <typename TAllocator>
std::shared_ptr<TValue> Get(const TKey& key, TAllocator allocator);
// Fetches the entry for |filename| and updates it's usage so it is less
@ -47,7 +48,8 @@ LruCache<TKey, TValue>::LruCache(int max_entries) : max_entries_(max_entries) {
template <typename TKey, typename TValue>
template <typename TAllocator>
std::shared_ptr<TValue> LruCache<TKey, TValue>::Get(const TKey& key, TAllocator allocator) {
std::shared_ptr<TValue> LruCache<TKey, TValue>::Get(const TKey& key,
TAllocator allocator) {
std::shared_ptr<TValue> result = TryGet(key);
if (!result)
Insert(key, result = allocator());
@ -82,7 +84,8 @@ std::shared_ptr<TValue> LruCache<TKey, TValue>::TryTake(const TKey& key) {
}
template <typename TKey, typename TValue>
void LruCache<TKey, TValue>::Insert(const TKey& key, const std::shared_ptr<TValue>& value) {
void LruCache<TKey, TValue>::Insert(const TKey& key,
const std::shared_ptr<TValue>& value) {
if (entries_.size() >= max_entries_) {
// Find entry with the lowest score.
size_t lowest_idx = 0;
@ -113,9 +116,8 @@ void LruCache<TKey, TValue>::IncrementScore() {
// Overflow.
if (next_score_ == 0) {
std::sort(entries_.begin(), entries_.end(), [](const Entry& a, const Entry& b) {
return a.score < b.score;
});
std::sort(entries_.begin(), entries_.end(),
[](const Entry& a, const Entry& b) { return a.score < b.score; });
for (Entry& entry : entries_)
entry.score = next_score_++;
}