Commit 0473850e authored by Johannes Henkel's avatar Johannes Henkel Committed by Commit Bot

Add bool InspectorAgentState::*Map::IsEmpty().

Will use this in the InspectorDOMDebuggerAgent and elsewhere,
since Keys() returns vector<WTF::String> and it's a bit
inefficient / ugly to call .empty() on that.

Change-Id: I99f9cb6024077bbc60ada38e46240ac602bf8669
Reviewed-on: https://chromium-review.googlesource.com/1154038Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Johannes Henkel <johannes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578885}
parent 70aaae33
......@@ -174,6 +174,9 @@ class CORE_EXPORT InspectorAgentState {
return keys;
}
// O(1) shortcut for Keys().empty().
bool IsEmpty() const { return map_.IsEmpty(); }
// Returns the value for a given |key|, or the default value if
// the key wasn't set.
ConstRefType Get(const WTF::String& key) const {
......
......@@ -145,9 +145,13 @@ TEST(InspectorSessionStateTest, MapFields) {
AgentWithMapFields maps_agent;
maps_agent.agent_state_.InitFrom(&session_state);
EXPECT_TRUE(maps_agent.strings_.IsEmpty());
maps_agent.strings_.Set("key1", "Hello, world.");
maps_agent.strings_.Set("key2", WTF::String::FromUTF8("I ❤ Unicode."));
EXPECT_FALSE(maps_agent.strings_.IsEmpty());
EXPECT_THAT(maps_agent.strings_.Keys(),
UnorderedElementsAre("key1", "key2"));
EXPECT_EQ("Hello, world.", maps_agent.strings_.Get("key1"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment