FreeCol / freecol

FreeCol: FreeCol is a turn-based strategy game based on the old game Colonization, and similar to Civilization. The objective of the game is to create an independent nation.
GNU General Public License v2.0
589 stars 173 forks source link

Refactor and optimize the ColonizationSaveGameReader class. #97

Open teo-tsirpanis opened 3 years ago

teo-tsirpanis commented 3 years ago

This PR refactors the ColonizationSaveGameReader class by using static methods instead of creating objects only to call one method on them named print or run. Besides the reduced temporary object allocations, this PR also eliminated a redundant copy of the entire save file at the class' now-deleted constructor, and an array copy at the getString method by using another overload of Java's String class' constructor. Speaking of getString, it was moved to an inner class named Utilities to avoid a cyclic dependency warning by Designite.

mpope042 commented 3 years ago

Curious. ColonizationSaveGameReader is a rarely used standalone class. Refactoring it has very limited benefit. I have to ask why did you bother?

teo-tsirpanis commented 3 years ago

It is for a "Software Quality" university project. We had to pick a project and apply refactorings to it to increase its quality and my team chose FreeCol. And I personally enjoy refactoring and optimizing code.