From nobody Sat Feb 7 23:12:16 2026 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FEBB26AC1 for ; Fri, 23 Aug 2024 07:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724398644; cv=none; b=Y0z6nPj8kehwEMLzQ2zqT/Y18uekb2TOPjNIOFB58bjDnKk4O41aA7AWyIRe4rprxkq6yl7bX4Abj9gARmd5X/mCPezqGLjS8LjsZ1Fr7UIVXqJepw4Y1cJyyDiiQA2ADUpFTE27THGd0rf6RRG/bfbYXJ3Vi5ka547KP9XNS8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724398644; c=relaxed/simple; bh=G+V4EEePfeLVgzmqyuUsKexrHd+H4A4sfrV318W5QD0=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=uuXRP22gMzcdQun+Vln92aSo5l9bkN3fp4JufJrb05XHEn4SWnNIVGM7pUdUueBMEBRwleBpebFTmwhz2ftJjPsTlw79v86aSrLq9T/ZAZ4AYYQPRbpBDM4IKdukEMSBQ3Pxbr92G7Gdzq6Y2iWObKP74C9B7mvnzqxnNVUi2gI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gYvKz/xc; arc=none smtp.client-ip=209.85.214.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gYvKz/xc" Received: by mail-pl1-f194.google.com with SMTP id d9443c01a7336-20227ba378eso15074465ad.0 for ; Fri, 23 Aug 2024 00:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724398642; x=1725003442; darn=vger.kernel.org; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=IwdGusPFdheswVn42reak48rV6CoMS6cSkMLL55sAus=; b=gYvKz/xcSFVFNkyg/KIt3/0XbhxdtJ7FUmFzfb/YvGb+Yvs+KyEhVGC+GPrDbqOV/y Ct31GW8ogkdlgwXlcbfzWOQj0zTMyBgEO6YB1v5RhoN7+6/OwM7SRWEK4e9x9I/1/TwG LugXrKTBGohRYRf4nzlTl31s97zTJf+BKZXLoYOH2PTw5Xl7onLu9OQCEpsG1RMrwPFz 2FPEF8GNM+983Vm22BXe8SwustHNyHzJt+SSjfNWGVUtGoGSQP1o+YDHryZxAoT2/9lw F2vmzzh4H+RvafYZ7FbQKNv/VtNvYfcwUT+iHb7DMWOWMA+QhvhSlRNKndB/9PEDtREW WuZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724398642; x=1725003442; h=user-agent:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IwdGusPFdheswVn42reak48rV6CoMS6cSkMLL55sAus=; b=nHuSnqoCwuiW3yzZeDA4CSq5RSSBOQ65pmnOZlkdB4QexpDIS6VyarThZzqOdE7cI7 82/SIbjriW8OoJ9AdVbro9YlwDGffTzkrfiv/ktfJjIp4QYGXF1/Y4OvdN+c5djIJ8hD 4c3sIfrAPGunzcHs6A/gDgqm2difvNSoWw4hXLkM9QHGjNDfIJ16PTKc17NgJVy9AmrZ iyxaaauzNEIHgsB80AeoDW2NSQ3YV9uLmxQPW822fl4+6DHIRDD59w9F50aAX3rL3UNf HJlfumSAZKmUfTINwYLFt5VcSVyCxTdpa7dVMWXBq+RsNhFvvOoKz97ZSWS4WrOVqZ6C 4M4w== X-Forwarded-Encrypted: i=1; AJvYcCWmmCNcesuXqBNS44upuVaFpgPSxQO9M44tprLU/BMn3nyA4ZdbtfefI37uQX4drk4dckgoqiGRKl/ejOw=@vger.kernel.org X-Gm-Message-State: AOJu0Yw12XaCTe7iKA/UiFvFIZcdYIDph2yRJsFkoizOKrUxWRHQm6Qu kID86niyco4Kcz6hzvYAcFpEVFcDqr5U2kkr75ghDLG6q3ztIVyp X-Google-Smtp-Source: AGHT+IFPmO8ObNG7L/0IxjwHyS1ESRZJe1yyTGzbcnUCkT8bWbcp1Qww/ORuUHG1xrFv7pJzmQjVRg== X-Received: by 2002:a17:902:e804:b0:202:3432:230c with SMTP id d9443c01a7336-2039e46a37fmr11633475ad.18.1724398642421; Fri, 23 Aug 2024 00:37:22 -0700 (PDT) Received: from systemsresearch.io ([2a01:7e03::f03c:91ff:fe02:b162]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20385ae4f62sm22979485ad.256.2024.08.23.00.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Aug 2024 00:37:21 -0700 (PDT) Date: Fri, 23 Aug 2024 07:37:19 +0000 From: Hao Li To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, maple-tree@lists.infradead.org, haoli.tcs@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH] maple_tree: simplify mas_wr_node_walk for improved readability Message-ID: <20240823073719.GA18274@systemsresearch.io> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Refactor mas_wr_node_walk to make the code more clear and easier to understand. The main changes are: 1. Replace the forward-iterating loop with a backward-iterating loop. This simplifies the logic for determining the correct range containing mas->index. 2. Eliminate the ternary operator. The new implementation maintains the same functionality as before, but with improved readability. The performance characteristics remain essentially the same, as we cannot predict which interval mas->index will fall into. Signed-off-by: Hao Li --- lib/maple_tree.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index fe1b01b29..a180f54f5 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2213,16 +2213,14 @@ static inline void mas_wr_node_walk(struct ma_wr_st= ate *wr_mas) =20 wr_mas->node =3D mas_mn(wr_mas->mas); wr_mas->pivots =3D ma_pivots(wr_mas->node, wr_mas->type); - count =3D mas->end =3D ma_data_end(wr_mas->node, wr_mas->type, + mas->end =3D ma_data_end(wr_mas->node, wr_mas->type, wr_mas->pivots, mas->max); - offset =3D mas->offset; - - while (offset < count && mas->index > wr_mas->pivots[offset]) - offset++; - - wr_mas->r_max =3D offset < count ? wr_mas->pivots[offset] : mas->max; - wr_mas->r_min =3D mas_safe_min(mas, wr_mas->pivots, offset); - wr_mas->offset_end =3D mas->offset =3D offset; + wr_mas->r_max =3D mas->max; + idx =3D mas->end - 1; + while (idx >=3D mas->offset && wr_mas->pivots[idx] >=3D mas->index) + wr_mas->r_max =3D wr_mas->pivots[idx--]; + wr_mas->offset_end =3D mas->offset =3D idx + 1; + wr_mas->r_min =3D mas_safe_min(mas, wr_mas->pivots, mas->offset); } =20 /* --=20 2.21.0