mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #2738
2738: Don't search the sorted array linearly r=heinrich5991 a=Learath2 Small optimization but it could start mattering with #2733 Co-authored-by: Learath <learath2@gmail.com>
This commit is contained in:
commit
f6e1ed5f19
|
@ -196,7 +196,7 @@ const CSkins::CSkin *CSkins::Get(int Index)
|
|||
return &m_aSkins[Index % m_aSkins.size()];
|
||||
}
|
||||
|
||||
int CSkins::Find(const char *pName) const
|
||||
int CSkins::Find(const char *pName)
|
||||
{
|
||||
const char *pSkinPrefix = m_EventSkinPrefix[0] ? m_EventSkinPrefix : g_Config.m_ClSkinPrefix;
|
||||
if(g_Config.m_ClVanillaSkinsOnly && !IsVanillaSkin(pName))
|
||||
|
@ -217,14 +217,11 @@ int CSkins::Find(const char *pName) const
|
|||
return FindImpl(pName);
|
||||
}
|
||||
|
||||
int CSkins::FindImpl(const char *pName) const
|
||||
int CSkins::FindImpl(const char *pName)
|
||||
{
|
||||
for(int i = 0; i < m_aSkins.size(); i++)
|
||||
{
|
||||
if(str_comp(m_aSkins[i].m_aName, pName) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
auto r = ::find_binary(m_aSkins.all(), pName);
|
||||
if(r.empty())
|
||||
return -1;
|
||||
|
||||
return &r.front() - m_aSkins.base_ptr();
|
||||
}
|
||||
|
|
|
@ -20,19 +20,22 @@ public:
|
|||
ColorRGBA m_BloodColor;
|
||||
|
||||
bool operator<(const CSkin &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); }
|
||||
};
|
||||
|
||||
void OnInit();
|
||||
|
||||
int Num();
|
||||
const CSkin *Get(int Index);
|
||||
int Find(const char *pName) const;
|
||||
int Find(const char *pName);
|
||||
|
||||
private:
|
||||
sorted_array<CSkin> m_aSkins;
|
||||
char m_EventSkinPrefix[100];
|
||||
|
||||
int FindImpl(const char *pName) const;
|
||||
int FindImpl(const char *pName);
|
||||
static int SkinScan(const char *pName, int IsDir, int DirType, void *pUser);
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue