You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2019/03/25 14:59:22 UTC

[tinkerpop] branch tp4 updated: some code clean up on LocalMachine>

This is an automated email from the ASF dual-hosted git repository.

okram pushed a commit to branch tp4
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/tp4 by this push:
     new 21c098d  some code clean up on LocalMachine>
21c098d is described below

commit 21c098d1e0c1fb0cf13f2fdae07a97bb7db4a54d
Author: Marko A. Rodriguez <ok...@gmail.com>
AuthorDate: Mon Mar 25 08:59:13 2019 -0600

    some code clean up on LocalMachine>
---
 .../org/apache/tinkerpop/machine/LocalMachine.java | 25 ++++++++++++----------
 .../machine/bytecode/compiler/Compilation.java     |  4 ++--
 2 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/LocalMachine.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/LocalMachine.java
index 774a3aa..a5d4e27 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/LocalMachine.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/LocalMachine.java
@@ -47,18 +47,21 @@ public final class LocalMachine implements Machine {
     public <C> Bytecode<C> register(Bytecode<C> sourceCode) {
         sourceCode = sourceCode.clone(); // if the connection is local, don't mutate original
         final Optional<UUID> id = LocalMachine.getSourceId(sourceCode);
-        if (id.isPresent() && this.sources.containsKey(id.get())) {
-            if (1 == sourceCode.getSourceInstructions().size())
-                return sourceCode;
-            final SourceCompilation<C> source = (SourceCompilation<C>) this.sources.get(id.get());
-            BytecodeUtil.mergeSourceInstructions(source.getSourceCode(), sourceCode);
+        if (id.isPresent()) {
+            if (this.sources.containsKey(id.get())) {
+                if (1 == sourceCode.getSourceInstructions().size())
+                    return sourceCode;
+                final SourceCompilation<C> source = (SourceCompilation<C>) this.sources.get(id.get());
+                BytecodeUtil.mergeSourceInstructions(source.getSourceCode(), sourceCode);
+            }
             sourceCode.getInstructions().removeIf(i -> i.op().equals(WITH_SOURCE_CODE));
         }
         final UUID uuid = UUID.randomUUID();
         this.sources.put(uuid, new SourceCompilation<>(sourceCode));
-        final Bytecode<C> newSource = new Bytecode<>();
-        newSource.addUniqueSourceInstruction(WITH_SOURCE_CODE, uuid.toString());
-        return newSource;
+        final Bytecode<C> registeredBytecode = new Bytecode<>();
+        registeredBytecode.addSourceInstruction(WITH_SOURCE_CODE, uuid.toString());
+        registeredBytecode.getInstructions().addAll(sourceCode.getInstructions()); // all bytecode is returned
+        return registeredBytecode;
     }
 
     @Override
@@ -69,9 +72,9 @@ public final class LocalMachine implements Machine {
     @Override
     public <C, E> Iterator<Traverser<C, E>> submit(Bytecode<C> bytecode) {
         bytecode = bytecode.clone();
-        final UUID sourceId = LocalMachine.getSourceId(bytecode).orElse(null);
-        final SourceCompilation<C> source = null == sourceId ? null : (SourceCompilation<C>) this.sources.get(sourceId);
-        return null == sourceId ?
+        final UUID sourceId = LocalMachine.getSourceId(bytecode).orElse(UUID.randomUUID());
+        final SourceCompilation<C> source = (SourceCompilation<C>) this.sources.get(sourceId);
+        return null == source ?
                 Compilation.<C, Object, E>compile(bytecode).getProcessor() :
                 Compilation.<C, Object, E>compile(source, bytecode).getProcessor();
     }
diff --git a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/Compilation.java b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/Compilation.java
index 3193685..5c02215 100644
--- a/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/Compilation.java
+++ b/java/machine/machine-core/src/main/java/org/apache/tinkerpop/machine/bytecode/compiler/Compilation.java
@@ -62,10 +62,10 @@ public final class Compilation<C, S, E> implements Serializable {
     }
 
     public Compilation(final ProcessorFactory processorFactory) {
-        this.functions = Collections.emptyList(); // TODO: somehow strings for primitive processors
-        this.structureFactory = null;
+        this.structureFactory = EmptyStructure.instance();
         this.processorFactory = processorFactory;
         this.traverserFactory = null;
+        this.functions = Collections.emptyList(); // TODO: somehow strings for primitive processors
     }
 
     public Processor<C, S, E> getProcessor() {