[xoreos-devel] getNearestX call performance

Robert Hall rjh405 at gmail.com
Thu Sep 13 23:20:09 CEST 2018


Hi,

I noticed that several of the engine's nwscript 'functions_object.cpp'
files use a similar 'Functions::getNearestObject' call to find the 'nth'
nearest object. This relies on (the o(n log(n)) efficient) "objects.sort(
ObjectDistanceSort(*target))" call for ordered comparisons.

However, in the common case where 'nth' is one, I think it should always be
faster to use a "find minimum" call. (Particularly when the object count is
very large.) Perhaps there could be an if-then-else branch just before the
sort, and the nth == 1 branch could use something like (the o(n) efficient)
'std::min', for example? Would that make sense?

A similar argument holds for getNearestObjectByTag and
getNearestCreature functions.

-- 
  Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://xoreos.org/pipermail/xoreos-devel/attachments/20180913/c2809e6d/attachment.html>


More information about the xoreos-devel mailing list