]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Fixed Acorn MainProgram and GraphClientImpl2 to use Logger" into release/1...
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 25 Feb 2019 13:50:46 +0000 (13:50 +0000)
committerGerrit Code Review <gerrit2@simantics>
Mon, 25 Feb 2019 13:50:46 +0000 (13:50 +0000)
bundles/org.simantics.diagram.connection/src/org/simantics/diagram/connection/rendering/StyledRouteGraphRenderer.java

index b084e5875714938026400e5a8b6c938659e3ca71..dd9473042152d0c3af43244d9549d63e4c649e4b 100644 (file)
@@ -36,9 +36,13 @@ public class StyledRouteGraphRenderer implements IRouteGraphRenderer, Serializab
 
        protected final ConnectionStyle style;
 
+       private static class Cache {
+               Path2D path = new Path2D.Double();
+               THashSet<RoutePoint> branchPoints = new THashSet<>();
+       }
+
        // Caches to avoid creating new objects all the time during rendering
-       protected transient Path2D path;
-       protected transient THashSet<RoutePoint> branchPoints;
+       protected static ThreadLocal<Cache> caches = ThreadLocal.withInitial(() -> new Cache());
 
        public StyledRouteGraphRenderer(ConnectionStyle style) {
                if (style == null)
@@ -52,14 +56,14 @@ public class StyledRouteGraphRenderer implements IRouteGraphRenderer, Serializab
 
        @Override
        public void render(Graphics2D g, RouteGraph rg) {
-               if (path == null)
-                       path = new Path2D.Double();
+               Cache cache = caches.get();
+               Path2D path = cache.path;
+               THashSet<RoutePoint> branchPoints = cache.branchPoints;
+
                path.reset();
                rg.getPath2D(path);
                style.drawPath(g, path, false);
 
-               if (branchPoints == null)
-                       branchPoints = new THashSet<RoutePoint>();
                branchPoints.clear();
                for(RouteLine line : rg.getLines()) {
                    renderLine(g, line, false);