Skip to content

Commit 754223e

Browse files
committed
use a view of the array instead of allocating a new one
1 parent e3e6795 commit 754223e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/main/java/bwapi/Game.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void onFrame(final int frame) {
325325
* Avoids previous O(n^2) implementation which would be costly for
326326
* lategame carrier fights
327327
*/
328-
public List<Unit> getConnected(final Unit unit) {
328+
List<Unit> getConnected(final Unit unit) {
329329
final int frame = getFrameCount();
330330
if (lastConnectedUnitsUpdate < frame) {
331331
connectedUnits.clear();
@@ -346,13 +346,13 @@ public List<Unit> getConnected(final Unit unit) {
346346
if (!connectedUnits.containsKey(unit)) {
347347
return Collections.emptyList();
348348
}
349-
return new ArrayList<>(connectedUnits.get(unit));
349+
return Collections.unmodifiableList(connectedUnits.get(unit));
350350
}
351351

352352
/**
353353
* @see #getConnected
354354
*/
355-
public List<Unit> getLoadedUnits(final Unit unit) {
355+
List<Unit> getLoadedUnits(final Unit unit) {
356356
final int frame = getFrameCount();
357357
if (lastLoadedUnitsUpdate < frame) {
358358
loadedUnits.clear();
@@ -370,7 +370,7 @@ public List<Unit> getLoadedUnits(final Unit unit) {
370370
if (!loadedUnits.containsKey(unit)) {
371371
return Collections.emptyList();
372372
}
373-
return new ArrayList<>(loadedUnits.get(unit));
373+
return Collections.unmodifiableList(loadedUnits.get(unit));
374374
}
375375

376376
/**

0 commit comments

Comments
 (0)