diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp index f774b2a004..4abef9de33 100644 --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -406,7 +406,7 @@ public: ScriptList::ScriptList() { /* Default sorter */ - this->sorter = new ScriptListSorterValueDescending(this); + this->sorter = std::make_unique(this); this->sorter_type = SORT_BY_VALUE; this->sort_ascending = false; this->initialized = false; @@ -415,7 +415,6 @@ ScriptList::ScriptList() ScriptList::~ScriptList() { - delete this->sorter; } bool ScriptList::HasItem(SQInteger item) @@ -527,21 +526,20 @@ void ScriptList::Sort(SorterType sorter, bool ascending) if (sorter != SORT_BY_VALUE && sorter != SORT_BY_ITEM) return; if (sorter == this->sorter_type && ascending == this->sort_ascending) return; - delete this->sorter; switch (sorter) { case SORT_BY_ITEM: if (ascending) { - this->sorter = new ScriptListSorterItemAscending(this); + this->sorter = std::make_unique(this); } else { - this->sorter = new ScriptListSorterItemDescending(this); + this->sorter = std::make_unique(this); } break; case SORT_BY_VALUE: if (ascending) { - this->sorter = new ScriptListSorterValueAscending(this); + this->sorter = std::make_unique(this); } else { - this->sorter = new ScriptListSorterValueDescending(this); + this->sorter = std::make_unique(this); } break; @@ -576,11 +574,11 @@ void ScriptList::SwapList(ScriptList *list) this->items.swap(list->items); this->buckets.swap(list->buckets); - Swap(this->sorter, list->sorter); - Swap(this->sorter_type, list->sorter_type); - Swap(this->sort_ascending, list->sort_ascending); - Swap(this->initialized, list->initialized); - Swap(this->modifications, list->modifications); + std::swap(this->sorter, list->sorter); + std::swap(this->sorter_type, list->sorter_type); + std::swap(this->sort_ascending, list->sort_ascending); + std::swap(this->initialized, list->initialized); + std::swap(this->modifications, list->modifications); this->sorter->Retarget(this); list->sorter->Retarget(list); } diff --git a/src/script/api/script_list.hpp b/src/script/api/script_list.hpp index 0570364e24..164dd15ba6 100644 --- a/src/script/api/script_list.hpp +++ b/src/script/api/script_list.hpp @@ -36,7 +36,7 @@ public: static const bool SORT_DESCENDING = false; private: - ScriptListSorter *sorter; ///< Sorting algorithm + std::unique_ptr sorter; ///< Sorting algorithm SorterType sorter_type; ///< Sorting type bool sort_ascending; ///< Whether to sort ascending or descending bool initialized; ///< Whether an iteration has been started