diff options
| author | Shauren <shauren.trinity@gmail.com> | 2023-08-18 18:23:29 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2023-08-18 18:23:29 +0200 |
| commit | 9e1b97900eaf7dae656b2df187a4327b1f4d324d (patch) | |
| tree | 5442b0a5380fb26c37dc152202283ff55c849909 /src/common/Containers | |
| parent | e851902054ecab52c063a8a53854fc7ef8116297 (diff) | |
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)
Diffstat (limited to 'src/common/Containers')
| -rw-r--r-- | src/common/Containers/Utilities/ListUtils.h | 53 |
1 files changed, 53 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. + */ + +#ifndef TRINITYCORE_LIST_UTILS_H +#define TRINITYCORE_LIST_UTILS_H + +#include <forward_list> +#include <list> + +namespace Trinity::Containers::Lists +{ +template<typename T, typename Alloc = std::allocator<T>> +inline typename std::list<T, Alloc>::iterator RemoveUnique(std::list<T, Alloc>& 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<typename T, typename Alloc = std::allocator<T>> +inline typename std::forward_list<T, Alloc>::iterator RemoveUnique(std::forward_list<T, Alloc>& 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 |
