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:
Vadim Zeitlin
2026-10-04 18:08:29 +02:00
parent 6dc021c270
commit add0932f23
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -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
+4
View File
@@ -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);