Skip to content

Commit c1f3943

Browse files
committed
Some optimizations by Volkan YAZICI <yazicivo@ttnet.net.tr>
1 parent 10dd8df commit c1f3943

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

contrib/intarray/_int_op.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ _int_same(PG_FUNCTION_ARGS)
8383
if (avoid || bvoid)
8484
return (avoid && bvoid) ? TRUE : FALSE;
8585

86-
SORT(a);
87-
SORT(b);
8886
na = ARRNELEMS(a);
8987
nb = ARRNELEMS(b);
9088
da = ARRPTR(a);
@@ -94,7 +92,10 @@ _int_same(PG_FUNCTION_ARGS)
9492

9593
if (na == nb)
9694
{
95+
SORT(a);
96+
SORT(b);
9797
result = TRUE;
98+
9899
for (n = 0; n < na; n++)
99100
if (da[n] != db[n])
100101
{

contrib/intarray/_int_tool.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ inner_int_contains(ArrayType *a, ArrayType *b)
3434
j++;
3535
}
3636
else
37-
j++;
37+
break;
3838

3939
return (n == nb) ? TRUE : FALSE;
4040
}
@@ -76,13 +76,6 @@ ArrayType *
7676
inner_int_union(ArrayType *a, ArrayType *b)
7777
{
7878
ArrayType *r = NULL;
79-
int na,
80-
nb;
81-
int *da,
82-
*db,
83-
*dr;
84-
int i,
85-
j;
8679

8780
CHECKARRVALID(a);
8881
CHECKARRVALID(b);
@@ -94,31 +87,35 @@ inner_int_union(ArrayType *a, ArrayType *b)
9487
if (ARRISVOID(b))
9588
r = copy_intArrayType(a);
9689

97-
if (r)
98-
dr = ARRPTR(r);
99-
else
90+
if (!r)
10091
{
101-
na = ARRNELEMS(a);
102-
nb = ARRNELEMS(b);
103-
da = ARRPTR(a);
104-
db = ARRPTR(b);
92+
int na = ARRNELEMS(a),
93+
nb = ARRNELEMS(b);
94+
int *da = ARRPTR(a),
95+
*db = ARRPTR(b);
96+
int i,j, *dr;
10597

10698
r = new_intArrayType(na + nb);
10799
dr = ARRPTR(r);
108100

109101
/* union */
110102
i = j = 0;
111-
while (i < na && j < nb)
112-
if (da[i] < db[j])
103+
while (i < na && j < nb) {
104+
if (da[i] == db[j]) {
105+
*dr++ = da[i++];
106+
j++;
107+
} else if (da[i] < db[j])
113108
*dr++ = da[i++];
114109
else
115110
*dr++ = db[j++];
111+
}
116112

117113
while (i < na)
118114
*dr++ = da[i++];
119115
while (j < nb)
120116
*dr++ = db[j++];
121117

118+
r = resize_intArrayType(r, dr-ARRPTR(r));
122119
}
123120

124121
if (ARRNELEMS(r) > 1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy