X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.graph.compiler%2Fsrc%2Forg%2Fsimantics%2Fgraph%2Fcompiler%2FGraphCompiler.java;h=26663b08a2a5f288e9f38753ff53162045a82c02;hp=98852bcefafc4962bc90e3e64ae4b15c1b1549d0;hb=aab6399f20c07b61a0dbf9614614f44a2e0ea325;hpb=fb019f116468d003a751e4274a69ba01c34fa10b diff --git a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java index 98852bcef..26663b08a 100644 --- a/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java +++ b/bundles/org.simantics.graph.compiler/src/org/simantics/graph/compiler/GraphCompiler.java @@ -15,12 +15,11 @@ import java.util.Locale; import org.simantics.databoard.Bindings; import org.simantics.databoard.Files; import org.simantics.databoard.adapter.AdaptException; +import org.simantics.databoard.binding.Binding; import org.simantics.databoard.binding.error.BindingException; -import org.simantics.databoard.binding.error.RuntimeBindingConstructionException; import org.simantics.databoard.binding.mutable.Variant; import org.simantics.databoard.container.DataContainer; import org.simantics.databoard.container.DataContainers; -import org.simantics.databoard.serialization.SerializationException; import org.simantics.graph.compiler.internal.parsing.Parsing; import org.simantics.graph.compiler.internal.procedures.AddConsistsOf; import org.simantics.graph.compiler.internal.procedures.ApplyTemplates; @@ -39,6 +38,7 @@ import org.simantics.graph.compiler.internal.validation.ValidateGraph; import org.simantics.graph.query.CompositeGraph; import org.simantics.graph.query.Paths; import org.simantics.graph.query.TransferableGraphConversion; +import org.simantics.graph.representation.Extensions; import org.simantics.graph.representation.TransferableGraph1; import org.simantics.graph.store.GraphStore; import org.simantics.ltk.FileSource; @@ -62,10 +62,17 @@ public class GraphCompiler { } public static InputStream write(TransferableGraph1 tg) throws BindingException, IOException { - byte[] buffer = DataContainers.writeFile( - new DataContainer("graph", 1, new Variant(TransferableGraph1.BINDING, tg)) - ); - return new ByteArrayInputStream(buffer); + Binding binding = TransferableGraph1.BINDING; + int hashCode = binding.hashValue(tg); + tg.extensions.put(Extensions.CACHED_HASHCODE, new Variant(Bindings.INTEGER, hashCode)); + try { + byte[] buffer = DataContainers.writeFile( + new DataContainer("graph", 1, new Variant(TransferableGraph1.BINDING, tg)) + ); + return new ByteArrayInputStream(buffer); + } finally { + tg.extensions.remove(Extensions.CACHED_HASHCODE); + } } public static CompilationResult compile( @@ -200,9 +207,10 @@ public class GraphCompiler { public static void reportTime(String taskName, long beginTime, long endTime) { StringBuilder sb = new StringBuilder(); - Formatter formatter = new Formatter(sb, Locale.US); - formatter.format("%-25s %8.4f ms", taskName, (endTime - beginTime)*1e-6); - + @SuppressWarnings("resource") + Formatter formatter = new Formatter(sb, Locale.US); + formatter.format("%-25s %8.4f ms", taskName, (endTime - beginTime)*1e-6); + out.println(sb.toString()); }