add more methods to Assets for clearing and allocation reduction (#669)

This commit is contained in:
Joshua J. Bouw 2020-10-13 00:21:28 +07:00 committed by GitHub
parent 32b122e1c5
commit 036b3bc0e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -104,6 +104,28 @@ impl<T: Resource> Assets<T> {
self.assets.remove(&handle)
}
/// Clears the inner asset map, removing all key-value pairs.
///
/// Keeps the allocated memory for reuse.
pub fn clear(&mut self) {
self.assets.clear()
}
/// Reserves capacity for at least additional more elements to be inserted into the assets.
///
/// The collection may reserve more space to avoid frequent reallocations.
pub fn reserve(&mut self, additional: usize) {
self.assets.reserve(additional)
}
/// Shrinks the capacity of the asset map as much as possible.
///
/// It will drop down as much as possible while maintaining the internal rules and possibly
/// leaving some space in accordance with the resize policy.
pub fn shrink_to_fit(&mut self) {
self.assets.shrink_to_fit()
}
pub fn asset_event_system(
mut events: ResMut<Events<AssetEvent<T>>>,
mut assets: ResMut<Assets<T>>,