From 9211fa61513dcdbca273656454395a3dcf3ee4e7 Mon Sep 17 00:00:00 2001 From: Kyotaro Horiguchi Date: Thu, 20 Jan 2022 10:16:48 +0900 Subject: [PATCH] Improve confusing code in TransactionTreeSetCommitTsData TransactionTreeSetCommitTsData has a bit confusing use of the += operator. Simplifying it makes the code easier to follow. In the same function for-loop initializes only non-controlling variables, which is not great style. They ought to be initialized outside the loop. --- src/backend/access/transam/commit_ts.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/access/transam/commit_ts.c b/src/backend/access/transam/commit_ts.c index 659109f8d4..88eac10456 100644 --- a/src/backend/access/transam/commit_ts.c +++ b/src/backend/access/transam/commit_ts.c @@ -168,7 +168,10 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids, * subxid not on the previous page as head. This way, we only have to * lock/modify each SLRU page once. */ - for (i = 0, headxid = xid;;) + headxid = xid; + i = 0; + + for (;;) { int pageno = TransactionIdToCTsPage(headxid); int j; @@ -192,7 +195,7 @@ TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids, * just wrote. */ headxid = subxids[j]; - i += j - i + 1; + i = j + 1; } /* update the cached value in shared memory */ -- 2.27.0