compiler optimization - c#: Will this code get optimized out? -


i reviewing code given third-party outsourcing firm , ran across little gem:

try {     int = stroriginaldata.indexof("\r\n");     ////system.diagnostics..eventlog.writeentry("i", i.tostring()); } catch (system.exception ex) {     ////system.diagnostics..eventlog.writeentry("ex", ex.message); } 

my question compiler optimize out? when @ compiled assembly in reflector, shows this:

try {     = this.stroriginaldata.indexof("\r\n"); } catch (exception exception1) {     ex = exception1; } 

the declaration has been moved top of method, , additional declaration of type exception @ top of method also.

so, since code doesn't anything, wondering if compiler smart enough see code nothing , can optimize out.

so, you've found via reflector, c# compiler not optimize out. whether jit compiler question. but, guess answer not.

why? because jit compiler doesn't know indexof boring method. in other words, far jit compiler knows, string.indexof defined as

public int indexof() {    callawebservice(); } 

obviously, in case optimizing out line bad.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -