diff options
author | Sergio Giro <sgiro@google.com> | 2016-06-23 17:19:13 +0100 |
---|---|---|
committer | Sergio Giro <sgiro@google.com> | 2016-07-20 18:38:44 +0000 |
commit | 4c56e0a222b5267252bf088d19565585aa34f7ab (patch) | |
tree | 7c53a55c38cb39723db0573af257a7e4fbd8c5b1 /libutils/tests/LruCache_test.cpp | |
parent | a17427cb1e9caaeb4dde7184b05dfa4b3b1f7172 (diff) |
LruCache: avoid copying keys in lookup
Create objects of type KeyedEntry for lookups that only have
a key reference
Bug: 27567036
Change-Id: I5e609a3db63d3b9277ff1547a3cca37dce70251c
Diffstat (limited to 'libutils/tests/LruCache_test.cpp')
-rw-r--r-- | libutils/tests/LruCache_test.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libutils/tests/LruCache_test.cpp b/libutils/tests/LruCache_test.cpp index dd95c576d..de440fd7e 100644 --- a/libutils/tests/LruCache_test.cpp +++ b/libutils/tests/LruCache_test.cpp @@ -80,6 +80,14 @@ struct KeyWithPointer { } }; +struct KeyFailsOnCopy : public ComplexKey { + public: + KeyFailsOnCopy(const KeyFailsOnCopy& key) : ComplexKey(key) { + ADD_FAILURE(); + } + KeyFailsOnCopy(int key) : ComplexKey(key) { } +}; + } // namespace @@ -95,6 +103,10 @@ template<> inline android::hash_t hash_type(const KeyWithPointer& value) { return hash_type(*value.ptr); } +template<> inline android::hash_t hash_type(const KeyFailsOnCopy& value) { + return hash_type<ComplexKey>(value); +} + class EntryRemovedCallback : public OnEntryRemoved<SimpleKey, StringValue> { public: EntryRemovedCallback() : callbackCount(0), lastKey(-1), lastValue(NULL) { } @@ -437,4 +449,10 @@ TEST_F(LruCacheTest, RemoveNonMember) { EXPECT_EQ(std::unordered_set<int>({ 4, 5, 6 }), returnedValues); } +TEST_F(LruCacheTest, DontCopyKeyInGet) { + LruCache<KeyFailsOnCopy, KeyFailsOnCopy> cache(1); + // Check that get doesn't copy the key + cache.get(KeyFailsOnCopy(0)); +} + } |