Synchronize less in transportation_name layer (#180)

This commit is contained in:
Michael Barry
2022-04-19 06:38:50 -04:00
committed by GitHub
parent 7631199242
commit e876314e2b

View File

@@ -42,6 +42,8 @@ import static com.onthegomap.planetiler.basemap.util.Utils.*;
import com.carrotsearch.hppc.LongArrayList; import com.carrotsearch.hppc.LongArrayList;
import com.carrotsearch.hppc.LongByteMap; import com.carrotsearch.hppc.LongByteMap;
import com.carrotsearch.hppc.LongHashSet;
import com.carrotsearch.hppc.LongSet;
import com.onthegomap.planetiler.FeatureCollector; import com.onthegomap.planetiler.FeatureCollector;
import com.onthegomap.planetiler.FeatureMerge; import com.onthegomap.planetiler.FeatureMerge;
import com.onthegomap.planetiler.ForwardingProfile; import com.onthegomap.planetiler.ForwardingProfile;
@@ -124,6 +126,7 @@ public class TransportationName implements
private final boolean minorRefs; private final boolean minorRefs;
private Transportation transportation; private Transportation transportation;
private final LongByteMap motorwayJunctionHighwayClasses = Hppc.newLongByteHashMap(); private final LongByteMap motorwayJunctionHighwayClasses = Hppc.newLongByteHashMap();
private final LongSet motorwayJunctionNodes = new LongHashSet();
public TransportationName(Translations translations, PlanetilerConfig config, Stats stats) { public TransportationName(Translations translations, PlanetilerConfig config, Stats stats) {
this.config = config; this.config = config;
@@ -157,8 +160,8 @@ public class TransportationName implements
@Override @Override
public void preprocessOsmNode(OsmElement.Node node) { public void preprocessOsmNode(OsmElement.Node node) {
if (node.hasTag("highway", "motorway_junction")) { if (node.hasTag("highway", "motorway_junction")) {
synchronized (motorwayJunctionHighwayClasses) { synchronized (motorwayJunctionNodes) {
motorwayJunctionHighwayClasses.put(node.id(), HighwayClass.UNKNOWN.value); motorwayJunctionNodes.add(node.id());
} }
} }
} }
@@ -170,11 +173,11 @@ public class TransportationName implements
HighwayClass cls = HighwayClass.from(highway); HighwayClass cls = HighwayClass.from(highway);
if (cls != HighwayClass.UNKNOWN) { if (cls != HighwayClass.UNKNOWN) {
LongArrayList nodes = way.nodes(); LongArrayList nodes = way.nodes();
synchronized (motorwayJunctionHighwayClasses) { for (int i = 0; i < nodes.size(); i++) {
for (int i = 0; i < nodes.size(); i++) { long node = nodes.get(i);
long node = nodes.get(i); if (motorwayJunctionNodes.contains(node)) {
if (motorwayJunctionHighwayClasses.containsKey(node)) { synchronized (motorwayJunctionHighwayClasses) {
byte oldValue = motorwayJunctionHighwayClasses.get(node); byte oldValue = motorwayJunctionHighwayClasses.getOrDefault(node, HighwayClass.UNKNOWN.value);
byte newValue = cls.value; byte newValue = cls.value;
if (newValue > oldValue) { if (newValue > oldValue) {
motorwayJunctionHighwayClasses.put(node, newValue); motorwayJunctionHighwayClasses.put(node, newValue);