Skip to content

Commit 980e69d

Browse files
committed
instances: Iterator::collect() instances
1 parent 30e5567 commit 980e69d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

node-graph/gcore/src/instances.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ impl<T> Instances<T> {
2727
}
2828
}
2929

30+
pub fn with_capacity(capacity: usize) -> Self {
31+
Self {
32+
instance: Vec::with_capacity(capacity),
33+
transform: Vec::with_capacity(capacity),
34+
alpha_blending: Vec::with_capacity(capacity),
35+
source_node_id: Vec::with_capacity(capacity),
36+
}
37+
}
38+
3039
pub fn push(&mut self, instance: Instance<T>) {
3140
self.instance.push(instance.instance);
3241
self.transform.push(instance.transform);
@@ -161,6 +170,18 @@ unsafe impl<T: StaticType + 'static> StaticType for Instances<T> {
161170
type Static = Instances<T>;
162171
}
163172

173+
impl<T> FromIterator<Instance<T>> for Instances<T> {
174+
fn from_iter<I: IntoIterator<Item = Instance<T>>>(iter: I) -> Self {
175+
let iter = iter.into_iter();
176+
let (lower, _) = iter.size_hint();
177+
let mut instances = Self::with_capacity(lower);
178+
for instance in iter {
179+
instances.push(instance);
180+
}
181+
instances
182+
}
183+
}
184+
164185
fn one_daffine2_default() -> Vec<DAffine2> {
165186
vec![DAffine2::IDENTITY]
166187
}

0 commit comments

Comments
 (0)