summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-08-17 16:34:36 +0300
committerAndrei Karas <akaras@inbox.ru>2012-08-17 16:34:36 +0300
commitc6c4eef4e49bb4de90845408af9f642a1a4e224b (patch)
tree81d192e85b3c075cb2e52671bea4c3c0499dc3f2 /src
parent093e392dd84c920d26bca17d48ac6611393d087c (diff)
downloadManaVerse-c6c4eef4e49bb4de90845408af9f642a1a4e224b.tar.gz
ManaVerse-c6c4eef4e49bb4de90845408af9f642a1a4e224b.tar.bz2
ManaVerse-c6c4eef4e49bb4de90845408af9f642a1a4e224b.tar.xz
ManaVerse-c6c4eef4e49bb4de90845408af9f642a1a4e224b.zip
Improve size calculations.
Diffstat (limited to 'src')
-rw-r--r--src/chatlogger.cpp7
-rw-r--r--src/gui/charcreatedialog.cpp8
-rw-r--r--src/gui/charselectdialog.cpp6
-rw-r--r--src/gui/didyouknowwindow.cpp2
-rw-r--r--src/gui/helpwindow.cpp2
-rw-r--r--src/gui/ministatuswindow.cpp4
-rw-r--r--src/gui/outfitwindow.cpp18
-rw-r--r--src/gui/palette.cpp2
-rw-r--r--src/gui/serverdialog.cpp6
-rw-r--r--src/gui/setup_relations.cpp10
-rw-r--r--src/gui/updaterwindow.cpp11
-rw-r--r--src/gui/whoisonline.cpp8
-rw-r--r--src/gui/widgets/browserbox.cpp9
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp7
-rw-r--r--src/gui/widgets/itemcontainer.cpp2
-rw-r--r--src/gui/widgets/layout.cpp8
-rw-r--r--src/gui/widgets/progressindicator.cpp2
-rw-r--r--src/gui/widgets/tabbedarea.cpp7
-rw-r--r--src/gui/widgets/tablemodel.cpp2
-rw-r--r--src/gui/widgets/textbox.cpp5
-rw-r--r--src/gui/widgets/textfield.cpp4
-rw-r--r--src/guichan/defaultfont.cpp2
-rw-r--r--src/guichan/focushandler.cpp30
-rw-r--r--src/guichan/font.cpp2
-rw-r--r--src/guichan/widgets/tabbedarea.cpp11
-rw-r--r--src/guichan/widgets/textbox.cpp10
-rw-r--r--src/map.cpp5
-rw-r--r--src/utils/stringutils.cpp2
28 files changed, 105 insertions, 87 deletions
diff --git a/src/chatlogger.cpp b/src/chatlogger.cpp
index 4c4f2ce83..95cf15363 100644
--- a/src/chatlogger.cpp
+++ b/src/chatlogger.cpp
@@ -200,11 +200,16 @@ void ChatLogger::loadLast(std::string name, std::list<std::string> &list,
return;
char line[710];
+ unsigned sz = list.size();
while (logFile.getline(line, 700))
{
list.push_back(line);
- if (list.size() > n)
+ sz ++;
+ if (sz > n)
+ {
list.pop_front();
+ sz --;
+ }
}
if (logFile.is_open())
diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp
index 1ef29c93f..5c27b7440 100644
--- a/src/gui/charcreatedialog.cpp
+++ b/src/gui/charcreatedialog.cpp
@@ -268,7 +268,7 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
mCreateButton->setEnabled(false);
std::vector<int> atts;
- for (unsigned i = 0; i < mAttributeSlider.size(); i++)
+ for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++)
{
atts.push_back(static_cast<int>(
mAttributeSlider[i]->getValue()));
@@ -362,7 +362,7 @@ std::string CharCreateDialog::getName() const
void CharCreateDialog::updateSliders()
{
- for (unsigned i = 0; i < mAttributeSlider.size(); i++)
+ for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++)
{
// Update captions
mAttributeValue[i]->setCaption(
@@ -404,7 +404,7 @@ int CharCreateDialog::getDistributedPoints() const
{
int points = 0;
- for (unsigned i = 0; i < mAttributeSlider.size(); i++)
+ for (size_t i = 0, sz = mAttributeSlider.size(); i < sz; i++)
points += static_cast<int>(mAttributeSlider[i]->getValue());
return points;
}
@@ -434,7 +434,7 @@ void CharCreateDialog::setAttributes(const StringVect &labels,
int w = 480;
int h = 350;
- for (unsigned i = 0; i < labels.size(); i++)
+ for (unsigned i = 0, sz = labels.size(); i < sz; i++)
{
mAttributeLabel[i] = new Label(labels[i]);
mAttributeLabel[i]->setWidth(70);
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index e0ae9e85f..77c8ea55d 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -211,7 +211,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
// Check if a button of a character was pressed
const gcn::Widget *sourceParent = event.getSource()->getParent();
int selected = -1;
- for (int i = 0; i < static_cast<int>(mCharacterEntries.size()); ++i)
+ for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i)
{
if (mCharacterEntries[i] == sourceParent)
{
@@ -515,7 +515,7 @@ void CharSelectDialog::setLocked(bool locked)
if (mChangeEmailButton)
mChangeEmailButton->setEnabled(!locked);
- for (int i = 0; i < static_cast<int>(mCharacterEntries.size()); ++i)
+ for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i)
{
if (mCharacterEntries[i])
mCharacterEntries[i]->setActive(!mLocked);
@@ -528,7 +528,7 @@ bool CharSelectDialog::selectByName(const std::string &name,
if (mLocked)
return false;
- for (int i = 0; i < static_cast<int>(mCharacterEntries.size()); ++i)
+ for (size_t i = 0, sz = mCharacterEntries.size(); i < sz; ++i)
{
if (mCharacterEntries[i])
{
diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp
index d7c44ebaa..003395d3b 100644
--- a/src/gui/didyouknowwindow.cpp
+++ b/src/gui/didyouknowwindow.cpp
@@ -136,7 +136,7 @@ void DidYouKnowWindow::loadFile(int num)
TranslationManager::translateFile(helpPath + file + ".txt",
translator, lines);
- for (unsigned int i = 0; i < lines.size(); ++i)
+ for (size_t i = 0, sz = lines.size(); i < sz; ++i)
mBrowserBox->addRow(lines[i]);
}
diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp
index 151e8bb63..66e357d31 100644
--- a/src/gui/helpwindow.cpp
+++ b/src/gui/helpwindow.cpp
@@ -121,7 +121,7 @@ void HelpWindow::loadFile(const std::string &file)
TranslationManager::translateFile(helpPath + file + ".txt",
translator, lines);
- for (unsigned int i = 0; i < lines.size(); ++i)
+ for (size_t i = 0, sz = lines.size(); i < sz; ++i)
mBrowserBox->addRow(lines[i]);
}
diff --git a/src/gui/ministatuswindow.cpp b/src/gui/ministatuswindow.cpp
index 72064c335..c32aaa742 100644
--- a/src/gui/ministatuswindow.cpp
+++ b/src/gui/ministatuswindow.cpp
@@ -212,7 +212,7 @@ void MiniStatusWindow::drawIcons(Graphics *graphics)
{
// Draw icons
int icon_x = mStatusBar->getX() + mStatusBar->getWidth() + 4;
- for (unsigned int i = 0; i < mIcons.size(); i++)
+ for (size_t i = 0, sz = mIcons.size(); i < sz; i ++)
{
if (mIcons[i])
{
@@ -268,7 +268,7 @@ void MiniStatusWindow::logic()
{
Popup::logic();
- for (unsigned int i = 0; i < mIcons.size(); i++)
+ for (size_t i = 0, sz = mIcons.size(); i < sz; i++)
{
if (mIcons[i])
mIcons[i]->update(tick_time * 10);
diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp
index fafb69896..2127bc6cf 100644
--- a/src/gui/outfitwindow.cpp
+++ b/src/gui/outfitwindow.cpp
@@ -149,13 +149,12 @@ void OutfitWindow::load(bool oldConfig)
while (ss >> buf)
tokens.push_back(atoi(buf.c_str()));
- for (int i = 0; i < static_cast<int>(tokens.size())
- && i < OUTFIT_ITEM_COUNT; i++)
+ for (size_t i = 0, sz = tokens.size();
+ i < sz && i < OUTFIT_ITEM_COUNT; i++)
{
mItems[o][i] = tokens[i];
}
-
outfit = cfg->getValue("OutfitColor" + toString(o), "1");
std::stringstream ss2(outfit);
@@ -165,8 +164,8 @@ void OutfitWindow::load(bool oldConfig)
while (ss2 >> buf)
tokens2.push_back(static_cast<unsigned char>(atoi(buf.c_str())));
- for (int i = 0; i < static_cast<int>(tokens2.size())
- && i < OUTFIT_ITEM_COUNT; i++)
+ for (size_t i = 0, sz = tokens2.size();
+ i < sz && i < OUTFIT_ITEM_COUNT; i++)
{
mItemColors[o][i] = tokens2[i];
}
@@ -497,19 +496,20 @@ void OutfitWindow::unequipNotInOutfit(int outfit)
for (unsigned i = 0; i < inventory->getSize(); i++)
{
- if (inventory->getItem(i) && inventory->getItem(i)->isEquipped())
+ Item *item = inventory->getItem(i);
+ if (item && item->isEquipped())
{
bool found = false;
for (unsigned f = 0; f < OUTFIT_ITEM_COUNT; f++)
{
- if (inventory->getItem(i)->getId() == mItems[outfit][f])
+ if (item->getId() == mItems[outfit][f])
{
found = true;
break;
}
}
if (!found)
- Net::getInventoryHandler()->unequipItem(inventory->getItem(i));
+ Net::getInventoryHandler()->unequipItem(item);
}
}
}
@@ -603,7 +603,7 @@ void OutfitWindow::copyFromEquiped(int dst)
int outfitCell = 0;
- for (unsigned i = 0; i < inventory->getSize(); i++)
+ for (unsigned i = 0, sz = inventory->getSize(); i < sz; i++)
{
const Item *item = inventory->getItem(i);
if (item && item->isEquipped())
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
index a31346b87..523497044 100644
--- a/src/gui/palette.cpp
+++ b/src/gui/palette.cpp
@@ -98,7 +98,7 @@ void Palette::advanceGradient()
int advance = get_elapsed_time(mRainbowTime) / 5;
double startColVal, destColVal;
- for (size_t i = 0; i < mGradVector.size(); i++)
+ for (size_t i = 0, sz = mGradVector.size(); i < sz; i++)
{
if (!mGradVector[i])
continue;
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 80e793cd2..28e0c43e6 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -636,7 +636,7 @@ void ServerDialog::loadServers(bool addNew)
MutexLocker tempLock(&mMutex);
// Add the server to the local list if it's not already present
bool found = false;
- for (unsigned int i = 0; i < mServers.size(); i++)
+ for (unsigned int i = 0, sz = mServers.size(); i < sz; i++)
{
if (mServers[i] == server)
{
@@ -713,8 +713,8 @@ void ServerDialog::saveCustomServers(const ServerInfo &currentServer,
int savedServerCount = 0;
- for (unsigned i = 0;
- i < mServers.size() && savedServerCount < MAX_SERVERLIST; ++i)
+ for (unsigned i = 0, sz = mServers.size();
+ i < sz && savedServerCount < MAX_SERVERLIST; ++ i)
{
const ServerInfo &server = mServers.at(i);
diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp
index d40995ac2..20ef3b3d4 100644
--- a/src/gui/setup_relations.cpp
+++ b/src/gui/setup_relations.cpp
@@ -152,7 +152,7 @@ public:
mPlayers = player_names;
// set up widgets
- for (unsigned int r = 0; r < player_names->size(); ++r)
+ for (unsigned int r = 0, sz = player_names->size(); r < sz; ++r)
{
std::string name = (*player_names)[r];
gcn::Widget *widget = new Label(name);
@@ -316,9 +316,9 @@ void Setup_Relations::reset()
// current selection. We could use an index into the table of config
// options in player_relations instead of strategies to sidestep this.
int selection = 0;
- for (unsigned int i = 0;
- i < player_relations.getPlayerIgnoreStrategies()->size();
- ++i)
+ for (size_t i = 0, sz = player_relations.getPlayerIgnoreStrategies()
+ ->size(); i < sz; ++ i)
+ {
if ((*player_relations.getPlayerIgnoreStrategies())[i] ==
player_relations.getPlayerIgnoreStrategy())
{
@@ -326,7 +326,7 @@ void Setup_Relations::reset()
selection = i;
break;
}
-
+ }
mIgnoreActionChoicesBox->setSelected(selection);
}
diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp
index eef8ca306..71aec58a0 100644
--- a/src/gui/updaterwindow.cpp
+++ b/src/gui/updaterwindow.cpp
@@ -527,7 +527,8 @@ void UpdaterWindow::loadUpdates()
}
std::string fixPath = mUpdatesDir + "/fix";
- for (mUpdateIndex = 0; mUpdateIndex < mUpdateFiles.size(); mUpdateIndex++)
+ const unsigned sz = mUpdateFiles.size();
+ for (mUpdateIndex = 0; mUpdateIndex < sz; mUpdateIndex++)
{
UpdaterWindow::addUpdateFile(resman, mUpdatesDir, fixPath,
mUpdateFiles[mUpdateIndex].name, false);
@@ -551,8 +552,8 @@ void UpdaterWindow::loadLocalUpdates(std::string dir)
}
std::string fixPath = dir + "/fix";
- for (unsigned int updateIndex = 0;
- updateIndex < updateFiles.size(); updateIndex++)
+ for (unsigned int updateIndex = 0, sz = updateFiles.size();
+ updateIndex < sz; updateIndex ++)
{
UpdaterWindow::addUpdateFile(resman, dir, fixPath,
updateFiles[updateIndex].name, false);
@@ -567,8 +568,8 @@ void UpdaterWindow::loadManaPlusUpdates(std::string dir,
std::vector<updateFile> updateFiles
= loadXMLFile(fixPath + "/" + xmlUpdateFile);
- for (unsigned int updateIndex = 0;
- updateIndex < updateFiles.size(); updateIndex ++)
+ for (unsigned int updateIndex = 0, sz = updateFiles.size();
+ updateIndex < sz; updateIndex ++)
{
std::string name = updateFiles[updateIndex].name;
if (strStartWith(name, "manaplus_"))
diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp
index 8c2bfa6c9..911c26c3e 100644
--- a/src/gui/whoisonline.cpp
+++ b/src/gui/whoisonline.cpp
@@ -200,7 +200,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends,
sort(neutral.begin(), neutral.end(), nameCompare);
sort(disregard.begin(), disregard.end(), nameCompare);
bool addedFromSection(false);
- for (int i = 0; i < static_cast<int>(friends.size()); i++)
+ for (size_t i = 0, sz = friends.size(); i < sz; i++)
{
mBrowserBox->addRow(friends.at(i)->getText());
addedFromSection = true;
@@ -210,7 +210,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends,
mBrowserBox->addRow("---");
addedFromSection = false;
}
- for (int i = 0; i < static_cast<int>(enemy.size()); i++)
+ for (size_t i = 0, sz = enemy.size(); i < sz; i++)
{
mBrowserBox->addRow(enemy.at(i)->getText());
addedFromSection = true;
@@ -220,7 +220,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends,
mBrowserBox->addRow("---");
addedFromSection = false;
}
- for (int i = 0; i < static_cast<int>(neutral.size()); i++)
+ for (size_t i = 0, sz = neutral.size(); i < sz; i++)
{
mBrowserBox->addRow(neutral.at(i)->getText());
addedFromSection = true;
@@ -230,7 +230,7 @@ void WhoIsOnline::updateWindow(std::vector<OnlinePlayer*> &friends,
mBrowserBox->addRow("---");
// addedFromSection = false;
}
- for (int i = 0; i < static_cast<int>(disregard.size()); i++)
+ for (size_t i = 0, sz = disregard.size(); i < sz; i++)
mBrowserBox->addRow(disregard.at(i)->getText());
if (mScrollArea->getVerticalMaxScroll() <
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 534bd1d19..cf2a9ea88 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -120,6 +120,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
// Check for links in format "@@link|Caption@@"
idx1 = tmp.find("@@");
+ const int sz = static_cast<int>(mTextRows.size());
while (idx1 != std::string::npos)
{
size_t idx2 = tmp.find("|", idx1);
@@ -129,7 +130,7 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
break;
bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
- bLink.y1 = static_cast<int>(mTextRows.size()) * font->getHeight();
+ bLink.y1 = sz * font->getHeight();
bLink.y2 = bLink.y1 + font->getHeight();
newRow += tmp.substr(0, idx1);
@@ -224,19 +225,19 @@ void BrowserBox::addRow(const std::string &row, bool atTop)
i != i_end; ++ i)
{
std::string tempRow = *i;
- for (unsigned int j = 0; j < tempRow.size(); j++)
+ for (unsigned int j = 0, sz = tempRow.size(); j < sz; j++)
{
std::string character = tempRow.substr(j, 1);
x += font->getWidth(character);
nextChar = j + 1;
// Wraping between words (at blank spaces)
- if (nextChar < tempRow.size() && tempRow.at(nextChar) == ' ')
+ if (nextChar < sz && tempRow.at(nextChar) == ' ')
{
int nextSpacePos = static_cast<int>(
tempRow.find(" ", (nextChar + 1)));
if (nextSpacePos <= 0)
- nextSpacePos = static_cast<int>(tempRow.size()) - 1;
+ nextSpacePos = static_cast<int>(sz) - 1;
unsigned nextWordWidth = font->getWidth(
tempRow.substr(nextChar,
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index 17d825909..2347edd0c 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -131,17 +131,18 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
graphics->setColor(getForegroundColor());
g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT);
}
+ unsigned sz = mEmoteImg.size();
for (unsigned i = 0; i < mMaxItems; i++)
{
- if (i < mEmoteImg.size() && mEmoteImg[i] && mEmoteImg[i]->sprite)
+ if (i < sz && mEmoteImg[i] && mEmoteImg[i]->sprite)
{
mEmoteImg[i]->sprite->draw(g, (i % mGridWidth) * mBoxWidth + 2,
(i / mGridWidth) * mBoxHeight + 10);
}
}
- if (mEmoteMoved && mEmoteMoved < static_cast<unsigned>(
- mEmoteImg.size()) + 1 && mEmoteMoved > 0)
+ if (mEmoteMoved && mEmoteMoved < static_cast<unsigned>(sz) + 1
+ && mEmoteMoved > 0)
{
// Draw the emote image being dragged by the cursor.
const EmoteSprite* sprite = mEmoteImg[mEmoteMoved - 1];
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index e315a336c..f16852673 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -551,7 +551,7 @@ void ItemContainer::updateMatrix()
mShowMatrix[idx] = -1;
}
- for (unsigned idx = 0; idx < sortedItems.size(); idx ++)
+ for (size_t idx = 0, sz = sortedItems.size(); idx < sz; idx ++)
delete sortedItems[idx];
}
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
index 990937e06..b7856da81 100644
--- a/src/gui/widgets/layout.cpp
+++ b/src/gui/widgets/layout.cpp
@@ -338,6 +338,8 @@ void LayoutArray::reflow(int nx, int ny, int nw, int nh)
std::vector<int> widths = getSizes(0, nw);
std::vector<int> heights = getSizes(1, nh);
+ const int szW = static_cast<int>(widths.size());
+ const int szH = static_cast<int>(heights.size());
int y = ny;
for (int gridY = 0; gridY < gridH; ++gridY)
{
@@ -348,10 +350,8 @@ void LayoutArray::reflow(int nx, int ny, int nw, int nh)
if (cell && cell->mType != LayoutCell::NONE)
{
int dx = x, dy = y, dw = 0, dh = 0;
- align(dx, dw, 0, *cell, &widths[gridX],
- static_cast<int>(widths.size() - gridX));
- align(dy, dh, 1, *cell, &heights[gridY],
- static_cast<int>(heights.size() - gridY));
+ align(dx, dw, 0, *cell, &widths[gridX], szW - gridX);
+ align(dy, dh, 1, *cell, &heights[gridY], szH - gridY);
cell->reflow(dx, dy, dw, dh);
}
x += widths[gridX] + mSpacing;
diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp
index 6adb5a2fa..681da7ae4 100644
--- a/src/gui/widgets/progressindicator.cpp
+++ b/src/gui/widgets/progressindicator.cpp
@@ -42,7 +42,7 @@ ProgressIndicator::ProgressIndicator()
Animation *anim = new Animation;
if (images)
{
- for (ImageSet::size_type i = 0; i < images->size(); ++i)
+ for (ImageSet::size_type i = 0, sz = images->size(); i < sz; ++i)
anim->addFrame(images->get(i), 100, 0, 0, 100);
mIndicator = new SimpleAnimation(anim);
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 96e81b534..43e829a4e 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -342,7 +342,7 @@ void TabbedArea::updateTabsWidth()
void TabbedArea::updateVisibleTabsWidth()
{
mVisibleTabsWidth = 0;
- for (unsigned int i = mTabScrollIndex; i < mTabs.size(); ++i)
+ for (size_t i = mTabScrollIndex, sz = mTabs.size(); i < sz; ++i)
{
if (mTabs[i].first)
mVisibleTabsWidth += mTabs[i].first->getWidth();
@@ -352,14 +352,15 @@ void TabbedArea::updateVisibleTabsWidth()
void TabbedArea::adjustTabPositions()
{
int maxTabHeight = 0;
- for (unsigned i = 0; i < mTabs.size(); ++i)
+ size_t sz = mTabs.size();
+ for (size_t i = 0; i < sz; ++i)
{
if (mTabs[i].first && mTabs[i].first->getHeight() > maxTabHeight)
maxTabHeight = mTabs[i].first->getHeight();
}
int x = mArrowButton[0]->isVisible() ? mArrowButton[0]->getWidth() : 0;
- for (unsigned i = mTabScrollIndex; i < mTabs.size(); ++i)
+ for (size_t i = mTabScrollIndex; i < sz; ++i)
{
gcn::Tab* tab = mTabs[i].first;
if (!tab)
diff --git a/src/gui/widgets/tablemodel.cpp b/src/gui/widgets/tablemodel.cpp
index bc5d2ead6..04f81fdd6 100644
--- a/src/gui/widgets/tablemodel.cpp
+++ b/src/gui/widgets/tablemodel.cpp
@@ -163,7 +163,7 @@ int StaticTableModel::getWidth() const
{
int width = 0;
- for (unsigned int i = 0; i < mWidths.size(); i++)
+ for (size_t i = 0, sz = mWidths.size(); i < sz; i++)
width += mWidths[i];
return width;
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index cd5b4bf99..048051bb9 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -191,9 +191,10 @@ void TextBox::keyPressed(gcn::KeyEvent& keyEvent)
{
++ mCaretRow;
- if (mCaretRow >= static_cast<int>(mTextRows.size()))
+ const int sz = static_cast<int>(mTextRows.size());
+ if (mCaretRow >= sz)
{
- mCaretRow = static_cast<int>(mTextRows.size()) - 1;
+ mCaretRow = sz - 1;
if (mCaretRow < 0)
mCaretRow = 0;
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index d5fb58cb9..79c48beac 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -241,7 +241,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
case 6: // Ctrl+f
{
- unsigned sz = static_cast<unsigned>(mText.size());
+ const unsigned sz = static_cast<unsigned>(mText.size());
while (mCaretPosition < sz)
{
++mCaretPosition;
@@ -356,7 +356,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
case Input::KEY_GUI_RIGHT:
{
consumed = true;
- unsigned sz = static_cast<unsigned>(mText.size());
+ const unsigned sz = static_cast<unsigned>(mText.size());
while (mCaretPosition < sz)
{
++mCaretPosition;
diff --git a/src/guichan/defaultfont.cpp b/src/guichan/defaultfont.cpp
index 8d0b23623..e6da87fcd 100644
--- a/src/guichan/defaultfont.cpp
+++ b/src/guichan/defaultfont.cpp
@@ -78,7 +78,7 @@ namespace gcn
void DefaultFont::drawString(Graphics* graphics, const std::string& text,
int x, int y)
{
- for (unsigned int i = 0; i< text.size(); ++i)
+ for (size_t i = 0, sz = text.size(); i < sz; ++i)
{
drawGlyph(graphics, text.at(i), x, y);
x += getWidth(text);
diff --git a/src/guichan/focushandler.cpp b/src/guichan/focushandler.cpp
index 494a2a899..3a5424851 100644
--- a/src/guichan/focushandler.cpp
+++ b/src/guichan/focushandler.cpp
@@ -74,7 +74,7 @@ namespace gcn
return;
int toBeFocusedIndex = -1;
- for (unsigned int i = 0; i < mWidgets.size(); ++i)
+ for (unsigned int i = 0, sz = mWidgets.size(); i < sz; ++i)
{
if (mWidgets[i] == widget)
{
@@ -157,7 +157,8 @@ namespace gcn
{
int i;
int focusedWidget = -1;
- for (i = 0; i < static_cast<int>(mWidgets.size()); ++i)
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++i)
{
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
@@ -166,7 +167,7 @@ namespace gcn
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
- i = static_cast<int>(mWidgets.size());
+ i = sz;
do
{
++ focusedWidget;
@@ -179,7 +180,7 @@ namespace gcn
-- i;
- if (focusedWidget >= static_cast<int>(mWidgets.size()))
+ if (focusedWidget >= sz)
focusedWidget = 0;
if (focusedWidget == focused)
@@ -212,7 +213,8 @@ namespace gcn
int i;
int focusedWidget = -1;
- for (i = 0; i < static_cast<int>(mWidgets.size()); ++ i)
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++ i)
{
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
@@ -221,7 +223,7 @@ namespace gcn
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
- i = static_cast<int>(mWidgets.size());
+ i = sz;
do
{
-- focusedWidget;
@@ -235,7 +237,7 @@ namespace gcn
-- i;
if (focusedWidget <= 0)
- focusedWidget = static_cast<int>(mWidgets.size() - 1);
+ focusedWidget = sz - 1;
if (focusedWidget == focused)
return;
@@ -340,7 +342,8 @@ namespace gcn
int i;
int focusedWidget = -1;
- for (i = 0; i < static_cast<int>(mWidgets.size()); ++ i)
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++ i)
{
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
@@ -350,7 +353,7 @@ namespace gcn
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
- i = static_cast<int>(mWidgets.size());
+ i = sz;
do
{
++ focusedWidget;
@@ -363,7 +366,7 @@ namespace gcn
-- i;
- if (focusedWidget >= static_cast<int>(mWidgets.size()))
+ if (focusedWidget >= sz)
focusedWidget = 0;
if (focusedWidget == focused)
@@ -408,7 +411,8 @@ namespace gcn
int i;
int focusedWidget = -1;
- for (i = 0; i < static_cast<int>(mWidgets.size()); ++ i)
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++ i)
{
if (mWidgets[i] == mFocusedWidget)
focusedWidget = i;
@@ -418,7 +422,7 @@ namespace gcn
// i is a counter that ensures that the following loop
// won't get stuck in an infinite loop
- i = static_cast<int>(mWidgets.size());
+ i = sz;
do
{
-- focusedWidget;
@@ -432,7 +436,7 @@ namespace gcn
-- i;
if (focusedWidget <= 0)
- focusedWidget = static_cast<int>(mWidgets.size() - 1);
+ focusedWidget = sz - 1;
if (focusedWidget == focused)
return;
diff --git a/src/guichan/font.cpp b/src/guichan/font.cpp
index 6fec94121..ea4652814 100644
--- a/src/guichan/font.cpp
+++ b/src/guichan/font.cpp
@@ -56,7 +56,7 @@ namespace gcn
{
int Font::getStringIndexAt(const std::string& text, int x) const
{
- for (unsigned int i = 0; i < text.size(); ++i)
+ for (unsigned int i = 0, sz = text.size(); i < sz; ++i)
{
if (getWidth(text.substr(0, i)) > x)
return i;
diff --git a/src/guichan/widgets/tabbedarea.cpp b/src/guichan/widgets/tabbedarea.cpp
index a4179db5e..487549b6a 100644
--- a/src/guichan/widgets/tabbedarea.cpp
+++ b/src/guichan/widgets/tabbedarea.cpp
@@ -88,7 +88,7 @@ namespace gcn
delete mWidgetContainer;
mWidgetContainer = nullptr;
- for (unsigned int i = 0; i < mTabsToDelete.size(); i++)
+ for (size_t i = 0, sz = mTabsToDelete.size(); i < sz; i++)
{
delete mTabsToDelete[i];
mTabsToDelete[i] = nullptr;
@@ -160,7 +160,7 @@ namespace gcn
int TabbedArea::getSelectedTabIndex() const
{
- for (unsigned int i = 0; i < mTabs.size(); i++)
+ for (unsigned int i = 0, sz = mTabs.size(); i < sz; i++)
{
if (mTabs[i].first == mSelectedTab)
return i;
@@ -241,7 +241,7 @@ namespace gcn
{
int maxTabHeight = 0;
- for (unsigned int i = 0; i < mTabs.size(); i++)
+ for (size_t i = 0, sz = mTabs.size(); i < sz; i++)
{
if (mTabs[i].first->getHeight() > maxTabHeight)
maxTabHeight = mTabs[i].first->getHeight();
@@ -258,14 +258,15 @@ namespace gcn
{
int maxTabHeight = 0;
unsigned int i;
- for (i = 0; i < mTabs.size(); i++)
+ const unsigned int sz = mTabs.size();
+ for (i = 0; i < sz; i++)
{
if (mTabs[i].first->getHeight() > maxTabHeight)
maxTabHeight = mTabs[i].first->getHeight();
}
int x = 0;
- for (i = 0; i < mTabs.size(); i++)
+ for (i = 0; i < sz; i++)
{
Tab* tab = mTabs[i].first;
tab->setPosition(x, maxTabHeight - tab->getHeight());
diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp
index 6b03a1cb5..97256eb44 100644
--- a/src/guichan/widgets/textbox.cpp
+++ b/src/guichan/widgets/textbox.cpp
@@ -130,7 +130,7 @@ namespace gcn
graphics->setColor(getForegroundColor());
graphics->setFont(getFont());
- for (size_t i = 0; i < mTextRows.size(); i++)
+ for (size_t i = 0, sz = mTextRows.size(); i < sz; i++)
{
// Move the text one pixel so we can have a caret before a letter.
graphics->drawText(mTextRows[i], 1,
@@ -170,7 +170,7 @@ namespace gcn
void TextBox::adjustSize()
{
int width = 0;
- for (size_t i = 0; i < mTextRows.size(); ++i)
+ for (size_t i = 0, sz = mTextRows.size(); i < sz; ++i)
{
int w = getFont()->getWidth(mTextRows[i]);
if (width < w)
@@ -183,7 +183,8 @@ namespace gcn
void TextBox::setCaretPosition(unsigned int position)
{
- for (int row = 0; row < static_cast<int>(mTextRows.size()); row ++)
+ for (int row = 0, sz = static_cast<int>(mTextRows.size());
+ row < sz; row ++)
{
if (position <= mTextRows[row].size())
{
@@ -280,7 +281,8 @@ namespace gcn
int i;
std::string text;
- for (i = 0; i < static_cast<int>(mTextRows.size()) - 1; ++ i)
+ const int sz = static_cast<int>(mTextRows.size());
+ for (i = 0; i < sz - 1; ++ i)
text = text + mTextRows[i] + "\n";
text = text + mTextRows[i];
diff --git a/src/map.cpp b/src/map.cpp
index 6123332a2..3d09a0d4a 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -811,11 +811,12 @@ Path Map::findPixelPath(int startPixelX, int startPixelY, int endPixelX,
float endOffsetX = static_cast<float>(endPixelX % 32);
float endOffsetY = static_cast<float>(endPixelY % 32);
+ int sz = myPath.size();
// Find the distance, and divide it by the number of steps
int changeX = static_cast<int>((endOffsetX - startOffsetX)
- / static_cast<float>(myPath.size()));
+ / static_cast<float>(sz));
int changeY = static_cast<int>((endOffsetY - startOffsetY)
- / static_cast<float>(myPath.size()));
+ / static_cast<float>(sz));
// Convert the map path to pixels over tiles
// And add interpolation between the starting and ending offsets
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index d55e4e650..57d83fbdc 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -535,7 +535,7 @@ std::string stringToHexPath(const std::string &str)
return "";
std::string hex = strprintf("%%%2x/", static_cast<int>(str[0]));
- for (unsigned f = 1; f < str.size(); f ++)
+ for (unsigned f = 1, sz = str.size(); f < sz; f ++)
hex += strprintf("%%%2x", static_cast<int>(str[f]));
return hex;
}