[cfe-dev] Proposed C++ optimization with big speed gains with big objects

Klaim - Joël Lamotte mjklaim at gmail.com
Thu Sep 27 03:32:55 PDT 2012


On Thu, Sep 27, 2012 at 12:51 AM, Ladislav Nevery <neuralll at gmail.com>wrote:

> Actually the sample you provided will work without problem.
> Since switch works only on first assign(after default constructor)
>
> TextFile textfile[1000]; // default constructor doing nothing
>
> textfile[1]=TextFile("c:\test1.txt"); // = we call destructor doing nothing
> and placement new
> textfile[1]=TextFile("c:\test1.txt"); // standard temp copy + operator
> combo
>
> But I see the point if you put code logic to default constructor then yes
> first assign will not happen. You use switch to remove copy from arrays
> init. So yes actual code change is needed in this statistically marginal
> case.
>
> Anyway code logic (opening files etc) in default constructors is BLASPHEMY
> !
> :D such people actually deserve to being punished.
> Punishing them a bit more is actually good thing ;D Lets call it feature
>

I'm sorry I don't understand at all what you mean here.
I'm saying, taking the exact code I proposed, not changing it by adding a
default constructor, this expression:

TextFile a ("a.txt");
TextFile b ("b.txt");
a = b; //copy the content of b.txt in a.txt

Would have, using your change, a different semantic than what the standard
propose because there would be file closing and opening where I didn't want
to.
The type is specifically written to avoid closing and opening files until
the instances are really out of scope or explicitely deleted.

Or did I misunderstand your proposal?

Joel Lamotte
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120927/8e96ce8b/attachment.html>


More information about the cfe-dev mailing list