Improve the findNewTarget UnitAI function
When lots of units are involved, this function is really slow, mainly due to the fact that AttackEntitiesByPreference starts by checking all units in range to know if they canAttack, then sort them by preference, and then try to attack in the found order. The sort is in fact useless as units are already sorted by distance, and we only need to classify them by distance. As the initial canAttack check is quite long, it can be omitted first and only done when units are effectively tried to attack.
This is done in the attached patch which reduces the time to perform findNewtarget in "Demo Combat Huge" by a factor 4, while in this map it initially represented up to 40% of the simulation time.
see http://irclogs.wildfiregames.com/2015-11-14-QuakeNet-%230ad-dev.log for some discussions on IRC