From b292a06b3f6e24fd0ab2239f75ea9094327259c9 Mon Sep 17 00:00:00 2001 From: Tobias Gloth Date: Tue, 21 Jul 2026 15:14:14 -0400 Subject: [PATCH] std::set_union expects its inputs to be sorted. (#13928) --- src/slic3r/GUI/Tab.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index e2eb67a5fb..6bb47059e2 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3299,7 +3299,19 @@ static std::vector intersect(std::vector const& l, std static std::vector concat(std::vector const& l, std::vector const& r) { std::vector t; - std::set_union(l.begin(), l.end(), r.begin(), r.end(), std::back_inserter(t)); + bool l_is_sorted = std::is_sorted(l.begin(), l.end()); + bool r_is_sorted = std::is_sorted(r.begin(), r.end()); + + if (l_is_sorted && r_is_sorted) { + std::set_union(l.begin(), l.end(), r.begin(), r.end(), std::back_inserter(t)); + return t; + } + + std::vector l_sorted = l; + std::vector r_sorted = r; + std::sort(l_sorted.begin(), l_sorted.end()); + std::sort(r_sorted.begin(), r_sorted.end()); + std::set_union(l_sorted.begin(), l_sorted.end(), r_sorted.begin(), r_sorted.end(), std::back_inserter(t)); return t; }