|
5 | 5 | //! C header: [`include/linux/xarray.h`](srctree/include/linux/xarray.h) |
6 | 6 |
|
7 | 7 | use crate::{ |
8 | | - alloc, bindings, build_assert, |
9 | | - error::{Error, Result}, |
| 8 | + alloc, |
| 9 | + prelude::*, |
10 | 10 | types::{ForeignOwnable, NotThreadSafe, Opaque}, |
11 | 11 | }; |
12 | | -use core::{iter, marker::PhantomData, mem, pin::Pin, ptr::NonNull}; |
13 | | -use pin_init::{pin_data, pin_init, pinned_drop, PinInit}; |
| 12 | +use core::{iter, marker::PhantomData, mem, ptr::NonNull}; |
14 | 13 |
|
15 | 14 | /// An array which efficiently maps sparse integer indices to owned objects. |
16 | 15 | /// |
17 | | -/// This is similar to a [`crate::alloc::kvec::Vec<Option<T>>`], but more efficient when there are |
| 16 | +/// This is similar to a [`Vec<Option<T>>`], but more efficient when there are |
18 | 17 | /// holes in the index space, and can be efficiently grown. |
19 | 18 | /// |
20 | 19 | /// # Invariants |
@@ -104,16 +103,23 @@ impl<T: ForeignOwnable> XArray<T> { |
104 | 103 | fn iter(&self) -> impl Iterator<Item = NonNull<T::PointedTo>> + '_ { |
105 | 104 | let mut index = 0; |
106 | 105 |
|
107 | | - // SAFETY: `self.xa` is always valid by the type invariant. |
108 | | - iter::once(unsafe { |
109 | | - bindings::xa_find(self.xa.get(), &mut index, usize::MAX, bindings::XA_PRESENT) |
110 | | - }) |
111 | | - .chain(iter::from_fn(move || { |
| 106 | + core::iter::Iterator::chain( |
112 | 107 | // SAFETY: `self.xa` is always valid by the type invariant. |
113 | | - Some(unsafe { |
114 | | - bindings::xa_find_after(self.xa.get(), &mut index, usize::MAX, bindings::XA_PRESENT) |
115 | | - }) |
116 | | - })) |
| 108 | + iter::once(unsafe { |
| 109 | + bindings::xa_find(self.xa.get(), &mut index, usize::MAX, bindings::XA_PRESENT) |
| 110 | + }), |
| 111 | + iter::from_fn(move || { |
| 112 | + // SAFETY: `self.xa` is always valid by the type invariant. |
| 113 | + Some(unsafe { |
| 114 | + bindings::xa_find_after( |
| 115 | + self.xa.get(), |
| 116 | + &mut index, |
| 117 | + usize::MAX, |
| 118 | + bindings::XA_PRESENT, |
| 119 | + ) |
| 120 | + }) |
| 121 | + }), |
| 122 | + ) |
117 | 123 | .map_while(|ptr| NonNull::new(ptr.cast())) |
118 | 124 | } |
119 | 125 |
|
|
0 commit comments