Skip to content

Commit a2b5880

Browse files
authored
Merge pull request #9222 from h3xds1nz/replace-arraylist-with-preallocated-array
Replace ArrayList in CursorConverter with preallocated array and reduce allocations
2 parents 8b20afb + 90e8c2c commit a2b5880

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/CursorConverter.cs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System.ComponentModel;
66
using System.ComponentModel.Design.Serialization;
7-
using System.Collections;
87
using System.Globalization;
98
using System.Reflection;
109
using System.Windows.Media; // TypeConverterHelper, UriHolder
@@ -53,35 +52,29 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati
5352
return false;
5453
}
5554

56-
/// <summary>
57-
/// Gets the public/static properties of the Cursors class
58-
/// </summary>
59-
/// <returns>PropertyInfo array of the objects properties</returns>
60-
private PropertyInfo[] GetProperties()
61-
{
62-
return typeof(Cursors).GetProperties(BindingFlags.Public | BindingFlags.Static);
63-
}
64-
6555
/// <summary>
6656
/// StandardValuesCollection method override
6757
/// </summary>
6858
/// <param name="context">ITypeDescriptorContext</param>
6959
/// <returns>TypeConverter.StandardValuesCollection</returns>
7060
public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
7161
{
72-
if(this._standardValues == null)
62+
if(_standardValues is null)
7363
{
74-
ArrayList list1 = new ArrayList();
75-
PropertyInfo[] infoArray1 = this.GetProperties();
76-
for(int num1 = 0; num1 < infoArray1.Length; num1++)
64+
PropertyInfo[] properties = typeof(Cursors).GetProperties(BindingFlags.Public | BindingFlags.Static);
65+
object[] values = new object[properties.Length]; //Could use Cursor but its wrapped in ICollection anyways
66+
67+
for (int i = 0; i < properties.Length; i++)
7768
{
78-
PropertyInfo info1 = infoArray1[num1];
79-
object[] objArray1 = null;
80-
list1.Add(info1.GetValue(null, objArray1));
69+
PropertyInfo info = properties[i];
70+
71+
values[i] = info.GetValue(null, null);
8172
}
82-
this._standardValues = new TypeConverter.StandardValuesCollection(list1.ToArray());
73+
74+
_standardValues = new TypeConverter.StandardValuesCollection(values);
8375
}
84-
return this._standardValues;
76+
77+
return _standardValues;
8578
}
8679

8780
/// <summary>

0 commit comments

Comments
 (0)