mirror of
https://github.com/BepInEx/dotnet-runtime.git
synced 2026-11-23 03:39:35 -10:00
Add explicit 0 index args to Array.Copy usage
Array.Copy is implemented to work with any System.Array, not just T[]. When Array.Copy(sourceArr, destArray, length) is used, it delegates to Copy(sourceArr, sourceIndex, destArray, destIndex, length), and as such needs to query for the lower-bound of the supplied arrays, since although a T[] in C# always has a lower-bound of 0, an arbitrary Array may not. Given this, when calling Array.Copy, instead of calling Array.Copy(src, dest, length), it's slightly more efficient to just call Array.Copy(src, 0, dest, 0, length), avoiding the need for the GetLowerBound calls made while delegating to the 5-arg version. I noticed one occurrence of this in some code I was looking at, and while fixing that, I fixed all of them across corefx\src. Commit migrated from https://github.com/dotnet/corefx/commit/979026e435672e611e3f6e0647c873aa96ccc684
This commit is contained in:
1 parent
e111c60d34
commit
613a87d035
39 files changed
+66
-66
No files matched your search
@@ -299,11 +299,11 @@ namespace System.IO
|
||||
{
|
||||
int newSize = currentMatches.Length * 2;
|
||||
int[] tmp = new int[newSize];
|
||||
Array.Copy(currentMatches, tmp, currentMatches.Length);
|
||||
Array.Copy(currentMatches, 0, tmp, 0, currentMatches.Length);
|
||||
currentMatches = tmp;
|
||||
|
||||
tmp = new int[newSize];
|
||||
Array.Copy(previousMatches, tmp, previousMatches.Length);
|
||||
Array.Copy(previousMatches, 0, tmp, 0, previousMatches.Length);
|
||||
previousMatches = tmp;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user