From 0610fc3ad2d8c9da74559af78d5a6b2d6d7fe408 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 26 Nov 2013 02:48:19 +0100 Subject: [PATCH] use the proper abstraction of ImmutableOpenMap we already use the open map / clone trick, might as well use the ImmutableOpenMap here --- .../common/collect/ImmutableOpenMap.java | 11 +++++++++++ .../index/mapper/object/ObjectMapper.java | 13 ++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java b/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java index 1221a2f0e76..d8475f0fe70 100644 --- a/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java +++ b/src/main/java/org/elasticsearch/common/collect/ImmutableOpenMap.java @@ -25,6 +25,7 @@ import com.carrotsearch.hppc.predicates.ObjectPredicate; import com.carrotsearch.hppc.procedures.ObjectObjectProcedure; import java.util.Iterator; +import java.util.Map; /** * An immutable map implementation based on open hash map. @@ -180,6 +181,16 @@ public final class ImmutableOpenMap implements Iterable(map); } + /** + * Puts all the entries in the map to the builder. + */ + public Builder putAll(Map map) { + for (Map.Entry entry : map.entrySet()) { + this.map.put(entry.getKey(), entry.getValue()); + } + return this; + } + /** * A put operation that can be used in the fluent pattern. */ diff --git a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java index 1e8f58ca2ec..b79553934e6 100644 --- a/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java +++ b/src/main/java/org/elasticsearch/index/mapper/object/ObjectMapper.java @@ -19,7 +19,6 @@ package org.elasticsearch.index.mapper.object; -import com.carrotsearch.hppc.ObjectObjectOpenHashMap; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; @@ -30,7 +29,7 @@ import org.apache.lucene.search.Filter; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.collect.HppcMaps; +import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -291,7 +290,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll { private Boolean includeInAll; - private volatile ObjectObjectOpenHashMap mappers = HppcMaps.newMap(); + private volatile ImmutableOpenMap mappers = ImmutableOpenMap.of(); private final Object mutex = new Object(); @@ -303,9 +302,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll { this.dynamic = dynamic; this.pathType = pathType; if (mappers != null) { - for (Map.Entry entry : mappers.entrySet()) { - this.mappers.put(entry.getKey(), entry.getValue()); - } + this.mappers = ImmutableOpenMap.builder(this.mappers).putAll(mappers).build(); } this.nestedTypePathAsString = "__" + fullPath; this.nestedTypePathAsBytes = new BytesRef(nestedTypePathAsString); @@ -357,9 +354,7 @@ public class ObjectMapper implements Mapper, AllFieldMapper.IncludeInAll { ((AllFieldMapper.IncludeInAll) mapper).includeInAllIfNotSet(includeInAll); } synchronized (mutex) { - ObjectObjectOpenHashMap mappers = this.mappers.clone(); - mappers.put(mapper.name(), mapper); - this.mappers = mappers; + this.mappers = ImmutableOpenMap.builder(this.mappers).fPut(mapper.name(), mapper).build(); } return this; }