From a96aa1725f6d0760d3df39c5a1a44eb196f7c8c6 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 7 Mar 2022 22:58:50 +0100 Subject: [PATCH] Optimize `AssignedProtos::empty()` to stop early Also allow counting an `AssignedProtos`'s number of proto-palettes --- src/gfx/pal_packing.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gfx/pal_packing.cpp b/src/gfx/pal_packing.cpp index e354c4f5..ab9e883a 100644 --- a/src/gfx/pal_packing.cpp +++ b/src/gfx/pal_packing.cpp @@ -156,7 +156,13 @@ public: } void clear() { _assigned.clear(); } - bool empty() const { return std::distance(begin(), end()) == 0; } + bool empty() const { + return std::find_if_not( + _assigned.begin(), _assigned.end(), + [](std::optional const &slot) { return slot.has_value(); }) + == _assigned.end(); + } + size_t nbProtoPals() const { return std::distance(begin(), end()); } private: template