On Wed, Jul 22, 2009 at 12:40 AM, Stephen Adams <[email protected]> wrote:
> This is one example of where coding style affects code size:
> int foo(const std::wstring& s);
> ...
> int x = foo(L"Hello");
>
> The compiler generates an expression-lifetime temporary object of type
> std::wstring, which entails calls to the constructor and destructor.
> This happens at every call site where the argument gets implicitly
> converted; there is an additional pair of calls.
> If you provide an overload
>
> int foo(const wchar_t* s) { return foo(std::wstring(s)); }
>
> this moves the constructor / destructor call into the overload (and
> hopefully the overload does not get inlined).
>
> How effective is this at shrinking the overall code size?
>
> I'm not sure that it is worth-while. The function has to be called many
> times to get much saving, since the saving is about 40 bytes per call site
> (win).
>
> The savings on Windows and Linux are comparable: 0.11-0.12% for the four
> functions in the changelist. The functions in the change list are ideal
> candidates because they are called many times - 397 calls.
> win: save 17k of 15MB
> linux: save 33k of 28MB (stripped)
>
> http://codereview.chromium.org/159156
>
For the record, on Windows you built in "release" and not a whole program
optimized build so your test is not that valuable.
You need to "set CHROMIUM_BUILD=_official" first to enable LTCG.
M-A
--~--~---------~--~----~------------~-------~--~----~
Chromium Developers mailing list: [email protected]
View archives, change email options, or unsubscribe:
http://groups.google.com/group/chromium-dev
-~----------~----~----~----~------~----~------~--~---