rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible
@ 2025-03-10  7:38 I Hsin Cheng
  2025-05-21 15:23 ` Miguel Ojeda
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: I Hsin Cheng @ 2025-03-10  7:38 UTC (permalink / raw)
  To: ojeda
  Cc: alex.gaynor, boqun.feng, gary, bjorn3_gh, benno.lossin,
	a.hindborg, aliceryhl, tmgross, rust-for-linux, linux-kernel,
	skhan, linux-kernel-mentees, jserv, I Hsin Cheng

"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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-22 10:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10  7:38 [PATCH] rust: list: Use "List::is_empty()" to perform checking when possible I Hsin Cheng
2025-05-21 15:23 ` Miguel Ojeda
2025-05-22  9:47 ` Miguel Ojeda
2025-05-22  9:52 ` Benno Lossin
2025-05-22 10:01   ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).