mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-11 09:38:44 +08:00
[csharp] Avoiding reallocations in Animation ctor by adding all HashSet entries at once. Closes #1709.
This commit is contained in:
parent
46a0ffce50
commit
5b65f3f155
@ -43,9 +43,13 @@ namespace Spine {
|
||||
public Animation (string name, ExposedList<Timeline> timelines, float duration) {
|
||||
if (name == null) throw new ArgumentNullException("name", "name cannot be null.");
|
||||
if (timelines == null) throw new ArgumentNullException("timelines", "timelines cannot be null.");
|
||||
this.timelineIds = new HashSet<int>();
|
||||
foreach (Timeline timeline in timelines)
|
||||
timelineIds.Add(timeline.PropertyId);
|
||||
// Note: avoiding reallocations by adding all hash set entries at
|
||||
// once (EnsureCapacity() is only available in newer .Net versions).
|
||||
int[] propertyIDs = new int[timelines.Count];
|
||||
for (int i = 0; i < timelines.Count; ++i) {
|
||||
propertyIDs[i] = timelines.Items[i].PropertyId;
|
||||
}
|
||||
this.timelineIds = new HashSet<int>(propertyIDs);
|
||||
this.name = name;
|
||||
this.timelines = timelines;
|
||||
this.duration = duration;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user