Add readability-container-size-empty

This commit is contained in:
def 2022-01-22 13:54:25 +01:00
parent bcb50c1b29
commit 7aac8b5386
13 changed files with 23 additions and 22 deletions

View file

@ -40,6 +40,7 @@ Checks: >
readability-const-return-type, readability-const-return-type,
readability-container-data-pointer, readability-container-data-pointer,
readability-qualified-auto, readability-qualified-auto,
readability-container-size-empty,
readability-delete-null-pointer, readability-delete-null-pointer,
performance-*, performance-*,
-performance-no-int-to-ptr, -performance-no-int-to-ptr,

View file

@ -2706,7 +2706,7 @@ void CClient::Update()
if(State() == IClient::STATE_ONLINE) if(State() == IClient::STATE_ONLINE)
{ {
if(m_EditJobs.size() > 0) if(!m_EditJobs.empty())
{ {
std::shared_ptr<CDemoEdit> e = m_EditJobs.front(); std::shared_ptr<CDemoEdit> e = m_EditJobs.front();
if(e->Status() == IJob::STATE_DONE) if(e->Status() == IJob::STATE_DONE)

View file

@ -1275,7 +1275,7 @@ void CGraphics_Threaded::QuadContainerUpload(int ContainerIndex)
if(IsQuadContainerBufferingEnabled()) if(IsQuadContainerBufferingEnabled())
{ {
SQuadContainer &Container = m_QuadContainers[ContainerIndex]; SQuadContainer &Container = m_QuadContainers[ContainerIndex];
if(Container.m_Quads.size() > 0) if(!Container.m_Quads.empty())
{ {
if(Container.m_QuadBufferObjectIndex == -1) if(Container.m_QuadBufferObjectIndex == -1)
{ {

View file

@ -977,7 +977,7 @@ public:
AppendTextContainer(pCursor, ContainerIndex, pText, Length); AppendTextContainer(pCursor, ContainerIndex, pText, Length);
if(TextContainer.m_StringInfo.m_CharacterQuads.size() == 0 && TextContainer.m_StringInfo.m_SelectionQuadContainerIndex == -1 && IsRendered) if(TextContainer.m_StringInfo.m_CharacterQuads.empty() && TextContainer.m_StringInfo.m_SelectionQuadContainerIndex == -1 && IsRendered)
{ {
FreeTextContainer(ContainerIndex); FreeTextContainer(ContainerIndex);
return -1; return -1;
@ -1402,7 +1402,7 @@ public:
GotNewLineLast = 0; GotNewLineLast = 0;
} }
if(TextContainer.m_StringInfo.m_CharacterQuads.size() != 0 && IsRendered) if(!TextContainer.m_StringInfo.m_CharacterQuads.empty() && IsRendered)
{ {
TextContainer.m_StringInfo.m_QuadNum = TextContainer.m_StringInfo.m_CharacterQuads.size(); TextContainer.m_StringInfo.m_QuadNum = TextContainer.m_StringInfo.m_CharacterQuads.size();
// setup the buffers // setup the buffers

View file

@ -394,7 +394,7 @@ void mem_copy_special(void *pDest, void *pSource, size_t Size, size_t Count, siz
CMapLayers::~CMapLayers() CMapLayers::~CMapLayers()
{ {
//clear everything and destroy all buffers //clear everything and destroy all buffers
if(m_TileLayerVisuals.size() != 0) if(!m_TileLayerVisuals.empty())
{ {
int s = m_TileLayerVisuals.size(); int s = m_TileLayerVisuals.size();
for(int i = 0; i < s; ++i) for(int i = 0; i < s; ++i)
@ -402,7 +402,7 @@ CMapLayers::~CMapLayers()
delete m_TileLayerVisuals[i]; delete m_TileLayerVisuals[i];
} }
} }
if(m_QuadLayerVisuals.size() != 0) if(!m_QuadLayerVisuals.empty())
{ {
int s = m_QuadLayerVisuals.size(); int s = m_QuadLayerVisuals.size();
for(int i = 0; i < s; ++i) for(int i = 0; i < s; ++i)
@ -417,7 +417,7 @@ void CMapLayers::OnMapLoad()
if(!Graphics()->IsTileBufferingEnabled() && !Graphics()->IsQuadBufferingEnabled()) if(!Graphics()->IsTileBufferingEnabled() && !Graphics()->IsQuadBufferingEnabled())
return; return;
//clear everything and destroy all buffers //clear everything and destroy all buffers
if(m_TileLayerVisuals.size() != 0) if(!m_TileLayerVisuals.empty())
{ {
int s = m_TileLayerVisuals.size(); int s = m_TileLayerVisuals.size();
for(int i = 0; i < s; ++i) for(int i = 0; i < s; ++i)
@ -427,7 +427,7 @@ void CMapLayers::OnMapLoad()
} }
m_TileLayerVisuals.clear(); m_TileLayerVisuals.clear();
} }
if(m_QuadLayerVisuals.size() != 0) if(!m_QuadLayerVisuals.empty())
{ {
int s = m_QuadLayerVisuals.size(); int s = m_QuadLayerVisuals.size();
for(int i = 0; i < s; ++i) for(int i = 0; i < s; ++i)
@ -823,8 +823,8 @@ void CMapLayers::OnMapLoad()
tmpTileTexCoords.insert(tmpTileTexCoords.end(), tmpBorderRightTilesTexCoords.begin(), tmpBorderRightTilesTexCoords.end()); tmpTileTexCoords.insert(tmpTileTexCoords.end(), tmpBorderRightTilesTexCoords.begin(), tmpBorderRightTilesTexCoords.end());
//setup params //setup params
float *pTmpTiles = (tmpTiles.size() == 0) ? NULL : (float *)&tmpTiles[0]; float *pTmpTiles = (tmpTiles.empty()) ? NULL : (float *)&tmpTiles[0];
unsigned char *pTmpTileTexCoords = (tmpTileTexCoords.size() == 0) ? NULL : (unsigned char *)&tmpTileTexCoords[0]; unsigned char *pTmpTileTexCoords = (tmpTileTexCoords.empty()) ? NULL : (unsigned char *)&tmpTileTexCoords[0];
Visuals.m_BufferContainerIndex = -1; Visuals.m_BufferContainerIndex = -1;
size_t UploadDataSize = tmpTileTexCoords.size() * sizeof(SGraphicTileTexureCoords) + tmpTiles.size() * sizeof(SGraphicTile); size_t UploadDataSize = tmpTileTexCoords.size() * sizeof(SGraphicTileTexureCoords) + tmpTiles.size() * sizeof(SGraphicTile);

View file

@ -389,7 +389,7 @@ void CMenuBackground::ChangePosition(int PositionNumber)
std::vector<CTheme> &CMenuBackground::GetThemes() std::vector<CTheme> &CMenuBackground::GetThemes()
{ {
if(m_lThemes.size() == 0) // not loaded yet if(m_lThemes.empty()) // not loaded yet
{ {
// when adding more here, make sure to change the value of PREDEFINED_THEMES_COUNT too // when adding more here, make sure to change the value of PREDEFINED_THEMES_COUNT too
m_lThemes.push_back(CTheme("", true, true)); // no theme m_lThemes.push_back(CTheme("", true, true)); // no theme

View file

@ -17,7 +17,7 @@ void CUIElement::Init(CUI *pUI, int RequestedRectCount)
void CUIElement::InitRects(int RequestedRectCount) void CUIElement::InitRects(int RequestedRectCount)
{ {
dbg_assert(m_UIRects.size() == 0, "UI rects can only be initialized once, create another ui element instead."); dbg_assert(m_UIRects.empty(), "UI rects can only be initialized once, create another ui element instead.");
m_UIRects.resize(RequestedRectCount); m_UIRects.resize(RequestedRectCount);
} }

View file

@ -171,7 +171,7 @@ public:
bool AreRectsInit() bool AreRectsInit()
{ {
return m_UIRects.size() != 0; return !m_UIRects.empty();
} }
void InitRects(int RequestedRectCount); void InitRects(int RequestedRectCount);

View file

@ -299,7 +299,7 @@ void CCharacterCore::Tick(bool UseInput)
m_HookState = HOOK_RETRACT_START; m_HookState = HOOK_RETRACT_START;
} }
if(GoingThroughTele && m_pWorld && m_pTeleOuts && m_pTeleOuts->size() && (*m_pTeleOuts)[teleNr - 1].size()) if(GoingThroughTele && m_pWorld && m_pTeleOuts && !m_pTeleOuts->empty() && !(*m_pTeleOuts)[teleNr - 1].empty())
{ {
m_TriggeredEvents = 0; m_TriggeredEvents = 0;
m_HookedPlayer = -1; m_HookedPlayer = -1;

View file

@ -283,7 +283,7 @@ void CGameContext::ConToTeleporter(IConsole::IResult *pResult, void *pUserData)
unsigned int TeleTo = pResult->GetInteger(0); unsigned int TeleTo = pResult->GetInteger(0);
CGameControllerDDRace *pGameControllerDDRace = (CGameControllerDDRace *)pSelf->m_pController; CGameControllerDDRace *pGameControllerDDRace = (CGameControllerDDRace *)pSelf->m_pController;
if(pGameControllerDDRace->m_TeleOuts[TeleTo - 1].size()) if(!pGameControllerDDRace->m_TeleOuts[TeleTo - 1].empty())
{ {
CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientID); CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientID);
if(pChr) if(pChr)
@ -304,7 +304,7 @@ void CGameContext::ConToCheckTeleporter(IConsole::IResult *pResult, void *pUserD
unsigned int TeleTo = pResult->GetInteger(0); unsigned int TeleTo = pResult->GetInteger(0);
CGameControllerDDRace *pGameControllerDDRace = (CGameControllerDDRace *)pSelf->m_pController; CGameControllerDDRace *pGameControllerDDRace = (CGameControllerDDRace *)pSelf->m_pController;
if(pGameControllerDDRace->m_TeleCheckOuts[TeleTo - 1].size()) if(!pGameControllerDDRace->m_TeleCheckOuts[TeleTo - 1].empty())
{ {
CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientID); CCharacter *pChr = pSelf->GetPlayerChar(pResult->m_ClientID);
if(pChr) if(pChr)

View file

@ -1901,7 +1901,7 @@ void CCharacter::HandleTiles(int Index)
} }
int z = GameServer()->Collision()->IsTeleport(MapIndex); int z = GameServer()->Collision()->IsTeleport(MapIndex);
if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons && z && (*m_pTeleOuts)[z - 1].size()) if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons && z && !(*m_pTeleOuts)[z - 1].empty())
{ {
if(m_Super) if(m_Super)
return; return;
@ -1916,7 +1916,7 @@ void CCharacter::HandleTiles(int Index)
return; return;
} }
int evilz = GameServer()->Collision()->IsEvilTeleport(MapIndex); int evilz = GameServer()->Collision()->IsEvilTeleport(MapIndex);
if(evilz && (*m_pTeleOuts)[evilz - 1].size()) if(evilz && !(*m_pTeleOuts)[evilz - 1].empty())
{ {
if(m_Super) if(m_Super)
return; return;
@ -1945,7 +1945,7 @@ void CCharacter::HandleTiles(int Index)
// first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints // first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints
for(int k = m_TeleCheckpoint - 1; k >= 0; k--) for(int k = m_TeleCheckpoint - 1; k >= 0; k--)
{ {
if((*m_pTeleCheckOuts)[k].size()) if(!(*m_pTeleCheckOuts)[k].empty())
{ {
int TeleOut = m_Core.m_pWorld->RandomOr0((*m_pTeleCheckOuts)[k].size()); int TeleOut = m_Core.m_pWorld->RandomOr0((*m_pTeleCheckOuts)[k].size());
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut]; m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut];
@ -1982,7 +1982,7 @@ void CCharacter::HandleTiles(int Index)
// first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints // first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints
for(int k = m_TeleCheckpoint - 1; k >= 0; k--) for(int k = m_TeleCheckpoint - 1; k >= 0; k--)
{ {
if((*m_pTeleCheckOuts)[k].size()) if(!(*m_pTeleCheckOuts)[k].empty())
{ {
int TeleOut = m_Core.m_pWorld->RandomOr0((*m_pTeleCheckOuts)[k].size()); int TeleOut = m_Core.m_pWorld->RandomOr0((*m_pTeleCheckOuts)[k].size());
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut]; m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut];

View file

@ -129,7 +129,7 @@ void CLaser::DoBounce()
m_Energy -= distance(m_From, m_Pos) + GameServer()->TuningList()[m_TuneZone].m_LaserBounceCost; m_Energy -= distance(m_From, m_Pos) + GameServer()->TuningList()[m_TuneZone].m_LaserBounceCost;
CGameControllerDDRace *pControllerDDRace = (CGameControllerDDRace *)GameServer()->m_pController; CGameControllerDDRace *pControllerDDRace = (CGameControllerDDRace *)GameServer()->m_pController;
if(Res == TILE_TELEINWEAPON && pControllerDDRace->m_TeleOuts[z - 1].size()) if(Res == TILE_TELEINWEAPON && !pControllerDDRace->m_TeleOuts[z - 1].empty())
{ {
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(pControllerDDRace->m_TeleOuts[z - 1].size()); int TeleOut = GameServer()->m_World.m_Core.RandomOr0(pControllerDDRace->m_TeleOuts[z - 1].size());
m_TelePos = pControllerDDRace->m_TeleOuts[z - 1][TeleOut]; m_TelePos = pControllerDDRace->m_TeleOuts[z - 1][TeleOut];

View file

@ -273,7 +273,7 @@ void CProjectile::Tick()
else else
z = GameServer()->Collision()->IsTeleportWeapon(x); z = GameServer()->Collision()->IsTeleportWeapon(x);
CGameControllerDDRace *pControllerDDRace = (CGameControllerDDRace *)GameServer()->m_pController; CGameControllerDDRace *pControllerDDRace = (CGameControllerDDRace *)GameServer()->m_pController;
if(z && pControllerDDRace->m_TeleOuts[z - 1].size()) if(z && !pControllerDDRace->m_TeleOuts[z - 1].empty())
{ {
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(pControllerDDRace->m_TeleOuts[z - 1].size()); int TeleOut = GameServer()->m_World.m_Core.RandomOr0(pControllerDDRace->m_TeleOuts[z - 1].size());
m_Pos = pControllerDDRace->m_TeleOuts[z - 1][TeleOut]; m_Pos = pControllerDDRace->m_TeleOuts[z - 1][TeleOut];