Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6ce22489 authored by Jack He's avatar Jack He Committed by Automerger Merge Worker
Browse files

LruCache: Allow Get to take nullptr am: 4ab4065b

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1342899

Change-Id: If37fbca0d43fb84500a6a7303a841069ce83fb40
parents 6cfa9c90 4ab4065b
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -83,7 +83,9 @@ class LruCache {
    node_list_.erase(list_iterator);
    node_list_.push_front(node);
    map_iterator->second = node_list_.begin();
    if (value != nullptr) {
      *value = node.second;
    }
    return true;
  }

+14 −0
Original line number Diff line number Diff line
@@ -139,6 +139,20 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest2) {
  EXPECT_EQ(*value, 50);
}

TEST(BluetoothLruCacheTest, LruCacheGetTest) {
  LruCache<int, int> cache(10, "testing", [](int a, int b) {});
  cache.Put(1, 10);
  cache.Put(2, 20);
  int value = 0;
  EXPECT_TRUE(cache.Get(1, &value));
  EXPECT_EQ(value, 10);
  EXPECT_TRUE(cache.Get(1, nullptr));
  EXPECT_TRUE(cache.Get(2, nullptr));
  EXPECT_FALSE(cache.Get(3, nullptr));
  EXPECT_FALSE(cache.Get(3, &value));
  EXPECT_EQ(value, 10);
}

TEST(BluetoothLruCacheTest, LruCacheRemoveTest) {
  LruCache<int, int> cache(10, "testing", [](int a, int b) {});
  for (int key = 0; key <= 30; key++) {