use HashSet instead of ArrayList in getStandaloneBoats() for performance

Change-Id: Ie6648a8f81ea9534bfe411cd2902ed1c082ce5ec
This commit is contained in:
Axel Uhl committed 2018-03-19 18:22:19 +01:00
1 parent a66ffac4b3
commit e750f974be
2 files changed
+3 -6

No files matched your search

@@ -601,9 +601,9 @@ public class TransientCompetitorStoreImpl implements CompetitorStore, Serializab
public Iterable<Boat> getStandaloneBoats() {
LockUtil.lockForRead(lock);
try {
List<Boat> boats = new ArrayList<>(boatCache.values());
Set<Boat> boats = new HashSet<>(boatCache.values());
Set<Boat> boatsEmbeddedInCompetitors = new HashSet<>();
for (Competitor competitor: competitorCache.values()) {
for (Competitor competitor : competitorCache.values()) {
if (isValidCompetitorWithBoat(competitor)) {
boatsEmbeddedInCompetitors.add(((CompetitorWithBoat) competitor).getBoat());
}
@@ -613,7 +613,6 @@ public class TransientCompetitorStoreImpl implements CompetitorStore, Serializab
} finally {
LockUtil.unlockAfterRead(lock);
}
}
protected void removeBoat(Boat boat) {
@@ -82,14 +82,12 @@ public class PersistentCompetitorStore extends TransientCompetitorStoreImpl impl
if (allLegacyCompetitorsWithBoat != null) {
List<Competitor> newCompetitors = new ArrayList<>();
List<Boat> newBoats = new ArrayList<>();
for (CompetitorWithBoat competitorWithBoat: allLegacyCompetitorsWithBoat) {
for (CompetitorWithBoat competitorWithBoat : allLegacyCompetitorsWithBoat) {
Boat containedBoat = competitorWithBoat.getBoat();
// Create a new random uuid for the boats to make sure the competitor uuid is not used
UUID boatUUID = UUID.randomUUID();
DynamicBoat newBoat = new BoatImpl(boatUUID, null /* the old boat names were nonsense names */, containedBoat.getBoatClass(), containedBoat.getSailID());
newBoats.add(newBoat);
CompetitorWithBoat newCompetitorWithBoat = new CompetitorWithBoatImpl((Competitor) competitorWithBoat, newBoat);
newCompetitors.add(newCompetitorWithBoat);
}