Truthfully the only thing that needs to be IL optimized at this stage of the C#
compiler is stack local usage. They don't share stack locals for nested
elements, when they probably should, since IL has a method for aliasing
nested locals to be re-used. For instance:
for(int i = 0; i < 10; i++) {}
for(int i = 0; i < 10; i++) {}
for(int i = 0; i < 10; i++) {}
How many locals does that produce? 3 of them, though you'd only think
it would produce one. IL has something called slot aliasing, so they could
refer to i as V_0, V_1, and V_2, but all three of these variables would
share the same stack slot.
This is only a code-size enhancement, but it produces decent results. As for
the 'as' enhancement. That type of layout is easy to detect. Changing it
really
doesn't produce that much of an enhancement though, and you'd have to
special case your detection logic so that it didn't try to convert value type
instances of the is/casting pattern. Of course, the IL for a value type versus
object type casting looks different (castclass versus unbox), so that shouldn't
be a big issue.
I can't find my blog entry on the stack local enhancement, but it is in there
somewhere
under the performance category if anyone is interested.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog:
http://weblogs.asp.net/justin_rogers