Skip to content

Commit

Permalink
While on it, optimize a bit the way the textboxes text is recomputed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohann Ferreira committed Dec 17, 2012
1 parent af98fa2 commit 71a3edf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/common/gui/textbox.cpp
Expand Up @@ -257,6 +257,10 @@ void TextBox::SetDisplayText(const ustring &text)
return;
}

// If the text hasn't changed, don't recompute the textbox.
if (_text_save == text)
return;

_text_save = text;
_ReformatText();

Expand Down
14 changes: 14 additions & 0 deletions src/utils.cpp
Expand Up @@ -236,6 +236,20 @@ ustring &ustring::operator = (const ustring &s)
return *this;
} // ustring & ustring::operator = (const ustring &s)

// Compare two substrings
bool ustring::operator == (const ustring &s)
{
size_t len = length();
if (s.length() != len)
return false;

for(size_t j = 0; j < len; ++j) {
if (_str[j] != s[j] )
return false;
}

return true;
} // bool ustring::operator == (const ustring &s)

// Finds a character within a string, starting at pos. If nothing is found, npos is returned
size_t ustring::find(uint16 c, size_t pos) const
Expand Down
2 changes: 2 additions & 0 deletions src/utils.h
Expand Up @@ -312,6 +312,8 @@ class ustring

ustring &operator = (const ustring &s);

bool operator == (const ustring &s);

uint16 &operator [](size_t pos) {
return _str[pos];
}
Expand Down

2 comments on commit 71a3edf

@IkarusDowned
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a thought, you may want to make those operators const. so:
bool operator == (const ustring &s) const;

@Bertram25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, I'll do, thanks!

Please sign in to comment.