bug with wxVariant

Willem Kokke wkokke at gmail.com
Tue Oct 17 15:33:50 PDT 2006


wxVariant::GetLong ends up calling Convert

bool wxVariant::Convert(long* value) const
{
    wxString type(GetType());
    if (type =3D=3D wxT("double"))
        *value =3D (long) (((wxVariantDoubleData*)GetData())->GetValue());
    else if (type =3D=3D wxT("long"))
        *value =3D ((wxVariantDataLong*)GetData())->GetValue();
#ifdef HAVE_BOOL
    else if (type =3D=3D wxT("bool"))
        *value =3D (long) (((wxVariantDataBool*)GetData())->GetValue());
#endif
    else if (type =3D=3D wxT("string"))
        *value =3D wxAtol((const wxChar*)
((wxVariantDataString*)GetData())->GetValue());
    else
        return false;

    return true;
}


so it creates 4 temporary string object, loads of string compares and in the
end it just calls wxAtol, which calls atol

so you are creating a extra temporary wxVariant for no good reason, wasting
memory and processor time, just to save a line of code?
then you might as well use atol(str.c_str()); and get it over with...

Some people do need to test whether the string contains a valid number. I
prefer having a concise library instead of a library with hundreds of
utility functions that just discard one single parameter. if you really
can't stand the extra line of code, write a utility functions yourself.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-users/attachments/20061017/23e=
078fd/attachment.htm


More information about the wx-users mailing list