stepmania/stepmania — pull request #96 by kyzentun (2014-03-17 00:15:11+00:00)
Title: Unload profile optimization

ProfileManager::UnloadProfile was going through all the work of unloading profiles even when there wasn't originally a profile loaded in that slot, including traversing the entire list of all loaded songs checking for edits that might need to be unloaded.
GameState::UnjoinPlayer was calling ResetPlayer before unjoining the player from STATSMAN. ResetPlayer also calls UnloadProfile, so UnloadProfile was running twice, once before the STATSMAN unjoin, and once after. Since STATSMAN marks edit charts and songs as okay to free, the first UnloadProfile wasn't actually unloading songs and edits, but it was unloading every other aspect of the profile. The second call was what was actually unloading songs.
Additionally, UnjoinPlayer wasn't updating the master player number correctly, because GetFirstHumanPlayer just looks at the current style (if it's a two player style), and UnjoinPlayer has to occur before the style can change.