Is there such a C++ optimisation?

E.g.

vector<string> a;

vector<string> b;

a.push_back("first");

b=a;

Would it be optimised somehow as

vector<string> b;

b.push_back("first");

Answers


Short answer: Yes.

Long answer: Not really an "optimization", as most modern compilers (read as: non-MSVC) will do that. It's called static single assignment (SSA) and GCC supports it since version 4.0 - and it kicks ass, too!


Well, you're saving yourself a call to operator=...

You should always remember the 2 rules of optimization though.

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson


Need Your Help

How to stop a curl while requesting or stop the running php script?

php apache curl

I using url to request remote urls that sometimes may very slow or just down.

How do I disable warnings in lisp (sbcl)

debugging lisp common-lisp sbcl

How do I disable all warnings in sbcl? The extra output is rather annoying.