]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
rust: list: Use "List::is_empty()" to perform checking when possible
authorI Hsin Cheng <richard120310@gmail.com>
Mon, 10 Mar 2025 07:38:52 +0000 (15:38 +0800)
committerMiguel Ojeda <ojeda@kernel.org>
Thu, 22 May 2025 10:00:37 +0000 (12:00 +0200)
"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>
Link: https://lore.kernel.org/r/20250310073853.427954-1-richard120310@gmail.com
Reviewed-by: Benno Lossin <lossin@kernel.org>
[ Rebased dropping the cases that do not apply anymore. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/kernel/list.rs

index a335c3b1ff5e48c246d3a771a2c3c750a4138419..7740c8f16cf6a553545d709ba8c109b363a7f619 100644 (file)
@@ -319,7 +319,7 @@ impl<T: ?Sized + ListItem<ID>, const ID: u64> List<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;
         }
 
@@ -331,7 +331,7 @@ impl<T: ?Sized + ListItem<ID>, const ID: u64> List<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;
         }