blob: d5f4a6536a792f48df0998d6e7a9a603b3577aa9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/disk_cache/mem_rankings.h"
#include "base/logging.h"
#include "net/disk_cache/mem_entry_impl.h"
namespace disk_cache {
MemRankings::~MemRankings() {
DCHECK(!head_ && !tail_);
}
void MemRankings::Insert(MemEntryImpl* node) {
if (head_)
head_->set_prev(node);
if (!tail_)
tail_ = node;
node->set_prev(NULL);
node->set_next(head_);
head_ = node;
}
void MemRankings::Remove(MemEntryImpl* node) {
MemEntryImpl* prev = node->prev();
MemEntryImpl* next = node->next();
if (head_ == node)
head_ = next;
if (tail_ == node)
tail_ = prev;
if (prev)
prev->set_next(next);
if (next)
next->set_prev(prev);
node->set_next(NULL);
node->set_prev(NULL);
}
void MemRankings::UpdateRank(MemEntryImpl* node) {
Remove(node);
Insert(node);
}
MemEntryImpl* MemRankings::GetNext(MemEntryImpl* node) {
if (!node)
return head_;
return node->next();
}
MemEntryImpl* MemRankings::GetPrev(MemEntryImpl* node) {
if (!node)
return tail_;
return node->prev();
}
} // namespace disk_cache
|