Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Side by Side Diff: net/disk_cache/memory/mem_rankings.cc

Issue 1715833002: Reland: Refactor and shorten in-memory cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo in comment Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/disk_cache/memory/mem_rankings.h"
6
7 #include "base/logging.h"
8 #include "net/disk_cache/memory/mem_entry_impl.h"
9
10 namespace disk_cache {
11
12 MemRankings::~MemRankings() {
13 DCHECK(!head_ && !tail_);
14 }
15
16 void MemRankings::Insert(MemEntryImpl* node) {
17 if (head_)
18 head_->set_prev(node);
19
20 if (!tail_)
21 tail_ = node;
22
23 node->set_prev(NULL);
24 node->set_next(head_);
25 head_ = node;
26 }
27
28 void MemRankings::Remove(MemEntryImpl* node) {
29 MemEntryImpl* prev = node->prev();
30 MemEntryImpl* next = node->next();
31
32 if (head_ == node)
33 head_ = next;
34
35 if (tail_ == node)
36 tail_ = prev;
37
38 if (prev)
39 prev->set_next(next);
40
41 if (next)
42 next->set_prev(prev);
43
44 node->set_next(NULL);
45 node->set_prev(NULL);
46 }
47
48 void MemRankings::UpdateRank(MemEntryImpl* node) {
49 Remove(node);
50 Insert(node);
51 }
52
53 MemEntryImpl* MemRankings::GetNext(MemEntryImpl* node) {
54 if (!node)
55 return head_;
56
57 return node->next();
58 }
59
60 MemEntryImpl* MemRankings::GetPrev(MemEntryImpl* node) {
61 if (!node)
62 return tail_;
63
64 return node->prev();
65 }
66
67 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698