There are many articles on the Internet that list optimizations made by C # JIT before executing a piece of code. For example, this MSDN post talks about:
Constant bending, distribution of constants and copies, general subexpression exception, code movement of loop invariants, dead storage and dead code exception, register allocation, inlining method, Loop unrolling (small loops with small bodies).
My question is: is the JIT compiler dealing with useless zero checks? I can not find a source considering this issue.
In the same article, I read:
since the C # language specification ensures that any call to a null-value reference to an object throws a NullReferenceException, each call site must make sure that the instance is not null. This is done by dereferencing the reference to the instance; if it is zero, it will generate an error, which turned into this exception.
So, suppose I write a piece of code as follows:
if (person != null)
{
Console.WriteLine(person.Name);
}
person.Namecalls the second null check again, which is useless, and the compiler can delete it. Or not?
I read that this has already been done in Java (some sources between many here , here and here ).
If C # does this too, do you know some source or documentation that talks about this?
# , , ? .NET, JIT Java ?