From b8e528ebfba266fa719c81c3b4afc2c36f01cd60 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Tue, 1 Jul 2025 01:49:57 +0100 Subject: [PATCH] Palette k-d tree: A small lookup optimization Avoid needlessly recalculating the best distance so far. 7.88 M/s -> 8.47 M/s `GenerateBlendedLookupTable` takes 5% less time. --- Source/utils/palette_kd_tree.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/utils/palette_kd_tree.hpp b/Source/utils/palette_kd_tree.hpp index 84308f964..9f6843304 100644 --- a/Source/utils/palette_kd_tree.hpp +++ b/Source/utils/palette_kd_tree.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -323,8 +324,7 @@ private: // To see if we need to check a node's subtree, we compare the distance from the query // to the current best candidate vs the distance to the edge of the half-space represented // by the node. - if (bestDiff == std::numeric_limits::max() - || GetColorDistanceToPlane(node.pivot, coord) < GetColorDistance(values_[best].first, rgb)) { + if (GetColorDistanceToPlane(node.pivot, coord) < bestDiff) { findNearestNeighborVisit(node.child(coord >= node.pivot), rgb, bestDiff, best); } }