@@ -146,7 +146,7 @@ static bool TransactionIdIsInDoubt(TransactionId xid)
146
146
147
147
static void DtmMergeSnapshots (Snapshot dst , Snapshot src )
148
148
{
149
- int i , j , n ;
149
+ int i , j ;
150
150
TransactionId xid ;
151
151
152
152
Assert (TransactionIdIsValid (src -> xmin ) && TransactionIdIsValid (src -> xmax ));
@@ -173,20 +173,17 @@ static void DtmMergeSnapshots(Snapshot dst, Snapshot src)
173
173
//MyPgXact->xmin = TransactionXmin = src->xmin;
174
174
}
175
175
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 ());
176
180
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 );
187
183
xid = InvalidTransactionId ;
188
184
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 ++ ) {
190
187
if (dst -> xip [i ] != xid ) {
191
188
dst -> xip [j ++ ] = xid = dst -> xip [i ];
192
189
}
0 commit comments