[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    Re: [Kde-pim] AddresseeEditorWidget::addressee()
From:       Mike Pilone <mpilone () slac ! com>
Date:       2002-05-08 16:11:05
[Download RAW message or body]

On Wednesday 08 May 2002 10:49 am, Cornelius Schumacher wrote:
> But you can't safely do something like "return Addressee()" in such
> functions and the overhead of copying is minimal because the class is
> implicitly shared.

I assumed that with the AddresseeEditorWidget you would never be doing a 
'return Addressee()' since you would always return mAddressee.

> I'm not sure that I really understand all the implications of returning a
> constant reference from a function, but as it doesn't mean much overhead
> (if any at all) with shared classes and it looks simpler I would prefer
> to return the value. At least that's what is done in Qt and KDE (for
> QString return values) in most cases, and this probably has a good
> reason.

Returning a const reference means the function only puts a int (pointer) on 
the return value stack rather than the entire object. In most cases the 
creation of a new int is much faster than the creation (and copying) of a 
new object. The const ensures that the caller cannot modify the object they 
get without copying it (passing the object as a const ref into the 
operator=()). This means that for simple calls like: 
AddresseeEditorWidget::addressee().uid(), a new object is not created just 
to call one method on it.

If there is a reason to return Addressee() from AddresseeEditorWidget, then 
definately change the return type. Since Addressee is shared anyway this 
argument doesn't really matter. The difference would only really show up if 
all the data in an Addressee was copied. I was just trying to take the 
approach that I don't know what is happening inside Addressee.

-mike

-- 
Mike Pilone <mpilone@slac.com>        http://www.slac.com/mpilone/personal/
GPG Fingerprint = 856C 8B36 ECF7 9156 4611  7C6B C265 05C4 162F C3B5

See http://www.slac.com/mpilone/personal/mpilone_pub_key.gpg for full key.
See http://www.gnupg.org for GPG information.
_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic