mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Fix and simplify check for maximum number of favorite communities
Because of incorrect index/size math, two favorite communities were removed when exceeding the maximum number of three favorite communities instead of only one. The check can be simplified because the maximum number of favorite communities can never be exceeded, so at most the first element needs to be removed from the vector. Closes #7935.
This commit is contained in:
parent
68ee8a758b
commit
bf3622e8f1
|
@ -1701,13 +1701,14 @@ void CFavoriteCommunityFilterList::Add(const char *pCommunityId)
|
|||
// the end of the list, to allow setting the entire list easier with binds.
|
||||
Remove(pCommunityId);
|
||||
|
||||
// Ensure maximum number of favorite communities, by removing least-recently
|
||||
// added communities from the beginning. One more than the maximum is removed
|
||||
// to make room for the new community.
|
||||
// Ensure maximum number of favorite communities, by removing the least-recently
|
||||
// added community from the beginning, when the maximum number of favorite
|
||||
// communities has been reached.
|
||||
constexpr size_t MaxFavoriteCommunities = 3;
|
||||
if(m_vEntries.size() >= MaxFavoriteCommunities)
|
||||
{
|
||||
m_vEntries.erase(m_vEntries.begin(), m_vEntries.begin() + (MaxFavoriteCommunities - 1));
|
||||
dbg_assert(m_vEntries.size() == MaxFavoriteCommunities, "Maximum number of communities can never be exceeded");
|
||||
m_vEntries.erase(m_vEntries.begin());
|
||||
}
|
||||
m_vEntries.emplace_back(pCommunityId);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue