From a9d1aaa774b9e986b8ee3c6cb1e7baa1d9ba3ea5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 9 Aug 2013 23:41:59 +0300 Subject: improve size() methods usage. --- src/guichan/widgets/textbox.cpp | 15 +++++++++------ src/guichan/widgets/textfield.cpp | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/guichan') diff --git a/src/guichan/widgets/textbox.cpp b/src/guichan/widgets/textbox.cpp index 3f1c51402..512471391 100644 --- a/src/guichan/widgets/textbox.cpp +++ b/src/guichan/widgets/textbox.cpp @@ -137,8 +137,9 @@ namespace gcn { mCaretRow = mouseEvent.getY() / getFont()->getHeight(); - 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; mCaretColumn = getFont()->getStringIndexAt( mTextRows[mCaretRow], mouseEvent.getX()); @@ -210,8 +211,9 @@ namespace gcn { mCaretRow = row; - 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; if (mCaretRow < 0) mCaretRow = 0; @@ -228,8 +230,9 @@ namespace gcn { mCaretColumn = column; - if (mCaretColumn > static_cast(mTextRows[mCaretRow].size())) - mCaretColumn = static_cast(mTextRows[mCaretRow].size()); + const int sz = static_cast(mTextRows[mCaretRow].size()); + if (mCaretColumn > sz) + mCaretColumn = sz; if (mCaretColumn < 0) mCaretColumn = 0; diff --git a/src/guichan/widgets/textfield.cpp b/src/guichan/widgets/textfield.cpp index e5ecc172b..f0d464995 100644 --- a/src/guichan/widgets/textfield.cpp +++ b/src/guichan/widgets/textfield.cpp @@ -89,9 +89,9 @@ namespace gcn void TextField::setText(const std::string& text) { - if (text.size() < mCaretPosition) - mCaretPosition = static_cast(text.size()); - + const size_t sz = text.size(); + if (sz < mCaretPosition) + mCaretPosition = sz; mText = text; } -- cgit v1.2.3-70-g09d2