Avoid unnecessary work for identical locations in Buffer.BlockCopy
authorBen Adams <thundercat@illyriad.co.uk>
Tue, 3 Feb 2015 21:41:36 +0000 (21:41 +0000)
committerben_a_adams <ben.adams@ageofascent.com>
Wed, 4 Feb 2015 19:47:15 +0000 (19:47 +0000)
commita5dd659fdc1719f943fead7e1b6e2db167a271a4
tree21682a83d1b5b74faa97ce37d4a65c6c4a250bae
parentb846bb46cfa695d7fc39993a70a4d0add762d6c3
Avoid unnecessary work for identical locations in Buffer.BlockCopy

Perform validity checks to ensure parameters are correct but short-circuit
out memmove when exactly the same data would be copied to the same location.

There are a number of occasions; which can be intentional or unintentional,
where the buffer being copied is the same place - e.g an internal buffer is
the same as the return buffer, and there is no need to call memmove's
overwrite safe copy.

Generally the call to BlockCopy will be in a library so it is more practical
to enable the check here rather than alter all the calling functions,
including 3rd party libraries to preform additional checks.
src/vm/comutilnative.cpp