Skip to content

Commit a65596e

Browse files
committed
Eliminated some temporary object creation in API calls
1 parent cdb67d5 commit a65596e

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

src/main/java/bwapi/Game.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -872,10 +872,7 @@ final public boolean isWalkable(final int walkX, final int walkY) {
872872
}
873873

874874
final public boolean isWalkable(final WalkPosition position) {
875-
if (!position.isValid(this)) {
876-
return false;
877-
}
878-
return walkable[position.x][position.y];
875+
return position.isValid(this) && walkable[position.x][position.y];
879876
}
880877

881878
/**
@@ -892,15 +889,12 @@ final public boolean isWalkable(final WalkPosition position) {
892889
* - 5: Very high ground doodad
893890
* .
894891
*/
895-
public int getGroundHeight(final int tileX, final int tileY) {
896-
return getGroundHeight(new TilePosition(tileX, tileY));
892+
final public int getGroundHeight(final int tileX, final int tileY) {
893+
return isValidTile(tileX, tileY) ? groundHeight[tileX][tileY] : 0;
897894
}
898895

899-
public int getGroundHeight(final TilePosition position) {
900-
if (!position.isValid(this)) {
901-
return 0;
902-
}
903-
return groundHeight[position.x][position.y];
896+
final public int getGroundHeight(final TilePosition position) {
897+
return getGroundHeight(position.x, position.y);
904898
}
905899

906900
final public boolean isBuildable(final int tileX, final int tileY) {
@@ -1014,23 +1008,23 @@ final public boolean hasPowerPrecise(final Position position, final UnitType uni
10141008
return hasPowerPrecise(position.x, position.y, unitType);
10151009
}
10161010

1017-
final public boolean hasPower(final int tileX, final int tileY) {
1018-
return hasPower(new TilePosition(tileX, tileY));
1011+
final public boolean hasPower(final TilePosition position) {
1012+
return hasPower(position.x, position.y);
10191013
}
10201014

1021-
final public boolean hasPower(final int tileX, final int tileY, final UnitType unitType) {
1022-
return hasPower(new TilePosition(tileX, tileY), unitType);
1015+
final public boolean hasPower(final int tileX, final int tileY) {
1016+
return hasPower(tileX, tileY, UnitType.None);
10231017
}
10241018

1025-
final public boolean hasPower(final TilePosition position) {
1026-
return hasPower(position.x, position.y, UnitType.None);
1019+
final public boolean hasPower(final TilePosition position, final UnitType unitType) {
1020+
return hasPower(position.x, position.y, unitType);
10271021
}
10281022

1029-
final public boolean hasPower(final TilePosition position, final UnitType unitType) {
1023+
final public boolean hasPower(final int tileX, final int tileY, final UnitType unitType) {
10301024
if (unitType.id >= 0 && unitType.id < UnitType.None.id) {
1031-
return hasPowerPrecise(position.x * 32 + unitType.tileWidth() * 16, position.y * 32 + unitType.tileHeight() * 16, unitType);
1025+
return hasPowerPrecise(tileX * 32 + unitType.tileWidth() * 16, tileY * 32 + unitType.tileHeight() * 16, unitType);
10321026
}
1033-
return hasPowerPrecise(position.x * 32, position.y * 32, UnitType.None);
1027+
return hasPowerPrecise(tileY * 32, tileY * 32, UnitType.None);
10341028
}
10351029

10361030
final public boolean hasPower(final int tileX, final int tileY, final int tileWidth, final int tileHeight) {

0 commit comments

Comments
 (0)