diff --git a/posts/2015-11-15-allocating-frames.md b/posts/2015-11-15-allocating-frames.md index 49ffc2f1..1e285443 100644 --- a/posts/2015-11-15-allocating-frames.md +++ b/posts/2015-11-15-allocating-frames.md @@ -301,7 +301,7 @@ fn choose_next_area(&mut self) { self.current_area = self.areas.clone().filter(|area| { let address = area.base_addr + area.length - 1; Frame::containing_address(address as usize) >= self.next_free_frame - }).min_by(|area| area.base_addr); + }).min_by_key(|area| area.base_addr); if let Some(area) = self.current_area { let start_frame = Frame::containing_address(area.base_addr as usize); @@ -311,9 +311,9 @@ fn choose_next_area(&mut self) { } } ``` -This function chooses the area with the minimal base address that still has free frames, i.e. `next_free_frame` is smaller than its last frame. Note that we need to clone the iterator because the [min_by] function consumes it. If there are no areas with free frames left, `min_by` automatically returns the desired `None`. +This function chooses the area with the minimal base address that still has free frames, i.e. `next_free_frame` is smaller than its last frame. Note that we need to clone the iterator because the [min_by_key] function consumes it. If there are no areas with free frames left, `min_by_key` automatically returns the desired `None`. -[min_by]: https://doc.rust-lang.org/nightly/core/iter/trait.Iterator.html#method.min_by +[min_by_key]: https://doc.rust-lang.org/nightly/core/iter/trait.Iterator.html#method.min_by_key If the `next_free_frame` is below the new `current_area`, it needs to be updated to the area's start frame. Else, the `allocate_frame` call could return an unavailable frame. diff --git a/src/memory/area_frame_allocator.rs b/src/memory/area_frame_allocator.rs index 86563e63..99dbadc7 100644 --- a/src/memory/area_frame_allocator.rs +++ b/src/memory/area_frame_allocator.rs @@ -37,7 +37,7 @@ impl AreaFrameAllocator { self.current_area = self.areas.clone().filter(|area| { let address = area.base_addr + area.length - 1; Frame::containing_address(address as usize) >= self.next_free_frame - }).min_by(|area| area.base_addr); + }).min_by_key(|area| area.base_addr); if let Some(area) = self.current_area { let start_frame = Frame::containing_address(area.base_addr as usize);