mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-10-06 07:00:16 +08:00
Optimize wxMSW wxChoice/wxListBox::SetString() if nothing changes
Because the corresponding native controls don't support modifying their items in place, wxChoice and wxListBox had to remove the item and add it back, which was quite expensive, so it's better to avoid this if the item doesn't change at all.
This commit is contained in:
@@ -378,6 +378,11 @@ void wxChoice::SetString(unsigned int n, const wxString& s)
|
||||
{
|
||||
wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::SetString") );
|
||||
|
||||
// don't do anything if the string doesn't change, deleting and inserting
|
||||
// the item back below is not free and also results in flicker
|
||||
if ( s == GetString(n) )
|
||||
return;
|
||||
|
||||
// we have to delete and add back the string as there is no way to change a
|
||||
// string in place
|
||||
|
||||
|
||||
@@ -515,6 +515,10 @@ void wxListBox::SetString(unsigned int n, const wxString& s)
|
||||
wxCHECK_RET( IsValid(n),
|
||||
wxT("invalid index in wxListBox::SetString") );
|
||||
|
||||
// don't do anything if the string doesn't change, see wxChoice::SetString()
|
||||
if ( s == GetString(n) )
|
||||
return;
|
||||
|
||||
// remember the state of the item
|
||||
bool wasSelected = IsSelected(n);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user