codymanix said:
That is exactly the point! Since the Jitting (unlike compilation)is done at
runtime is *can* determine the runtimetype of the IComparer passed and rejit
it.
No, "rejit" is the key word here: JITting is only done once per method.
That means jitting of the Array.SortMethod could be done *every* call of
the method but the Jitter may determine to rejit only if the Arraylenght is
bigger than a certain value so that the rejit is worth it.
It could be, but the current implementation certainly only JITs once
per method.
Additionally, already jitted instances of Array.Sort(IConparer comp) may be
cached in memory so that repeated calls of Array.Sort with the same
IComparer uses the cached version.
Hmm. Even HotSpot (the Sun JVM which *does* JIT multiple times) doesn't
take that kind of approach. It rejits either once it's noticed that the
method has been called frequently, and does it again with more
optimisation, or if the circumstances have changed (e.g. a virtual
method has been overridden, so an optimisation elsewhere is no longer
valid).
There are various penalties associated with JITting, and while what
you're suggesting may well be possible, I suspect it wouldn't be
beneficial in the long run. (It would also add significantly to the
complexity of the JIT, which would have stability implications.)