-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Penumbra] Optimize adding points to a hull
- Loading branch information
1 parent
5fe346f
commit 4d29721
Showing
7 changed files
with
102 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Penumbra.Utilities; | ||
using System.Collections.Generic; | ||
|
||
namespace Penumbra | ||
{ | ||
/// <summary> | ||
/// Provides extension methods for various types. | ||
/// </summary> | ||
public static class Extensions | ||
{ | ||
/// <summary> | ||
/// Adds the elements of the specified collection to the end of the <see cref="IList{T}"/>. | ||
/// </summary> | ||
/// <typeparam name="T">Type of collection elements.</typeparam> | ||
/// <param name="listInterface">The <see cref="IList{T}"/> to add elements to.</param> | ||
/// <param name="collection"> | ||
/// The collection whose elements should be added to the end of the <see cref="IList{T}"/>. | ||
/// The collection itself cannot be <c>null</c>, but it can contain elements that are | ||
/// <c>null</c>, if type <typeparamref name="T"/> is a reference type. | ||
/// </param> | ||
public static void AddRange<T>(this IList<T> listInterface, IEnumerable<T> collection) | ||
{ | ||
// Use fast path in case of extended observable collection. | ||
var extendedObservableCollection = listInterface as ExtendedObservableCollection<T>; | ||
if (extendedObservableCollection != null) | ||
{ | ||
extendedObservableCollection.AddRange(collection); | ||
return; | ||
} | ||
|
||
// Use fast path in case of list. | ||
var list = listInterface as List<T>; | ||
if (list != null) | ||
{ | ||
list.AddRange(collection); | ||
return; | ||
} | ||
|
||
// Fallback to iterative add. | ||
foreach (T item in collection) | ||
listInterface.Add(item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters