From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FC4122A7E1 for ; Thu, 20 Mar 2025 22:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742509330; cv=none; b=oZCyxvkFSloSs1vdgOEeLojE9k4WP3PsXSZYIKD04cXIcX9bhPY9rU6jQFKIRBnTh+0QILdOvAPL4gVJIpsqJKRjozzUea/Gk92sfW2NNLzNTrhqIS6lDq9FZs4V9lYpeRc+yAfGb1Vq8wjljNKVAuY7/jNovpXTVgjJpJ+qYRA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742509330; c=relaxed/simple; bh=/9IupfoS+aiHJcuUOULQMXT2HMqYQt1igYXUTT8eIEo=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=fNv16pJHHaJrrF2oif/28iJqJkxZduysG0Etwo6Z5I1AlfGItaNdACHNVe0B1oM6XvqvTCARKQoNC9CztJZSbKoCQGq4/KTOf8QeGTeoXlCMvZczg4KiKkclfoqpWwLT32X+z/mX7JN49woz57Xn4hYcIlfu8RAV+8sVKSZzDvE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=d6T5yEly; arc=none smtp.client-ip=185.70.40.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="d6T5yEly" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1742509321; x=1742768521; bh=TrJztFCk8Z9fLwx377hSlrUS+2GuthUOlCSMAdqQEjU=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=d6T5yElyaFIeWZTPgB9GjHR5MGtP1o4kjzRyT/gEJcJGNaS4mgNt88Uc3PMoljR6r 6suzLqO2n92vFu0d3cY77he8yofRl/2VQpw6wF242f4Xzz/7SunZisJOO4033D+9xv lxFfW3CMYhTAXEToQmRu/iTWqv13n5CxAFA+VQDrBdsFFBk8uRNwAZVRpQYgOlOC99 vkOobpj9kJ4t0Tt7kbasld0WLtOJRY3AV45kvrKnTkemJhlkpRUkGrJU4zZ8cHpmfr 5A/efeZOI4gm7EbxK0IAvDAxwkjfvatC6ZYVhIVf89ljYs+WZe3yyXEvKTpbSPqKdw Iodqm5xbSCnXw== Date: Thu, 20 Mar 2025 22:21:56 +0000 To: Alice Ryhl , Danilo Krummrich From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/5] rust: alloc: add Vec::retain Message-ID: Feedback-ID: 71780778:user:proton X-Pm-Message-ID: eb9a79e14a0a7ed328c405e7c699b82953c5a550 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu Mar 20, 2025 at 2:53 PM CET, Alice Ryhl wrote: > diff --git a/rust/kernel/alloc/kvec.rs b/rust/kernel/alloc/kvec.rs > index 303198509885f5e24b74da5a92382b518de3e1c0..00dabea8ea6c8a742a7fc9595= 4d8de58be124493 100644 > --- a/rust/kernel/alloc/kvec.rs > +++ b/rust/kernel/alloc/kvec.rs > @@ -588,6 +588,20 @@ pub fn drain_all(&mut self) -> DrainAll<'_, T> { > elements: self.spare_capacity_mut()[..len].iter_mut(), > } > } > + > + /// Removes all elements that don't match the provided closure. Can you also add an example here? Otherwise the code looks good. --- Cheers, Benno > + pub fn retain(&mut self, mut f: impl FnMut(&mut T) -> bool) { > + let mut num_kept =3D 0; > + let mut next_to_check =3D 0; > + while let Some(to_check) =3D self.get_mut(next_to_check) { > + if f(to_check) { > + self.swap(num_kept, next_to_check); > + num_kept +=3D 1; > + } > + next_to_check +=3D 1; > + } > + self.truncate(num_kept); > + } > } > =20 > impl Vec {