diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-08-27 13:16:40 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-08-28 11:02:30 +0200 |
commit | 8a7f05014a4a778969dc71f3ace77af9045e3df6 (patch) | |
tree | 54594290d45e8c39e0f5deabce72549bf0340b95 /container-core | |
parent | e123f699cc2d73e4f0118d283da4c2cf9011e7f9 (diff) |
Clone map with sufficient initial size
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/processing/request/CloneHelper.java | 15 | ||||
-rw-r--r-- | container-core/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java | 3 |
2 files changed, 5 insertions, 13 deletions
diff --git a/container-core/src/main/java/com/yahoo/processing/request/CloneHelper.java b/container-core/src/main/java/com/yahoo/processing/request/CloneHelper.java index 8ff54ab6728..64a356fbf2a 100644 --- a/container-core/src/main/java/com/yahoo/processing/request/CloneHelper.java +++ b/container-core/src/main/java/com/yahoo/processing/request/CloneHelper.java @@ -8,7 +8,6 @@ import com.yahoo.lang.PublicCloneable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.logging.Logger; import java.util.LinkedList; import java.util.ArrayList; @@ -35,9 +34,7 @@ public class CloneHelper { private static final Logger log = Logger.getLogger(CloneHelper.class.getName()); private static final MethodCache cloneMethodCache = new MethodCache("clone"); - /** - * Clones this object if it is clonable, and the clone is public. Returns null if not - */ + /** Clones this object if it is clonable, and the clone is public. Returns null if not. */ public final Object clone(Object object) { if (object == null) return null; if ( ! (object instanceof Cloneable)) return null; @@ -115,24 +112,22 @@ public class CloneHelper { Method cloneMethod = cloneMethodCache.get(object); if (cloneMethod == null) { log.warning("'" + object + "' of class " + object.getClass() + - " is Cloneable, but has no clone method - will use the same instance in all requests"); + " is Cloneable, but has no clone method - will use the same instance in all requests"); return null; } return cloneMethod.invoke(object); } catch (IllegalAccessException e) { log.warning("'" + object + "' of class " + object.getClass() + - " is Cloneable, but clone method cannot be accessed - will use the same instance in all requests"); + " is Cloneable, but clone method cannot be accessed - will use the same instance in all requests"); return null; } catch (InvocationTargetException e) { throw new RuntimeException("Exception cloning '" + object + "'", e); } } - /** - * Clones a map by deep cloning each value which is cloneable and shallow copying all other values. - */ + /** Clones a map by deep cloning each value which is cloneable and shallow copying all other values. */ public Map<CompoundName, Object> cloneMap(Map<CompoundName, Object> map) { - Map<CompoundName, Object> cloneMap = new HashMap<>(map.size()); + Map<CompoundName, Object> cloneMap = new HashMap<>((int)(map.size()/0.75) + 1); for (Map.Entry<CompoundName, Object> entry : map.entrySet()) { Object cloneValue = clone(entry.getValue()); if (cloneValue == null) diff --git a/container-core/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java b/container-core/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java index f149c177b47..adaac4216b9 100644 --- a/container-core/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java +++ b/container-core/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java @@ -22,9 +22,6 @@ import java.util.Map; */ public class PropertyMap extends Properties { - /** - * The properties of this - */ private Map<CompoundName, Object> properties = new HashMap<>(); public void set(CompoundName name, Object value, Map<String, String> context) { |