Avoid consecutive calls of wxVariant::GetType() in the multiple-branch conditional statements.

This is a minor optimization since wxVariant::GetType() is not a simple inline getter method.
This commit is contained in:
Artur Wieczorek 2015-02-28 16:35:20 +01:00
parent 3fb1827c93
commit 2f239930eb
2 changed files with 16 additions and 14 deletions

View File

@ -975,7 +975,8 @@ wxColourPropertyValue wxSystemColourProperty::GetVal( const wxVariant* pVariant
if ( pVariant->IsNull() ) if ( pVariant->IsNull() )
return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED, wxColour()); return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED, wxColour());
if ( pVariant->GetType() == wxS("wxColourPropertyValue") ) const wxString valType(pVariant->GetType());
if ( valType == wxS("wxColourPropertyValue") )
{ {
wxColourPropertyValue v; wxColourPropertyValue v;
v << *pVariant; v << *pVariant;
@ -985,16 +986,16 @@ wxColourPropertyValue wxSystemColourProperty::GetVal( const wxVariant* pVariant
wxColour col; wxColour col;
bool variantProcessed = true; bool variantProcessed = true;
if ( pVariant->GetType() == wxS("wxColour*") ) if ( valType == wxS("wxColour*") )
{ {
wxColour* pCol = wxStaticCast(pVariant->GetWxObjectPtr(), wxColour); wxColour* pCol = wxStaticCast(pVariant->GetWxObjectPtr(), wxColour);
col = *pCol; col = *pCol;
} }
else if ( pVariant->GetType() == wxS("wxColour") ) else if ( valType == wxS("wxColour") )
{ {
col << *pVariant; col << *pVariant;
} }
else if ( pVariant->GetType() == wxArrayInt_VariantType ) else if ( valType == wxArrayInt_VariantType )
{ {
// This code is mostly needed for wxPython bindings, which // This code is mostly needed for wxPython bindings, which
// may offer tuple of integers as colour value. // may offer tuple of integers as colour value.

View File

@ -239,11 +239,12 @@ wxIntProperty::~wxIntProperty() { }
wxString wxIntProperty::ValueToString( wxVariant& value, wxString wxIntProperty::ValueToString( wxVariant& value,
int WXUNUSED(argFlags) ) const int WXUNUSED(argFlags) ) const
{ {
if ( value.GetType() == wxPG_VARIANT_TYPE_LONG ) const wxString valType(value.GetType());
if ( valType == wxPG_VARIANT_TYPE_LONG )
{ {
return wxString::Format(wxS("%li"),value.GetLong()); return wxString::Format(wxS("%li"),value.GetLong());
} }
else if ( value.GetType() == wxPG_VARIANT_TYPE_LONGLONG ) else if ( valType == wxPG_VARIANT_TYPE_LONGLONG )
{ {
wxLongLong ll = value.GetLongLong(); wxLongLong ll = value.GetLongLong();
return ll.ToString(); return ll.ToString();
@ -283,7 +284,7 @@ bool wxIntProperty::StringToValue( wxVariant& variant, const wxString& text, int
wxString useText = text.substr(firstNonZeroPos, text.length() - firstNonZeroPos); wxString useText = text.substr(firstNonZeroPos, text.length() - firstNonZeroPos);
wxString variantType = variant.GetType(); const wxString variantType(variant.GetType());
bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG; bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG;
wxLongLong_t value64 = 0; wxLongLong_t value64 = 0;
@ -652,7 +653,7 @@ wxString wxUIntProperty::ValueToString( wxVariant& value,
bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, int WXUNUSED(argFlags) ) const bool wxUIntProperty::StringToValue( wxVariant& variant, const wxString& text, int WXUNUSED(argFlags) ) const
{ {
wxString variantType = variant.GetType(); const wxString variantType(variant.GetType());
bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG; bool isPrevLong = variantType == wxPG_VARIANT_TYPE_LONG;
if ( text.empty() ) if ( text.empty() )
@ -1197,14 +1198,14 @@ wxEnumProperty::~wxEnumProperty ()
void wxEnumProperty::OnSetValue() void wxEnumProperty::OnSetValue()
{ {
wxString variantType = m_value.GetType(); const wxString valType(m_value.GetType());
int index = -1; int index = -1;
if ( variantType == wxPG_VARIANT_TYPE_LONG ) if ( valType == wxPG_VARIANT_TYPE_LONG )
{ {
ValueFromInt_(m_value, &index, m_value.GetLong(), wxPG_FULL_VALUE); ValueFromInt_(m_value, &index, m_value.GetLong(), wxPG_FULL_VALUE);
} }
else if ( variantType == wxPG_VARIANT_TYPE_STRING ) else if ( valType == wxPG_VARIANT_TYPE_STRING )
{ {
ValueFromString_(m_value, &index, m_value.GetString(), 0); ValueFromString_(m_value, &index, m_value.GetString(), 0);
} }
@ -1383,14 +1384,14 @@ wxEditEnumProperty::~wxEditEnumProperty()
void wxEditEnumProperty::OnSetValue() void wxEditEnumProperty::OnSetValue()
{ {
wxString variantType = m_value.GetType(); const wxString valType(m_value.GetType());
int index = -1; int index = -1;
if ( variantType == wxPG_VARIANT_TYPE_LONG ) if ( valType == wxPG_VARIANT_TYPE_LONG )
{ {
ValueFromInt_(m_value, &index, m_value.GetLong(), wxPG_FULL_VALUE); ValueFromInt_(m_value, &index, m_value.GetLong(), wxPG_FULL_VALUE);
} }
else if ( variantType == wxPG_VARIANT_TYPE_STRING ) else if ( valType == wxPG_VARIANT_TYPE_STRING )
{ {
wxString val = m_value.GetString(); wxString val = m_value.GetString();
ValueFromString_(m_value, &index, val, 0); ValueFromString_(m_value, &index, val, 0);