summaryrefslogtreecommitdiffstats
path: root/processing
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2017-02-09 20:41:39 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2017-02-09 20:41:39 +0200
commit44d6271ce3a211bcbb041e57d5a473ef3e743d82 (patch)
tree22b89a869b4c5b6ce159f5c41487788bfd1d7175 /processing
parent86cbd8917a11e8e920adbb1dfabc83f4f03fbfa0 (diff)
Optimize objectclone with a general method cache and special handling of ArrayList
Diffstat (limited to 'processing')
-rw-r--r--processing/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java19
1 files changed, 11 insertions, 8 deletions
diff --git a/processing/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java b/processing/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java
index 9a1441196f3..9c85c60da69 100644
--- a/processing/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java
+++ b/processing/src/main/java/com/yahoo/processing/request/properties/PropertyMap.java
@@ -1,16 +1,14 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.processing.request.properties;
+import com.yahoo.collections.MethodCache;
import com.yahoo.component.provider.FreezableClass;
import com.yahoo.processing.request.CompoundName;
import com.yahoo.processing.request.Properties;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.Map;
+import java.util.*;
import java.util.logging.Logger;
/**
@@ -29,6 +27,7 @@ import java.util.logging.Logger;
public class PropertyMap extends Properties {
private static Logger log = Logger.getLogger(PropertyMap.class.getName());
+ private static final MethodCache cloneMethodCache = new MethodCache("clone");
/**
* The properties of this
@@ -115,13 +114,17 @@ public class PropertyMap extends Properties {
else if (object instanceof LinkedList) { // TODO: Why? Somebody's infatuation with LinkedList knows no limits
return ((LinkedList) object).clone();
}
+ else if (object instanceof ArrayList) { // TODO: Why? Likewise
+ return ((ArrayList) object).clone();
+ }
try {
- Method cloneMethod = object.getClass().getMethod("clone");
+ Method cloneMethod = cloneMethodCache.get(object);
+ if (cloneMethod == null) {
+ log.warning("'" + object + "' is Cloneable, but has no clone method - will use the same instance in all requests");
+ return null;
+ }
return cloneMethod.invoke(object);
- } catch (NoSuchMethodException e) {
- log.warning("'" + object + "' is Cloneable, but has no clone method - will use the same instance in all requests");
- return null;
} catch (IllegalAccessException e) {
log.warning("'" + object + "' is Cloneable, but clone method cannot be accessed - will use the same instance in all requests");
return null;