[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: object-model: Return by value, reference or pointer? (or something else?)

From: Philipp Marek <philipp.marek_at_linbit.com>
Date: Fri, 15 Oct 2010 08:31:00 +0200

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
Received on 2010-10-15 08:31:46 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.