feat: removes unecessary allocations

This commit is contained in:
2026-04-25 18:57:12 -03:00
parent 754c6a1313
commit b9d190c978

View File

@@ -9,25 +9,19 @@ import {
class RoomInspector { class RoomInspector {
public static inspectState(room: Room, state: GameState): GameState { public static inspectState(room: Room, state: GameState): GameState {
if (!this.stateWasInitialized(state)) { if (!state.sourcesStates) {
state = this.initializeState(room, state); this.initializeState(room, state);
} }
return state; return state;
} }
private static stateWasInitialized(state: GameState): boolean { private static initializeState(room: Room, state: GameState): void {
return !!state.sourcesStates;
}
private static initializeState(room: Room, state: GameState): GameState {
state.sourcesStates = {}; state.sourcesStates = {};
state.maxHarvesters = 0; state.maxHarvesters = 0;
for (const source of room.find(FIND_SOURCES)) { for (const source of room.find(FIND_SOURCES)) {
this.configureSourceState(source, state); this.configureSourceState(source, state);
} }
return state;
} }
private static configureSourceState( private static configureSourceState(