aboutsummaryrefslogtreecommitdiff
path: root/src/common/simple_string_dictionary_unittest.cc
diff options
context:
space:
mode:
authorRobert Sesek <rsesek@chromium.org>2017-11-07 18:24:26 -0500
committerRobert Sesek <rsesek@chromium.org>2017-11-07 23:24:48 +0000
commit8a0edac9abfec72e0a86aebd6a0a38761c7c8962 (patch)
tree999b482ec6d3db09802658ef0ac75258f23eb8e8 /src/common/simple_string_dictionary_unittest.cc
parentdump_symbols: Stop rejecting files with Android packed relocation sections. (diff)
downloadbreakpad-8a0edac9abfec72e0a86aebd6a0a38761c7c8962.tar.xz
Add index-based set functionality to NonAllocatingMap.
This enables repeatedly setting a value based on index, which avoids a linear scan of the entry table after the first SetKeyValue(). Bug: chromium:598854 Change-Id: I9964670a09dcd8ff76180d031a373f20990bf4d8 Reviewed-on: https://chromium-review.googlesource.com/757579 Reviewed-by: Mark Mentovai <mark@chromium.org>
Diffstat (limited to 'src/common/simple_string_dictionary_unittest.cc')
-rw-r--r--src/common/simple_string_dictionary_unittest.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/common/simple_string_dictionary_unittest.cc b/src/common/simple_string_dictionary_unittest.cc
index 34f4b9ef..e7b8fd76 100644
--- a/src/common/simple_string_dictionary_unittest.cc
+++ b/src/common/simple_string_dictionary_unittest.cc
@@ -288,6 +288,37 @@ TEST(NonAllocatingMapTest, OutOfSpace) {
EXPECT_FALSE(map.GetValueForKey("c"));
}
+TEST(NonAllocatingMapTest, ByIndex) {
+ NonAllocatingMap<10, 10, 3> map;
+
+ size_t index1 = map.SetKeyValue("test", "one");
+ EXPECT_TRUE(index1 >= 0 && index1 <= map.num_entries);
+
+ size_t index2 = map.SetKeyValue("moo", "foo");
+ EXPECT_TRUE(index2 >= 0 && index2 <= map.num_entries);
+ EXPECT_NE(index1, index2);
+
+ size_t index3 = map.SetKeyValue("blob", "kebab");
+ EXPECT_TRUE(index3 >= 0 && index3 <= map.num_entries);
+ EXPECT_NE(index2, index3);
+
+ size_t index4 = map.SetKeyValue("nogo", "full");
+ EXPECT_TRUE(index4 == map.num_entries);
+
+ EXPECT_STREQ("one", map.GetValueForKey("test"));
+ EXPECT_STREQ("foo", map.GetValueForKey("moo"));
+ EXPECT_STREQ("kebab", map.GetValueForKey("blob"));
+
+ map.SetValueAtIndex(index2, "booo");
+ EXPECT_STREQ("booo", map.GetValueForKey("moo"));
+
+ EXPECT_TRUE(map.RemoveAtIndex(index1));
+ EXPECT_FALSE(map.GetValueForKey("test"));
+
+ EXPECT_FALSE(map.RemoveAtIndex(map.num_entries));
+ EXPECT_FALSE(map.RemoveAtIndex(9999));
+}
+
#ifndef NDEBUG
TEST(NonAllocatingMapTest, NullKey) {