Commit c1f39437 authored by Teodor Sigaev's avatar Teodor Sigaev

Some optimizations by Volkan YAZICI <yazicivo@ttnet.net.tr>

parent 10dd8df6
......@@ -83,8 +83,6 @@ _int_same(PG_FUNCTION_ARGS)
if (avoid || bvoid)
return (avoid && bvoid) ? TRUE : FALSE;
SORT(a);
SORT(b);
na = ARRNELEMS(a);
nb = ARRNELEMS(b);
da = ARRPTR(a);
......@@ -94,7 +92,10 @@ _int_same(PG_FUNCTION_ARGS)
if (na == nb)
{
SORT(a);
SORT(b);
result = TRUE;
for (n = 0; n < na; n++)
if (da[n] != db[n])
{
......
......@@ -34,7 +34,7 @@ inner_int_contains(ArrayType *a, ArrayType *b)
j++;
}
else
j++;
break;
return (n == nb) ? TRUE : FALSE;
}
......@@ -76,13 +76,6 @@ ArrayType *
inner_int_union(ArrayType *a, ArrayType *b)
{
ArrayType *r = NULL;
int na,
nb;
int *da,
*db,
*dr;
int i,
j;
CHECKARRVALID(a);
CHECKARRVALID(b);
......@@ -94,31 +87,35 @@ inner_int_union(ArrayType *a, ArrayType *b)
if (ARRISVOID(b))
r = copy_intArrayType(a);
if (r)
dr = ARRPTR(r);
else
if (!r)
{
na = ARRNELEMS(a);
int na = ARRNELEMS(a),
nb = ARRNELEMS(b);
da = ARRPTR(a);
db = ARRPTR(b);
int *da = ARRPTR(a),
*db = ARRPTR(b);
int i,j, *dr;
r = new_intArrayType(na + nb);
dr = ARRPTR(r);
/* union */
i = j = 0;
while (i < na && j < nb)
if (da[i] < db[j])
while (i < na && j < nb) {
if (da[i] == db[j]) {
*dr++ = da[i++];
j++;
} else if (da[i] < db[j])
*dr++ = da[i++];
else
*dr++ = db[j++];
}
while (i < na)
*dr++ = da[i++];
while (j < nb)
*dr++ = db[j++];
r = resize_intArrayType(r, dr-ARRPTR(r));
}
if (ARRNELEMS(r) > 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment