@@ -46,6 +46,17 @@ pub trait RelationshipSourceCollection {
46
46
fn is_empty ( & self ) -> bool {
47
47
self . len ( ) == 0
48
48
}
49
+
50
+ /// Add multiple entities to collection at once.
51
+ ///
52
+ /// May be faster than repeatedly calling [`Self::add`].
53
+ fn extend_from_iter ( & mut self , entities : impl IntoIterator < Item = Entity > ) {
54
+ // The method name shouldn't conflict with `Extend::extend` as it's in the rust prelude and
55
+ // would always conflict with it.
56
+ for entity in entities {
57
+ self . add ( entity) ;
58
+ }
59
+ }
49
60
}
50
61
51
62
impl RelationshipSourceCollection for Vec < Entity > {
@@ -82,6 +93,10 @@ impl RelationshipSourceCollection for Vec<Entity> {
82
93
fn clear ( & mut self ) {
83
94
self . clear ( ) ;
84
95
}
96
+
97
+ fn extend_from_iter ( & mut self , entities : impl IntoIterator < Item = Entity > ) {
98
+ self . extend ( entities) ;
99
+ }
85
100
}
86
101
87
102
impl RelationshipSourceCollection for EntityHashSet {
@@ -112,6 +127,10 @@ impl RelationshipSourceCollection for EntityHashSet {
112
127
fn clear ( & mut self ) {
113
128
self . 0 . clear ( ) ;
114
129
}
130
+
131
+ fn extend_from_iter ( & mut self , entities : impl IntoIterator < Item = Entity > ) {
132
+ self . extend ( entities) ;
133
+ }
115
134
}
116
135
117
136
impl < const N : usize > RelationshipSourceCollection for SmallVec < [ Entity ; N ] > {
@@ -148,6 +167,10 @@ impl<const N: usize> RelationshipSourceCollection for SmallVec<[Entity; N]> {
148
167
fn clear ( & mut self ) {
149
168
self . clear ( ) ;
150
169
}
170
+
171
+ fn extend_from_iter ( & mut self , entities : impl IntoIterator < Item = Entity > ) {
172
+ self . extend ( entities) ;
173
+ }
151
174
}
152
175
153
176
impl RelationshipSourceCollection for Entity {
@@ -187,6 +210,12 @@ impl RelationshipSourceCollection for Entity {
187
210
fn clear ( & mut self ) {
188
211
* self = Entity :: PLACEHOLDER ;
189
212
}
213
+
214
+ fn extend_from_iter ( & mut self , entities : impl IntoIterator < Item = Entity > ) {
215
+ if let Some ( entity) = entities. into_iter ( ) . last ( ) {
216
+ * self = entity;
217
+ }
218
+ }
190
219
}
191
220
192
221
#[ cfg( test) ]
0 commit comments