freecol icon indicating copy to clipboard operation
freecol copied to clipboard

Refactor and optimize the ColonizationSaveGameReader class.

Open teo-tsirpanis opened this issue 4 years ago • 2 comments

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.

teo-tsirpanis avatar Jun 08 '21 21:06 teo-tsirpanis

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

mpope042 avatar Jun 08 '21 22:06 mpope042

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.

teo-tsirpanis avatar Jun 08 '21 22:06 teo-tsirpanis