Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit edffbd9

Browse files
authored
Remove two unnecessary ToArray calls (#22119)
We can just copy directly from the List, rather than first converting the list to an array and then copying that.
1 parent 401e931 commit edffbd9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ private static Attribute[] InternalGetCustomAttributes(PropertyInfo element, Typ
4848
AddAttributesToList(attributeList, attributes, types);
4949
baseProp = GetParentDefinition(baseProp, indexParamTypes);
5050
}
51-
Array array = CreateAttributeArrayHelper(type, attributeList.Count);
52-
Array.Copy(attributeList.ToArray(), 0, array, 0, attributeList.Count);
53-
return (Attribute[])array;
51+
Attribute[] array = CreateAttributeArrayHelper(type, attributeList.Count);
52+
attributeList.CopyTo(array, 0);
53+
return array;
5454
}
5555

5656
private static bool InternalIsDefined(PropertyInfo element, Type attributeType, bool inherit)
@@ -143,9 +143,9 @@ private static Attribute[] InternalGetCustomAttributes(EventInfo element, Type t
143143
AddAttributesToList(attributeList, attributes, types);
144144
baseEvent = GetParentDefinition(baseEvent);
145145
}
146-
Array array = CreateAttributeArrayHelper(type, attributeList.Count);
147-
Array.Copy(attributeList.ToArray(), 0, array, 0, attributeList.Count);
148-
return (Attribute[])array;
146+
Attribute[] array = CreateAttributeArrayHelper(type, attributeList.Count);
147+
attributeList.CopyTo(array, 0);
148+
return array;
149149
}
150150
else
151151
return attributes;

0 commit comments

Comments
 (0)