From: "Enrico Weigelt, metux IT consult" <enrico.weig...@gr13.net>

The previous implementation first generated a list of applicable
bordering directions (via streams and extra predicate object calls),
and then again iterates this list to collect the corner points.

This can be easily done in one pass, as the second list is a direct
mapping out of the first one (IOW: the same decision criteria).

And the data set is so small that the overhead of streams and
MethodRef calls really outweights the potetial gain from parallelization.
OTOH, we could think about rendering several tiles in parallel.
---
 src/net/sf/freecol/client/gui/RoadPainter.java | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/net/sf/freecol/client/gui/RoadPainter.java 
b/src/net/sf/freecol/client/gui/RoadPainter.java
index 55082a54908..48ed92b9168 100644
--- a/src/net/sf/freecol/client/gui/RoadPainter.java
+++ b/src/net/sf/freecol/client/gui/RoadPainter.java
@@ -27,17 +27,16 @@ import java.awt.RenderingHints;
 import java.awt.Stroke;
 import java.awt.geom.GeneralPath;
 import java.awt.geom.Point2D;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.EnumMap;
 import java.util.List;
-import java.util.function.Predicate;
 
 import net.sf.freecol.common.model.Direction;
 import net.sf.freecol.common.model.Map;
 import net.sf.freecol.common.model.Tile;
 import net.sf.freecol.common.model.TileImprovement;
 import net.sf.freecol.common.resources.ResourceManager;
-import static net.sf.freecol.common.util.CollectionUtils.*;
 
 
 /**
@@ -122,16 +121,23 @@ public final class RoadPainter {
         final Map map = tile.getMap();
         final int x = tile.getX();
         final int y = tile.getY();
-        final Predicate<Direction> borderPred = d -> {
+
+        List<Direction> directions = new ArrayList<>();
+        List<Point2D.Float> points = new ArrayList<>();
+
+        // do it in one pass instead of two subsequent ones
+        for (Direction d : Direction.allDirections) {
             Tile borderingTile = map.getTile(d.step(x, y));
             TileImprovement r;
-            return borderingTile != null
+            if (borderingTile != null
                 && (r = borderingTile.getRoad()) != null
-                && r.isComplete();
-        };
-        List<Direction> directions = transform(Direction.allDirections, 
borderPred);
-        List<Point2D.Float> points = transform(directions, alwaysTrue(),
-                                               d -> corners.get(d));
+                && r.isComplete())
+            {
+                directions.add(d);
+                points.add(corners.get(d));
+            }
+        }
+
         GeneralPath path = new GeneralPath();
         switch (points.size()) {
         case 0:
-- 
2.11.0.rc0.7.gbe5a750


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Freecol-developers mailing list
Freecol-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freecol-developers

Reply via email to