Hello Hyrum!

On Thursday 14 October 2010, Hyrum K. Wright wrote:
> The following is a somewhat naïve implementation, but does it jive
> with your suggestion?
...
>     inline const char *c_str() const
>     {
>       if (isNull)
>         return NULL;
>       else
>         return std::string::c_str();
>     }
It might be easier for callers if this did
        if (isNull)
                return "";
so that the value could just be used in printf() and similar without 
explicit checking.


Furthermore I don't know how many instances of these strings will be active 
simultaneously; but the "bool isNull" could cost up to 8 bytes (because of 
aligning on 64bit).
If that is a concern, how about using a specific, static value for the 
std::string instead that is compared against?

I know, microoptimization again, but I wanted to mention the idea.


Regards,

Phil

Reply via email to