From 2213603c14b289ceb5389329f79f7af3cfc44faa Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 1 Jul 2013 12:52:33 +0300 Subject: improve size() usage in textbox. --- src/gui/widgets/textbox.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/gui/widgets/textbox.cpp') diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index c1bf84d85..4eccbe76c 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -57,7 +57,8 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension) // point and try to beat it mMinWidth = minDimension; - size_t spacePos = text.rfind(" ", text.size()); + const size_t textSize = text.size(); + size_t spacePos = text.rfind(" ", textSize); if (spacePos != std::string::npos) { @@ -80,7 +81,7 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension) newlinePos = text.find("\n", lastNewlinePos); if (newlinePos == std::string::npos) - newlinePos = text.size(); + newlinePos = textSize; std::string line = text.substr(lastNewlinePos, newlinePos - lastNewlinePos); @@ -133,7 +134,7 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension) lastNewlinePos = 0; newlinePos = text.find("\n", lastNewlinePos); if (newlinePos == std::string::npos) - newlinePos = text.size(); + newlinePos = textSize; line = text.substr(lastNewlinePos, newlinePos - lastNewlinePos); // width = 0; @@ -314,8 +315,9 @@ void TextBox::keyPressed(gcn::KeyEvent& keyEvent) / getFont()->getHeight(); mCaretRow += rowsPerPage; - if (mCaretRow >= static_cast(mTextRows.size())) - mCaretRow = static_cast(mTextRows.size()) - 1; + const int sz = static_cast(mTextRows.size()); + if (mCaretRow >= sz) + mCaretRow = sz - 1; } break; } -- cgit v1.2.3-60-g2f50