summaryrefslogtreecommitdiff
path: root/contrib/intarray/_int_tool.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/intarray/_int_tool.c')
-rw-r--r--contrib/intarray/_int_tool.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c
index 79f018d333b..132d1531605 100644
--- a/contrib/intarray/_int_tool.c
+++ b/contrib/intarray/_int_tool.c
@@ -140,7 +140,8 @@ inner_int_inter(ArrayType *a, ArrayType *b)
*db,
*dr;
int i,
- j;
+ j,
+ k;
if (ARRISEMPTY(a) || ARRISEMPTY(b))
return new_intArrayType(0);
@@ -152,15 +153,15 @@ inner_int_inter(ArrayType *a, ArrayType *b)
r = new_intArrayType(Min(na, nb));
dr = ARRPTR(r);
- i = j = 0;
+ i = j = k = 0;
while (i < na && j < nb)
{
if (da[i] < db[j])
i++;
else if (da[i] == db[j])
{
- if (i + j == 0 || (i + j > 0 && *(dr - 1) != db[j]))
- *dr++ = db[j];
+ if (k == 0 || dr[k - 1] != db[j])
+ dr[k++] = db[j];
i++;
j++;
}
@@ -168,13 +169,13 @@ inner_int_inter(ArrayType *a, ArrayType *b)
j++;
}
- if ((dr - ARRPTR(r)) == 0)
+ if (k == 0)
{
pfree(r);
return new_intArrayType(0);
}
else
- return resize_intArrayType(r, dr - ARRPTR(r));
+ return resize_intArrayType(r, k);
}
void