From 9e1b97900eaf7dae656b2df187a4327b1f4d324d Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 18 Aug 2023 18:23:29 +0200 Subject: Core/Auras: Minor optimization for Unit object creation with msvc (not allocating a list end sentinel node for all of the 500 lists stored in Unit for each aura type) --- src/common/Containers/Utilities/ListUtils.h | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/common/Containers/Utilities/ListUtils.h (limited to 'src/common/Containers') diff --git a/src/common/Containers/Utilities/ListUtils.h b/src/common/Containers/Utilities/ListUtils.h new file mode 100644 index 00000000000..f5de0d42ec9 --- /dev/null +++ b/src/common/Containers/Utilities/ListUtils.h @@ -0,0 +1,53 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef TRINITYCORE_LIST_UTILS_H +#define TRINITYCORE_LIST_UTILS_H + +#include +#include + +namespace Trinity::Containers::Lists +{ +template> +inline typename std::list::iterator RemoveUnique(std::list& list, T const& value) +{ + auto itr = std::find(list.begin(), list.end(), value); + if (itr != list.end()) + return list.erase(itr); + + return list.end(); +} + +template> +inline typename std::forward_list::iterator RemoveUnique(std::forward_list& list, T const& value) +{ + auto itr = list.before_begin(); + auto toErase = std::next(itr); + while (toErase != list.end()) + { + if (*toErase == value) + return list.erase_after(itr); + + itr = toErase++; + } + + return list.end(); +} +} + +#endif // TRINITYCORE_LIST_UTILS_H -- cgit v1.2.3