Skip to content

Commit 4d371d9

Browse files
committed
Remove an unnecessary loop in snapshot merging procedure.
1 parent 0335888 commit 4d371d9

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

contrib/pg_xtm/pg_dtm.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static bool TransactionIdIsInDoubt(TransactionId xid)
146146

147147
static void DtmMergeSnapshots(Snapshot dst, Snapshot src)
148148
{
149-
int i, j, n;
149+
int i, j;
150150
TransactionId xid;
151151

152152
Assert(TransactionIdIsValid(src->xmin) && TransactionIdIsValid(src->xmax));
@@ -173,20 +173,17 @@ static void DtmMergeSnapshots(Snapshot dst, Snapshot src)
173173
//MyPgXact->xmin = TransactionXmin = src->xmin;
174174
}
175175
if (src->xmax < dst->xmax) dst->xmax = src->xmax;
176+
// concatenate two active lists
177+
memcpy(dst->xip + dst->xcnt, src->xip, src->xcnt*sizeof(TransactionId));
178+
dst->xcnt += src->xcnt;
179+
Assert(dst->xcnt <= GetMaxSnapshotXidCount());
176180

177-
178-
n = dst->xcnt;
179-
for (xid = dst->xmax; xid <= src->xmin; xid++) {
180-
dst->xip[n++] = xid;
181-
}
182-
memcpy(dst->xip + n, src->xip, src->xcnt*sizeof(TransactionId));
183-
n += src->xcnt;
184-
Assert(n <= GetMaxSnapshotXidCount());
185-
186-
qsort(dst->xip, n, sizeof(TransactionId), xidComparator);
181+
// sort the list
182+
qsort(dst->xip, dst->xcnt, sizeof(TransactionId), xidComparator);
187183
xid = InvalidTransactionId;
188184

189-
for (i = 0, j = 0; i < n && dst->xip[i] < dst->xmax; i++) {
185+
// remove duplicates
186+
for (i = 0, j = 0; i < dst->xcnt && dst->xip[i] < dst->xmax; i++) {
190187
if (dst->xip[i] != xid) {
191188
dst->xip[j++] = xid = dst->xip[i];
192189
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy