diff options
author | Teodor Sigaev <teodor@sigaev.ru> | 2006-05-10 11:39:12 +0000 |
---|---|---|
committer | Teodor Sigaev <teodor@sigaev.ru> | 2006-05-10 11:39:12 +0000 |
commit | c1f39437d0ad38d1f8d76f9ebf904faa9a7aaaf6 (patch) | |
tree | 2a09a68a0499e827feb3f67942188c6ea82aba2f /contrib/intarray/_int_tool.c | |
parent | 10dd8df68e6c826186b9900b703051b46ccd6b31 (diff) | |
download | postgresql-c1f39437d0ad38d1f8d76f9ebf904faa9a7aaaf6.tar.gz postgresql-c1f39437d0ad38d1f8d76f9ebf904faa9a7aaaf6.zip |
Some optimizations by Volkan YAZICI <yazicivo@ttnet.net.tr>
Diffstat (limited to 'contrib/intarray/_int_tool.c')
-rw-r--r-- | contrib/intarray/_int_tool.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c index 480e16ed9fe..82ce4b7ac56 100644 --- a/contrib/intarray/_int_tool.c +++ b/contrib/intarray/_int_tool.c @@ -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); - nb = ARRNELEMS(b); - da = ARRPTR(a); - db = ARRPTR(b); + int na = ARRNELEMS(a), + nb = ARRNELEMS(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) |