reduced complexity by having a single GLOBAL_METHOD_CACHE for both Traversal 
and TraversalSource methods. Cleaner code with less instanceof stuff.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/1fc52cb2
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/1fc52cb2
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/1fc52cb2

Branch: refs/heads/TINKERPOP-1404
Commit: 1fc52cb2d208fb0949e66f2e1cf2c1307495a537
Parents: ed8feea
Author: Marko A. Rodriguez <okramma...@gmail.com>
Authored: Tue Sep 13 13:34:47 2016 -0600
Committer: Marko A. Rodriguez <okramma...@gmail.com>
Committed: Tue Sep 13 13:34:47 2016 -0600

----------------------------------------------------------------------
 .../tinkerpop/gremlin/jsr223/JavaTranslator.java     | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1fc52cb2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java
index a4f97a1..ed2def2 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java
@@ -42,8 +42,8 @@ public final class JavaTranslator<S extends TraversalSource, 
T extends Traversal
 
     private final S traversalSource;
     private final Class anonymousTraversal;
-    private static final Map<Class<? extends TraversalSource>, Map<String, 
List<Method>>> TRAVERSAL_SOURCE_METHOD_CACHE = new ConcurrentHashMap<>();
-    private static final Map<Class<? extends Traversal>, Map<String, 
List<Method>>> TRAVERSAL_METHOD_CACHE = new ConcurrentHashMap<>();
+    private static final Map<Class<?>, Map<String, List<Method>>> 
GLOBAL_METHOD_CACHE = new ConcurrentHashMap<>();
+
 
     private JavaTranslator(final S traversalSource) {
         this.traversalSource = traversalSource;
@@ -105,9 +105,7 @@ public final class JavaTranslator<S extends 
TraversalSource, T extends Traversal
         //////////////////////////
         //////////////////////////
         // populate method cache for fast access to methods in subsequent calls
-        final Map<String, List<Method>> methodCache = delegate instanceof 
TraversalSource ?
-                
TRAVERSAL_SOURCE_METHOD_CACHE.getOrDefault(delegate.getClass(), new 
HashMap<>()) :
-                TRAVERSAL_METHOD_CACHE.getOrDefault(delegate.getClass(), new 
HashMap<>());
+        final Map<String, List<Method>> methodCache = 
GLOBAL_METHOD_CACHE.getOrDefault(delegate.getClass(), new HashMap<>());
         if (methodCache.isEmpty()) {
             for (final Method method : delegate.getClass().getMethods()) {
                 if (!(method.getName().equals("addV") && 
method.getParameterCount() == 1 && 
method.getParameters()[0].getType().equals(Object[].class))) { // hack cause 
its hard to tell Object[] vs. String :|
@@ -119,10 +117,7 @@ public final class JavaTranslator<S extends 
TraversalSource, T extends Traversal
                     list.add(method);
                 }
             }
-            if (delegate instanceof TraversalSource)
-                TRAVERSAL_SOURCE_METHOD_CACHE.put((Class<TraversalSource>) 
delegate.getClass(), methodCache);
-            else
-                TRAVERSAL_METHOD_CACHE.put((Class<Traversal>) 
delegate.getClass(), methodCache);
+            GLOBAL_METHOD_CACHE.put(delegate.getClass(), methodCache);
         }
         //////////////////////////
         //////////////////////////
@@ -133,7 +128,7 @@ public final class JavaTranslator<S extends 
TraversalSource, T extends Traversal
             if (arguments[i] instanceof Bytecode.Binding)
                 argumentsCopy[i] = ((Bytecode.Binding) arguments[i]).value();
             else if (arguments[i] instanceof Bytecode)
-                argumentsCopy[i] = translateFromAnonymous((Bytecode) 
arguments[i]);
+                argumentsCopy[i] = this.translateFromAnonymous((Bytecode) 
arguments[i]);
             else
                 argumentsCopy[i] = arguments[i];
         }

Reply via email to