[Common] Avoid GC in DeviceCollection

`DeviceCollection.GetEnumerator()` now returns a struct IEnumerable<T>
directly to avoid boxing.

Additionally, we can now use `DeviceCollection[int]` as a shortcut to
`FromIndex(int)`.
This commit is contained in:
thefiddler 2014-09-20 17:10:05 +02:00
parent 2b3a4c578a
commit 747d86bafb

View file

@ -46,7 +46,7 @@ namespace OpenTK.Platform
#region IEnumerable<T> Members
public IEnumerator<T> GetEnumerator()
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return Devices.GetEnumerator();
}
@ -64,6 +64,17 @@ namespace OpenTK.Platform
#region Public Members
// This avoids boxing when using foreach loops
public List<T>.Enumerator GetEnumerator()
{
return Devices.GetEnumerator();
}
public T this[int index]
{
get { return FromIndex(index); }
}
/// \internal
/// <summary>
/// Adds or replaces a device based on its hardware id.