summaryrefslogtreecommitdiffstats
path: root/libutils/include/utils/LruCache.h
diff options
context:
space:
mode:
authorYi Kong <yikong@google.com>2018-07-16 18:11:34 -0700
committerYi Kong <yikong@google.com>2018-07-16 18:11:34 -0700
commite1731a4f2e05f1abb4a45602067708851eaf1e14 (patch)
tree339c0ce3d3de7d6f5e0fb9bdada9b6210d1d470f /libutils/include/utils/LruCache.h
parent895acebe946e34d2626716c5c4d7d7f2cc28c39d (diff)
downloadsystem_core-e1731a4f2e05f1abb4a45602067708851eaf1e14.tar.gz
system_core-e1731a4f2e05f1abb4a45602067708851eaf1e14.tar.bz2
system_core-e1731a4f2e05f1abb4a45602067708851eaf1e14.zip
[libutils] Modernize codebase by replacing NULL with nullptr
Fixes -Wzero-as-null-pointer-constant warning. Test: m Bug: 68236239 Change-Id: I5e89ec8c42151875439d2656475a8739ab9cb7dc
Diffstat (limited to 'libutils/include/utils/LruCache.h')
-rw-r--r--libutils/include/utils/LruCache.h26
1 files changed, 13 insertions, 13 deletions
diff --git a/libutils/include/utils/LruCache.h b/libutils/include/utils/LruCache.h
index 89dccd613..36775d0f2 100644
--- a/libutils/include/utils/LruCache.h
+++ b/libutils/include/utils/LruCache.h
@@ -71,7 +71,7 @@ private:
Entry* parent;
Entry* child;
- Entry(TKey _key, TValue _value) : key(_key), value(_value), parent(NULL), child(NULL) {
+ Entry(TKey _key, TValue _value) : key(_key), value(_value), parent(nullptr), child(nullptr) {
}
const TKey& getKey() const final { return key; }
};
@@ -162,9 +162,9 @@ public:
template <typename TKey, typename TValue>
LruCache<TKey, TValue>::LruCache(uint32_t maxCapacity)
: mSet(new LruCacheSet())
- , mListener(NULL)
- , mOldest(NULL)
- , mYoungest(NULL)
+ , mListener(nullptr)
+ , mOldest(nullptr)
+ , mYoungest(nullptr)
, mMaxCapacity(maxCapacity)
, mNullValue(0) {
mSet->max_load_factor(1.0);
@@ -236,7 +236,7 @@ bool LruCache<TKey, TValue>::remove(const TKey& key) {
template <typename TKey, typename TValue>
bool LruCache<TKey, TValue>::removeOldest() {
- if (mOldest != NULL) {
+ if (mOldest != nullptr) {
return remove(mOldest->key);
// TODO: should probably abort if false
}
@@ -254,12 +254,12 @@ const TValue& LruCache<TKey, TValue>::peekOldestValue() {
template <typename TKey, typename TValue>
void LruCache<TKey, TValue>::clear() {
if (mListener) {
- for (Entry* p = mOldest; p != NULL; p = p->child) {
+ for (Entry* p = mOldest; p != nullptr; p = p->child) {
(*mListener)(p->key, p->value);
}
}
- mYoungest = NULL;
- mOldest = NULL;
+ mYoungest = nullptr;
+ mOldest = nullptr;
for (auto entry : *mSet.get()) {
delete entry;
}
@@ -268,7 +268,7 @@ void LruCache<TKey, TValue>::clear() {
template <typename TKey, typename TValue>
void LruCache<TKey, TValue>::attachToCache(Entry& entry) {
- if (mYoungest == NULL) {
+ if (mYoungest == nullptr) {
mYoungest = mOldest = &entry;
} else {
entry.parent = mYoungest;
@@ -279,19 +279,19 @@ void LruCache<TKey, TValue>::attachToCache(Entry& entry) {
template <typename TKey, typename TValue>
void LruCache<TKey, TValue>::detachFromCache(Entry& entry) {
- if (entry.parent != NULL) {
+ if (entry.parent != nullptr) {
entry.parent->child = entry.child;
} else {
mOldest = entry.child;
}
- if (entry.child != NULL) {
+ if (entry.child != nullptr) {
entry.child->parent = entry.parent;
} else {
mYoungest = entry.parent;
}
- entry.parent = NULL;
- entry.child = NULL;
+ entry.parent = nullptr;
+ entry.child = nullptr;
}
}