c# - Why is this NHibernate code performing a chain of explicit casts? -
i looking through source of nhibernate project (version 3.3.1.4000) , noticed strange in anywherematchmode class:
public override string tomatchstring(string pattern) { return (string) (object) '%' + (object) pattern + (string) (object) '%'; }
why on earth cast char object , re-cast string? why cast string object before adding other strings? there performance bonus here, or edge case avoid? i'm looking idea behind code, because there must reason it.
note: realized, got here resharper's "navigate to" feature, may decompiled code i'm looking at. if is, i'd know what's going on here.
looks may artifact of resharper's "navigate to", looking @ source code nhibernate method looks this:
public override string tomatchstring(string pattern) { return '%' + pattern + '%'; }
update: here's msil method:
.method public hidebysig virtual instance string tomatchstring(string pattern) cil managed { // code size 26 (0x1a) .maxstack 3 .locals init ([0] string cs$1$0000) il_0000: nop il_0001: ldc.i4.s 37 il_0003: box [mscorlib]system.char il_0008: ldarg.1 il_0009: ldc.i4.s 37 il_000b: box [mscorlib]system.char il_0010: call string [mscorlib]system.string::concat(object, object, object) il_0015: stloc.0 il_0016: br.s il_0018 il_0018: ldloc.0 il_0019: ret } // end of method anywherematchmode::tomatchstring
since code compiles string concatenation optimized string.concat("%", pattern, "%")
, when resharper decompiles looks may representing boxing cast object
.
Comments
Post a Comment