Choose more descriptive field names for ReserveEntitiesIterator (#15168)
				
					
				
			No hard feelings if you don't want to make this change. This is just something I stumbled over in my very first read of the `bevy_ecs` crate. # Objective - the general goal here is to improve DX slightly - make the code easier to read in general. The previous names make the code harder to read, especially since they are so similar. ## Solution - choose more specific names for the fields - `index_iter` -> `freelist_indices` : "freelist" is a well established term in the rest of the docs in this module, so we might want to reuse it - `index_range` -> `new_indices` : Nothing besides the doc comment stated that these indices were actually new/fresh ## Testing Note that the fields are private so that this is no breaking change. They are also only used in this one module.
This commit is contained in:
		
							parent
							
								
									4742f74fc4
								
							
						
					
					
						commit
						5484d2d6f8
					
				| @ -450,26 +450,26 @@ pub struct ReserveEntitiesIterator<'a> { | |||||||
|     meta: &'a [EntityMeta], |     meta: &'a [EntityMeta], | ||||||
| 
 | 
 | ||||||
|     // Reserved indices formerly in the freelist to hand out.
 |     // Reserved indices formerly in the freelist to hand out.
 | ||||||
|     index_iter: std::slice::Iter<'a, u32>, |     freelist_indices: std::slice::Iter<'a, u32>, | ||||||
| 
 | 
 | ||||||
|     // New Entity indices to hand out, outside the range of meta.len().
 |     // New Entity indices to hand out, outside the range of meta.len().
 | ||||||
|     index_range: std::ops::Range<u32>, |     new_indices: std::ops::Range<u32>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl<'a> Iterator for ReserveEntitiesIterator<'a> { | impl<'a> Iterator for ReserveEntitiesIterator<'a> { | ||||||
|     type Item = Entity; |     type Item = Entity; | ||||||
| 
 | 
 | ||||||
|     fn next(&mut self) -> Option<Self::Item> { |     fn next(&mut self) -> Option<Self::Item> { | ||||||
|         self.index_iter |         self.freelist_indices | ||||||
|             .next() |             .next() | ||||||
|             .map(|&index| { |             .map(|&index| { | ||||||
|                 Entity::from_raw_and_generation(index, self.meta[index as usize].generation) |                 Entity::from_raw_and_generation(index, self.meta[index as usize].generation) | ||||||
|             }) |             }) | ||||||
|             .or_else(|| self.index_range.next().map(Entity::from_raw)) |             .or_else(|| self.new_indices.next().map(Entity::from_raw)) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn size_hint(&self) -> (usize, Option<usize>) { |     fn size_hint(&self) -> (usize, Option<usize>) { | ||||||
|         let len = self.index_iter.len() + self.index_range.len(); |         let len = self.freelist_indices.len() + self.new_indices.len(); | ||||||
|         (len, Some(len)) |         (len, Some(len)) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @ -589,8 +589,8 @@ impl Entities { | |||||||
| 
 | 
 | ||||||
|         ReserveEntitiesIterator { |         ReserveEntitiesIterator { | ||||||
|             meta: &self.meta[..], |             meta: &self.meta[..], | ||||||
|             index_iter: self.pending[freelist_range].iter(), |             freelist_indices: self.pending[freelist_range].iter(), | ||||||
|             index_range: new_id_start..new_id_end, |             new_indices: new_id_start..new_id_end, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Robert Walter
						Robert Walter