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) ...@@ -83,8 +83,6 @@ _int_same(PG_FUNCTION_ARGS)
if (avoid || bvoid) if (avoid || bvoid)
return (avoid && bvoid) ? TRUE : FALSE; return (avoid && bvoid) ? TRUE : FALSE;
SORT(a);
SORT(b);
na = ARRNELEMS(a); na = ARRNELEMS(a);
nb = ARRNELEMS(b); nb = ARRNELEMS(b);
da = ARRPTR(a); da = ARRPTR(a);
...@@ -94,7 +92,10 @@ _int_same(PG_FUNCTION_ARGS) ...@@ -94,7 +92,10 @@ _int_same(PG_FUNCTION_ARGS)
if (na == nb) if (na == nb)
{ {
SORT(a);
SORT(b);
result = TRUE; result = TRUE;
for (n = 0; n < na; n++) for (n = 0; n < na; n++)
if (da[n] != db[n]) if (da[n] != db[n])
{ {
......
...@@ -34,7 +34,7 @@ inner_int_contains(ArrayType *a, ArrayType *b) ...@@ -34,7 +34,7 @@ inner_int_contains(ArrayType *a, ArrayType *b)
j++; j++;
} }
else else
j++; break;
return (n == nb) ? TRUE : FALSE; return (n == nb) ? TRUE : FALSE;
} }
...@@ -76,13 +76,6 @@ ArrayType * ...@@ -76,13 +76,6 @@ ArrayType *
inner_int_union(ArrayType *a, ArrayType *b) inner_int_union(ArrayType *a, ArrayType *b)
{ {
ArrayType *r = NULL; ArrayType *r = NULL;
int na,
nb;
int *da,
*db,
*dr;
int i,
j;
CHECKARRVALID(a); CHECKARRVALID(a);
CHECKARRVALID(b); CHECKARRVALID(b);
...@@ -94,31 +87,35 @@ inner_int_union(ArrayType *a, ArrayType *b) ...@@ -94,31 +87,35 @@ inner_int_union(ArrayType *a, ArrayType *b)
if (ARRISVOID(b)) if (ARRISVOID(b))
r = copy_intArrayType(a); r = copy_intArrayType(a);
if (r) if (!r)
dr = ARRPTR(r);
else
{ {
na = ARRNELEMS(a); int na = ARRNELEMS(a),
nb = ARRNELEMS(b); nb = ARRNELEMS(b);
da = ARRPTR(a); int *da = ARRPTR(a),
db = ARRPTR(b); *db = ARRPTR(b);
int i,j, *dr;
r = new_intArrayType(na + nb); r = new_intArrayType(na + nb);
dr = ARRPTR(r); dr = ARRPTR(r);
/* union */ /* union */
i = j = 0; i = j = 0;
while (i < na && j < nb) while (i < na && j < nb) {
if (da[i] < db[j]) if (da[i] == db[j]) {
*dr++ = da[i++];
j++;
} else if (da[i] < db[j])
*dr++ = da[i++]; *dr++ = da[i++];
else else
*dr++ = db[j++]; *dr++ = db[j++];
}
while (i < na) while (i < na)
*dr++ = da[i++]; *dr++ = da[i++];
while (j < nb) while (j < nb)
*dr++ = db[j++]; *dr++ = db[j++];
r = resize_intArrayType(r, dr-ARRPTR(r));
} }
if (ARRNELEMS(r) > 1) 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