From 56edecab9493a44c65b29179bc73e26872c18a10 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sat, 3 Jan 2015 15:20:19 +0000 Subject: [PATCH] Optimize wxPGChoices::Add methods. Remove unnecessary variables, limit the scope of variables and implement some sanity checks. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78344 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/propgrid/property.cpp | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 32a08769a4..1ce491982f 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -2935,17 +2935,10 @@ void wxPGChoices::Add( const wxChar* const* labels, const ValArrItem* values ) { AllocExclusive(); - unsigned int itemcount = 0; - const wxChar* const* p = &labels[0]; - while ( *p ) { p++; itemcount++; } - - unsigned int i; - for ( i = 0; i < itemcount; i++ ) + for ( unsigned int i = 0; *labels; labels++, i++ ) { - int value = i; - if ( values ) - value = values[i]; - wxPGChoiceEntry entry(labels[i], value); + const int value = values ? values[i] : i; + wxPGChoiceEntry entry(*labels, value); m_data->Insert( i, entry ); } } @@ -2956,14 +2949,14 @@ void wxPGChoices::Add( const wxArrayString& arr, const wxArrayInt& arrint ) { AllocExclusive(); - unsigned int i; - unsigned int itemcount = arr.size(); + const unsigned int itemcount = arr.size(); + const unsigned int valcount = arrint.size(); + wxASSERT_MSG( valcount >= itemcount || valcount == 0, + wxT("Insufficient number of values in the array") ); - for ( i = 0; i < itemcount; i++ ) + for ( unsigned int i = 0; i < itemcount; i++ ) { - int value = i; - if ( &arrint && arrint.size() ) - value = arrint[i]; + const int value = (i < valcount) ? arrint[i] : i; wxPGChoiceEntry entry(arr[i], value); m_data->Insert( i, entry ); }