I finally fixed the lag issue. The problem really wasn't obvious. But see for yourself
Code: Select all
city.getRoads().removeAll(removedRoads);
city.getRoads().addAll(addedRoads);
The query whether a road can be built from A to B issued always these two calls when finished.
city.getRoads() is the list of all roads while
removedRoads and
addedRoads are lists of added/removed roads during the build process. As nothing has been built in the query, the latter both lists are empty. The calls
should therefore be really cheap.
In reality, they aren't if
city.getRoads() is a really long list (as for big cities). A solution is just to avoid the two calls as they aren't needed here.
In conclusion: Don't expect any library function to be smart enough to not do unneeded heavy work where no work is to do at all. More precise:
removeAll() iterates over all elements of the list, even if the list given as parameter is empty.
Try out version 239 or later to get a performance boost in road building 8)