Skip to content

Commit 583fa67

Browse files
Use CopyTo(arr) instead of creating List<T> first (#36228)
* Use LINQ ToArray * Update RoType.cs * Update RoType.cs * Update src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Types/RoType.cs Co-authored-by: Stephen Toub <stoub@microsoft.com> * Fix whitespace causing analyzer warnings Co-authored-by: Stephen Toub <stoub@microsoft.com>
1 parent df8e2d7 commit 583fa67

File tree

1 file changed

+8
-3
lines changed
  • src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Types

1 file changed

+8
-3
lines changed

src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Types/RoType.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,14 @@ private RoType[] ComputeInterfaceClosure()
192192
}
193193
}
194194

195-
// todo: use IEnumerable<T> extension: return ifcs.ToArray()
196-
List<RoType> list = new List<RoType>(ifcs);
197-
return list.ToArray();
195+
if (ifcs.Count == 0)
196+
{
197+
return Array.Empty<RoType>();
198+
}
199+
200+
var arr = new RoType[ifcs.Count];
201+
ifcs.CopyTo(arr);
202+
return arr;
198203
}
199204

200205
private volatile RoType[]? _lazyInterfaces;

0 commit comments

Comments
 (0)