simon987 / Much-Assembly-Required

Assembly programming game
https://muchassemblyrequired.com
GNU General Public License v3.0
924 stars 88 forks source link

GameUniverse is inefficient #121

Closed djsheehy closed 6 years ago

djsheehy commented 6 years ago

The getWorld method of GameUniverse looks up a world by x and y coordinates by going through every world in a list and checking each one. If you have a lot of worlds, this might get slow. Instead you should have a HashTable with coordinates as keys:

private HashTable<Point, World> worldsByCoordinates;

Then you can look them up much more efficiently.

The getUser method does the same thing. It should have a HashTable too to look them up by name.

sg495 commented 6 years ago

Good point. Pull request #118 already switches worlds to private Hashtable<String,World> worlds, because worlds are now identified in the database by a unique string ID (which can be computed as a function of the coordinates). Next pull request I make on database stuff I will also switch users to private Hashtable<String,User> users and update the getUser method accordingly.