Commit 7d523efd authored by AnimeGitB's avatar AnimeGitB
Browse files

Avoid allocations on Map::putIfAbsent usage

Map::computeIfAbsent only runs the passed constructors when it needs to
parent 0cb75aeb
...@@ -106,8 +106,9 @@ public class TowerManager extends BasePlayerManager { ...@@ -106,8 +106,9 @@ public class TowerManager extends BasePlayerManager {
if (!hasNextLevel()) { if (!hasNextLevel()) {
// set up the next floor // set up the next floor
recordMap.putIfAbsent(getNextFloorId(), new TowerLevelRecord(getNextFloorId())); var nextFloorId = this.getNextFloorId();
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(getNextFloorId(), 1)); recordMap.computeIfAbsent(nextFloorId, TowerLevelRecord::new);
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(nextFloorId, 1));
}else { }else {
player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, getCurrentLevel())); player.getSession().send(new PacketTowerCurLevelRecordChangeNotify(currentFloorId, getCurrentLevel()));
} }
......
...@@ -42,7 +42,7 @@ public class WorldDataSystem extends BaseGameSystem { ...@@ -42,7 +42,7 @@ public class WorldDataSystem extends BaseGameSystem {
DataLoader.loadList("ChestReward.json", ChestReward.class) DataLoader.loadList("ChestReward.json", ChestReward.class)
.forEach(reward -> .forEach(reward ->
reward.getObjNames().forEach(name -> reward.getObjNames().forEach(name ->
chestInteractHandlerMap.putIfAbsent(name, new NormalChestInteractHandler(reward)))); chestInteractHandlerMap.computeIfAbsent(name, x -> new NormalChestInteractHandler(reward))));
} catch (Exception e) { } catch (Exception e) {
Grasscutter.getLogger().error("Unable to load chest reward config.", e); Grasscutter.getLogger().error("Unable to load chest reward config.", e);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment