mapcrafter
mapcrafter copied to clipboard
Optimize TileRenderer tile image sorting
This contains three main changes:
- Instead of sorting
TileImages directly, we'll leave them unmodified and sort pointers to them instead. This makes the actual sorting much faster, since it only has to swap a pair of pointers after each comparison instead of a 56-byte class with a non-trivial move assignment operator. -
std::sort()is now invoked separately for each of the sort modes, allowing the comparator to be inlined into the sorting code - Originally, a lot of time was being wasted resizing the
tile_imagesvector when filling it. This mitigates that by reserving a generous amount of space ahead of time, and also keeps track of the global maximum number of images per tile encountered so far.
These three optimizations reduce the total render time of a simple map by ~15% on my machine.
I've also replaced boost::container::vector with std::vector just to shave off an #include.