File tree 2 files changed +17
-19
lines changed
2 files changed +17
-19
lines changed Original file line number Diff line number Diff line change @@ -83,8 +83,6 @@ _int_same(PG_FUNCTION_ARGS)
83
83
if (avoid || bvoid )
84
84
return (avoid && bvoid ) ? TRUE : FALSE;
85
85
86
- SORT (a );
87
- SORT (b );
88
86
na = ARRNELEMS (a );
89
87
nb = ARRNELEMS (b );
90
88
da = ARRPTR (a );
@@ -94,7 +92,10 @@ _int_same(PG_FUNCTION_ARGS)
94
92
95
93
if (na == nb )
96
94
{
95
+ SORT (a );
96
+ SORT (b );
97
97
result = TRUE;
98
+
98
99
for (n = 0 ; n < na ; n ++ )
99
100
if (da [n ] != db [n ])
100
101
{
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ inner_int_contains(ArrayType *a, ArrayType *b)
34
34
j ++ ;
35
35
}
36
36
else
37
- j ++ ;
37
+ break ;
38
38
39
39
return (n == nb ) ? TRUE : FALSE;
40
40
}
@@ -76,13 +76,6 @@ ArrayType *
76
76
inner_int_union (ArrayType * a , ArrayType * b )
77
77
{
78
78
ArrayType * r = NULL ;
79
- int na ,
80
- nb ;
81
- int * da ,
82
- * db ,
83
- * dr ;
84
- int i ,
85
- j ;
86
79
87
80
CHECKARRVALID (a );
88
81
CHECKARRVALID (b );
@@ -94,31 +87,35 @@ inner_int_union(ArrayType *a, ArrayType *b)
94
87
if (ARRISVOID (b ))
95
88
r = copy_intArrayType (a );
96
89
97
- if (r )
98
- dr = ARRPTR (r );
99
- else
90
+ if (!r )
100
91
{
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 ;
105
97
106
98
r = new_intArrayType (na + nb );
107
99
dr = ARRPTR (r );
108
100
109
101
/* union */
110
102
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 ])
113
108
* dr ++ = da [i ++ ];
114
109
else
115
110
* dr ++ = db [j ++ ];
111
+ }
116
112
117
113
while (i < na )
118
114
* dr ++ = da [i ++ ];
119
115
while (j < nb )
120
116
* dr ++ = db [j ++ ];
121
117
118
+ r = resize_intArrayType (r , dr - ARRPTR (r ));
122
119
}
123
120
124
121
if (ARRNELEMS (r ) > 1 )
You can’t perform that action at this time.
0 commit comments