[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:
parent
2b3a4c578a
commit
747d86bafb
1 changed files with 12 additions and 1 deletions
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue