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

List:       kde-commits
Subject:    Re: kdenonbeta/kopete/kopete/protocols/msn
From:       Werner Trobin <trobin () kde ! org>
Date:       2002-04-11 8:45:21
[Download RAW message or body]

On Thursday 11 April 2002 10:29, Martijn Klingens wrote:
> On Wednesday 10 April 2002 22:34, Carsten Pfeiffer wrote:
> > What about adding some strategic "&"s everywhere?
>
> For passing on QStrings? I deliberately didn't, because I thought that was
> pointless for QStrings (explicit sharing and stuff)...

Implicit sharing :-)
QMemArray and QImage and such classes do explicit sharing.

I'd say it makes sense to use "QString foo" as a shallow copy of a QString is 
cheap anyway. "const QString& foo" is still a bit cheaper, but "const QString 
foo" doesn't make a lot of sense. You still shallow-copy the string but you 
restrict yourself not to modify it in the method. Don't know if any compiler 
can optimize a bit more aggressively with that information... probably not.

So if you really would want to modify it within your method you'd have to 
create yet another shallow copy (like QString bar( foo ); ). As soon as you 
write to it now it will do a deep copy and modify that one. This is one 
(albeit cheap) shallow copy too much.

Conclusion: use const QString& foo or maybe QString foo but not const QString 
foo :-)

Ciao,
Werner
[prev in list] [next in list] [prev in thread] [next in thread] 

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