mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-21 22:03:11 -07:00
Eliminate redundant copies of EMPTY_UNIT object, saving 2.5 KB.
There are currently 11 copies of the `EMPTY_UNIT` object in the `Calculator.exe` binary, which not only wastes space/footprint in the binary itself, but also means that each copy must be separately initialized, which effects performance. The reason for this is that the object is defined in a shared header file, which then is included by multiple .cpp files, causing each translation unit (.obj) to get a full complete copy of the object. By marking the object as `extern __declspec(selectany)` we can instruct the linker to pick any of the global objects, as we do not need to have 11 unique versions of the EMPTY_UNIT object, we only need 1. The net result is that the `Calculator.exe` binary size is reduced by 2,560 bytes (or 2.5 KB) with no change in behavior, other than the small performance benefit of not initializing 10 redundant copies of the object.
This commit is contained in:
parent
a98cb50a70
commit
8983a1cb46
1 changed files with 1 additions and 1 deletions
|
@ -51,7 +51,7 @@ namespace UnitConversionManager
|
|||
// null checks.
|
||||
//
|
||||
// unitId, name, abbreviation, isConversionSource, isConversionTarget, isWhimsical
|
||||
const Unit EMPTY_UNIT = Unit{ -1, L"", L"", true, true, false };
|
||||
extern __declspec(selectany) const Unit EMPTY_UNIT = Unit{ -1, L"", L"", true, true, false };
|
||||
|
||||
struct Category
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue