rust/kernel/list.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
"List::is_empty()" provides a straight forward convention to check
whether a given "List" is empty or not. There're numerous places in the
current implementation still use "self.first.is_null()" to perform the
equivalent check, replace them with "List::is_empty()".
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
---
rust/kernel/list.rs | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/rust/kernel/list.rs b/rust/kernel/list.rs
index fb93330f4af4..8f3919bd3f99 100644
--- a/rust/kernel/list.rs
+++ b/rust/kernel/list.rs
@@ -259,7 +259,7 @@ pub fn push_back(&mut self, item: ListArc<T, ID>) {
// SAFETY: We have not yet called `post_remove`, so `list_links` is still valid.
let item = unsafe { ListLinks::fields(list_links) };
- if self.first.is_null() {
+ if self.is_empty() {
self.first = item;
// SAFETY: The caller just gave us ownership of these fields.
// INVARIANT: A linked list with one item should be cyclic.
@@ -299,7 +299,7 @@ pub fn push_front(&mut self, item: ListArc<T, ID>) {
// SAFETY: We have not yet called `post_remove`, so `list_links` is still valid.
let item = unsafe { ListLinks::fields(list_links) };
- if self.first.is_null() {
+ if self.is_empty() {
// SAFETY: The caller just gave us ownership of these fields.
// INVARIANT: A linked list with one item should be cyclic.
unsafe {
@@ -325,7 +325,7 @@ pub fn push_front(&mut self, item: ListArc<T, ID>) {
/// Removes the last item from this list.
pub fn pop_back(&mut self) -> Option<ListArc<T, ID>> {
- if self.first.is_null() {
+ if self.is_empty() {
return None;
}
@@ -337,7 +337,7 @@ pub fn pop_back(&mut self) -> Option<ListArc<T, ID>> {
/// Removes the first item from this list.
pub fn pop_front(&mut self) -> Option<ListArc<T, ID>> {
- if self.first.is_null() {
+ if self.is_empty() {
return None;
}
@@ -493,7 +493,7 @@ pub fn push_all_back(&mut self, other: &mut List<T, ID>) {
///
/// If the list is empty, this returns `None`.
pub fn cursor_front(&mut self) -> Option<Cursor<'_, T, ID>> {
- if self.first.is_null() {
+ if self.is_empty() {
None
} else {
Some(Cursor {
--
2.43.0
On Mon Mar 10, 2025 at 8:38 AM CET, I Hsin Cheng wrote: > "List::is_empty()" provides a straight forward convention to check > whether a given "List" is empty or not. There're numerous places in the > current implementation still use "self.first.is_null()" to perform the > equivalent check, replace them with "List::is_empty()". > > Signed-off-by: I Hsin Cheng <richard120310@gmail.com> > --- > rust/kernel/list.rs | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) Reviewed-by: Benno Lossin <lossin@kernel.org> --- Cheers, Benno
On Thu, May 22, 2025 at 11:53 AM Benno Lossin <lossin@kernel.org> wrote: > > Reviewed-by: Benno Lossin <lossin@kernel.org> Added :) Cheers, Miguel
On Mon, 10 Mar 2025 15:38:52 +0800 I Hsin Cheng <richard120310@gmail.com> wrote:
>
> "List::is_empty()" provides a straight forward convention to check
> whether a given "List" is empty or not. There're numerous places in the
> current implementation still use "self.first.is_null()" to perform the
> equivalent check, replace them with "List::is_empty()".
>
> Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
Applied to `rust-next` -- thanks!
[ Rebased dropping the cases that do not apply anymore. - Miguel ]
Cheers,
Miguel
On Mon, 10 Mar 2025 15:38:52 +0800 I Hsin Cheng <richard120310@gmail.com> wrote: > > "List::is_empty()" provides a straight forward convention to check > whether a given "List" is empty or not. There're numerous places in the > current implementation still use "self.first.is_null()" to perform the > equivalent check, replace them with "List::is_empty()". > > Signed-off-by: I Hsin Cheng <richard120310@gmail.com> There are a couple cases that still apply here (i.e. after the cursor between elements change), so I will pick it up. By the way, for some reason, your email did not reach my inbox. Thanks! Cheers, Miguel
© 2016 - 2025 Red Hat, Inc.