From 5852a8845dbc5402a27f0a2663563c31394c7e83 Mon Sep 17 00:00:00 2001 From: Joe Gallo Date: Thu, 16 Sep 2021 17:33:07 -0400 Subject: [PATCH] Implement get and containsKey in terms of the wrapped innerMap In practice, the wrapped innerMap is either empty or a HashMap, so we can get much better performance here by delegating to it for these methods -- as opposed to using the default implementations from AbstractMap which do a linear scan through via an iterator() of the entrySet(). --- .../cluster/metadata/DiffableStringMap.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/DiffableStringMap.java b/server/src/main/java/org/elasticsearch/cluster/metadata/DiffableStringMap.java index 6edde80272454..fdc95c6db83cf 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/DiffableStringMap.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/DiffableStringMap.java @@ -47,6 +47,16 @@ public Set> entrySet() { return innerMap.entrySet(); } + @Override + public String get(Object key) { + return innerMap.get(key); + } + + @Override + public boolean containsKey(Object key) { + return innerMap.containsKey(key); + } + @Override @SuppressWarnings("unchecked") public void writeTo(StreamOutput out) throws IOException {