From 52911e43024ea628b8fa00a5cda3847c9de7b054 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Thu, 8 Oct 2020 07:28:53 +0200 Subject: [PATCH] Use std::sort instead of bubble_sort --- src/base/tl/algorithm.h | 3 ++- src/game/client/components/countryflags.h | 2 +- src/game/client/components/menus.h | 4 ++-- src/game/client/components/menus_settings.cpp | 2 +- src/game/client/components/skins.h | 12 ++++++------ src/game/editor/editor.h | 2 +- src/game/mapitems.h | 2 +- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/base/tl/algorithm.h b/src/base/tl/algorithm.h index d90fcc9c9..74d649fdf 100644 --- a/src/base/tl/algorithm.h +++ b/src/base/tl/algorithm.h @@ -4,6 +4,7 @@ #define BASE_TL_ALGORITHM_H #include "base/tl/range.h" +#include #include /* @@ -108,7 +109,7 @@ void sort_quick(R range) template void sort(R range) { - sort_bubble(range); + std::sort(&range.front(), &range.back() + 1); } template diff --git a/src/game/client/components/countryflags.h b/src/game/client/components/countryflags.h index 7e1e9e85d..d079417e4 100644 --- a/src/game/client/components/countryflags.h +++ b/src/game/client/components/countryflags.h @@ -15,7 +15,7 @@ public: char m_aCountryCodeString[8]; IGraphics::CTextureHandle m_Texture; - bool operator<(const CCountryFlag &Other) { return str_comp(m_aCountryCodeString, Other.m_aCountryCodeString) < 0; } + bool operator<(const CCountryFlag &Other) const { return str_comp(m_aCountryCodeString, Other.m_aCountryCodeString) < 0; } }; void OnInit(); diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index f940ac90f..902178210 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -316,7 +316,7 @@ protected: const CFriendInfo *m_pFriendInfo; int m_NumFound; - bool operator<(const CFriendItem &Other) + bool operator<(const CFriendItem &Other) const { if(m_NumFound && !Other.m_NumFound) return true; @@ -473,7 +473,7 @@ public: CGhostItem() : m_Slot(-1), m_Own(false) { m_aFilename[0] = 0; } - bool operator<(const CGhostItem &Other) { return m_Time < Other.m_Time; } + bool operator<(const CGhostItem &Other) const { return m_Time < Other.m_Time; } bool Active() const { return m_Slot != -1; } bool HasFile() const { return m_aFilename[0]; } diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 843830ac2..bc14cc93d 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -1302,7 +1302,7 @@ public: string m_FileName; int m_CountryCode; - bool operator<(const CLanguage &Other) { return m_Name < Other.m_Name; } + bool operator<(const CLanguage &Other) const { return m_Name < Other.m_Name; } }; void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, sorted_array *pLanguages) diff --git a/src/game/client/components/skins.h b/src/game/client/components/skins.h index 677332a4f..24645a9a7 100644 --- a/src/game/client/components/skins.h +++ b/src/game/client/components/skins.h @@ -20,10 +20,10 @@ public: char m_aName[24]; ColorRGBA m_BloodColor; - bool operator<(const CSkin &Other) { return str_comp(m_aName, Other.m_aName) < 0; } + bool operator<(const CSkin &Other) const { return str_comp(m_aName, Other.m_aName) < 0; } - bool operator<(const char *pOther) { return str_comp(m_aName, pOther) < 0; } - bool operator==(const char *pOther) { return !str_comp(m_aName, pOther); } + bool operator<(const char *pOther) const { return str_comp(m_aName, pOther) < 0; } + bool operator==(const char *pOther) const { return !str_comp(m_aName, pOther); } }; struct CDownloadSkin @@ -32,9 +32,9 @@ public: char m_aPath[MAX_PATH_LENGTH]; char m_aName[24]; - bool operator<(const CDownloadSkin &Other) { return str_comp(m_aName, Other.m_aName) < 0; } - bool operator<(const char *pOther) { return str_comp(m_aName, pOther) < 0; } - bool operator==(const char *pOther) { return !str_comp(m_aName, pOther); } + bool operator<(const CDownloadSkin &Other) const { return str_comp(m_aName, Other.m_aName) < 0; } + bool operator<(const char *pOther) const { return str_comp(m_aName, pOther) < 0; } + bool operator==(const char *pOther) const { return !str_comp(m_aName, pOther); } }; void OnInit(); diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index be57391b9..d0c3ce26e 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -881,7 +881,7 @@ public: int m_StorageType; bool m_IsVisible; - bool operator<(const CFilelistItem &Other) { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false : m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false : str_comp_nocase(m_aFilename, Other.m_aFilename) < 0; } + bool operator<(const CFilelistItem &Other) const { return !str_comp(m_aFilename, "..") ? true : !str_comp(Other.m_aFilename, "..") ? false : m_IsDir && !Other.m_IsDir ? true : !m_IsDir && Other.m_IsDir ? false : str_comp_nocase(m_aFilename, Other.m_aFilename) < 0; } }; sorted_array m_FileList; int m_FilesStartAt; diff --git a/src/game/mapitems.h b/src/game/mapitems.h index 10f6d9b8d..b5b0a23ce 100644 --- a/src/game/mapitems.h +++ b/src/game/mapitems.h @@ -347,7 +347,7 @@ struct CEnvPoint int m_Curvetype; int m_aValues[4]; // 1-4 depending on envelope (22.10 fixed point) - bool operator<(const CEnvPoint &Other) { return m_Time < Other.m_Time; } + bool operator<(const CEnvPoint &Other) const { return m_Time < Other.m_Time; } }; struct CMapItemEnvelope_v1