This project is read-only.


Writes to locals & fields don't use decimal.Zero



SSL wrote Nov 9, 2014 at 7:52 PM

Interestingly, the old compiler does the reverse, replacing all of the static readonly fields in decimal with ctor calls.

I wonder why.

VSadov wrote Nov 10, 2014 at 7:32 PM

Fetching a decimal value from a static field is cheaper than constructing a new one. At very least the ctor will do argument validation and copy is just a copy.
However when initializing a struct value to its default state (0 in the case of decimal), initobj is more appropriate and backend will use initobj. That is not specific to decimal.

Native compiler possibly used a different codegen strategy. Perhaps missing some optimizations or applying at a different stage or in different order.

SSL wrote Nov 11, 2014 at 4:27 AM


Thanks for the detailed explanation!