diff options
author | Ben Adams <thundercat@illyriad.co.uk> | 2019-01-20 23:42:10 +0100 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2019-01-20 14:42:10 -0800 |
commit | efee81505366236a22a06663fc14927a516d5655 (patch) | |
tree | 978baa76ecafcce5af4d38b7f12505b969d3177c | |
parent | 170854b92017d709bc82d7631c6cb33dd7443078 (diff) | |
download | coreclr-efee81505366236a22a06663fc14927a516d5655.tar.gz coreclr-efee81505366236a22a06663fc14927a516d5655.tar.bz2 coreclr-efee81505366236a22a06663fc14927a516d5655.zip |
Use List<T>.ToArray() in places (#22101)
* Use ReadOnlySpan.ToArray in places
* Use List.ToArray
* Don't take .Length in to local and use as loop condition
-rw-r--r-- | src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs | 5 | ||||
-rw-r--r-- | src/System.Private.CoreLib/src/System/RtType.cs | 23 |
2 files changed, 10 insertions, 18 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs index ea7387589c..61143fecfd 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/DateTimeFormat.cs @@ -1391,9 +1391,8 @@ namespace System results.Add(strings[j]); } } - string[] value = new string[results.Count]; - results.CopyTo(0, value, 0, results.Count); - return (value); + + return results.ToArray(); } // This is a placeholder for an MDA to detect when the user is using a diff --git a/src/System.Private.CoreLib/src/System/RtType.cs b/src/System.Private.CoreLib/src/System/RtType.cs index 921c15e25b..e423b45718 100644 --- a/src/System.Private.CoreLib/src/System/RtType.cs +++ b/src/System.Private.CoreLib/src/System/RtType.cs @@ -4097,8 +4097,7 @@ namespace System if (results != null) { Debug.Assert(results.Count > 1); - finalists = new MethodInfo[results.Count]; - results.CopyTo(finalists); + finalists = results.ToArray(); } } @@ -4149,8 +4148,7 @@ namespace System if (results != null) { Debug.Assert(results.Count > 1); - finalists = new MethodInfo[results.Count]; - results.CopyTo(finalists); + finalists = results.ToArray(); } } @@ -4342,8 +4340,6 @@ namespace System if (args == null) args = Array.Empty<object>(); - int argCnt = args.Length; - // Without a binder we need to do use the default binder... if (binder == null) binder = DefaultBinder; @@ -4352,7 +4348,7 @@ namespace System // so a call to GetMemberCons would fail bool publicOnly = (bindingAttr & BindingFlags.NonPublic) == 0; bool wrapExceptions = (bindingAttr & BindingFlags.DoNotWrapExceptions) == 0; - if (argCnt == 0 && (bindingAttr & BindingFlags.Public) != 0 && (bindingAttr & BindingFlags.Instance) != 0 + if (args.Length == 0 && (bindingAttr & BindingFlags.Public) != 0 && (bindingAttr & BindingFlags.Instance) != 0 && (IsGenericCOMObjectImpl() || IsValueType)) { server = CreateInstanceDefaultCtor(publicOnly, false, true, wrapExceptions); @@ -4363,8 +4359,8 @@ namespace System List<MethodBase> matches = new List<MethodBase>(candidates.Length); // We cannot use Type.GetTypeArray here because some of the args might be null - Type[] argsType = new Type[argCnt]; - for (int i = 0; i < argCnt; i++) + Type[] argsType = new Type[args.Length]; + for (int i = 0; i < args.Length; i++) { if (args[i] != null) { @@ -4378,16 +4374,13 @@ namespace System matches.Add(candidates[i]); } - MethodBase[] cons = new MethodBase[matches.Count]; - matches.CopyTo(cons); - if (cons != null && cons.Length == 0) - cons = null; - - if (cons == null) + if (matches.Count == 0) { throw new MissingMethodException(SR.Format(SR.MissingConstructor_Name, FullName)); } + MethodBase[] cons = matches.ToArray(); + MethodBase invokeMethod; object state = null; |