mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* btree: fix merge logic to use btree_last() return value
@ 2025-08-22  8:58 Guan-Chun.Wu
  2025-08-25 16:54 ` Kuan-Wei Chiu
  0 siblings, 1 reply; 3+ messages in thread
From: Guan-Chun.Wu @ 2025-08-22  8:58 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Guan-Chun.Wu

Previously btree_merge() called btree_last() only to test existence,
then performed an extra btree_lookup() to fetch the value. This patch
changes it to directly use the value returned by btree_last(), avoiding
redundant lookups and simplifying the merge loop.

Signed-off-by: Guan-Chun.Wu <409411716@gms.tku.edu.tw>
---
 lib/btree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/btree.c b/lib/btree.c
index bb81d3393ac5..9c80c0c7bba8 100644
--- a/lib/btree.c
+++ b/lib/btree.c
@@ -653,9 +653,9 @@ int btree_merge(struct btree_head *target, struct btree_head *victim,
 	 * walks to remove a single object from the victim.
 	 */
 	for (;;) {
-		if (!btree_last(victim, geo, key))
+		val = btree_last(victim, geo, key);
+		if (!val)
 			break;
-		val = btree_lookup(victim, geo, key);
 		err = btree_insert(target, geo, key, val, gfp);
 		if (err)
 			return err;
-- 
2.34.1


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

end of thread, other threads:[~2025-08-26 16:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-22  8:58 btree: fix merge logic to use btree_last() return value Guan-Chun.Wu
2025-08-25 16:54 ` Kuan-Wei Chiu
2025-08-26 16:08   ` Guan-Chun Wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®