← Back to team overview

kicad-developers team mailing list archive

Re: Static initialization order fiasco

 

On 04/13/2014 08:13 AM, Lorenzo Marcantonio wrote:
> On Sun, Apr 13, 2014 at 07:53:23AM -0500, Dick Hollenbeck wrote:
>>   const wxChar NETCLASS::Default[] = wxT( "Default" );
>>
>> instead of
>>
>>   const wxString NETCLASS::Default = wxT( "Default" );
>>
>> This defers the construction of the wxString until actually used, and removes the wxString
>> static constructor from the race.
> 
> Wouldn't this re-construct the wxString from scratch every time that
> value is used (maybe indirectly unless the overloaded functions are
> really smart, working with a char array instead of building a string and
> revert to the general case)?
> 
> Performance would be probably acceptable anyway but I don't like it very
> much (considering that something called 'default' would be probably used
> quite a lot).
> 
> IIRC you had performance issues with strings in the sexp parser, in the
> past.


Loops or high numbers of operations (often caused by looping) can give you enough deltas
to where you might care.   IOW:

  impact = iteration_count * delta_between_two_alternatives

If either iteration_count *or* delta is small enough, then there's no reason to care.

The case you cite had iteration_count equal to the total number of s-expression *tokens*
in a BOARD file.  So that number was quite high.

Nothing like that pertains here.

In this case the most frequent usage of NETCLASS::Default[] is line 187 of
pcbnew/class_netclass.cpp.  (I am ignoring wxString construction, since I don't think
wxString's copy constructor is appreciably faster than the one using wxChar*.)

For line 187, there is this gem in wxString, wx/string.h:

inline bool operator==(const wxScopedWCharBuffer& s1, const wxString& s2)
    { return (s2.Cmp((const wchar_t *)s1) == 0); }


If it still bothers you, you may perform some measurements looking to strengthen your
argument.  I won't do so.







Follow ups

References