From bf9f831cb2a7977c16fe146abdd41c5ee85d0bb9 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 27 Aug 2023 13:10:24 +0200 Subject: [PATCH] Inventory: skip redundant stack movement The list of dragged stacks includes the source stack, which however does not need to be moved onto itself. This is an optimization. --- src/gui/guiFormSpecMenu.cpp | 6 ++++++ src/gui/guiInventoryList.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 0e662b2822a9..8b6c78838bf4 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -4447,6 +4447,12 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event) if (m_left_drag_stacks.size() > 1) { // Finalize the left-dragging for (auto &ds : m_left_drag_stacks) { + if (ds.first == *m_selected_item) { + // This entry is needed to properly calculate the stack sizes. + // The stack already exists, hence no further action needed here. + continue; + } + // Check how many items we should move to this slot, // it may be less than the full split Inventory *inv_to = m_invmgr->getInventory(ds.first.inventoryloc); diff --git a/src/gui/guiInventoryList.h b/src/gui/guiInventoryList.h index 07ca93c3f328..8ef63c8bc0c8 100644 --- a/src/gui/guiInventoryList.h +++ b/src/gui/guiInventoryList.h @@ -43,7 +43,7 @@ class GUIInventoryList : public gui::IGUIElement { } - bool operator==(const ItemSpec& other) + bool operator==(const ItemSpec& other) const { return inventoryloc == other.inventoryloc && listname == other.listname && i == other.i;