@@ -1741,33 +1741,29 @@ makepol(WORKSTATE *state) {
1741
1741
typedef struct {
1742
1742
int4 * arrb ;
1743
1743
int4 * arre ;
1744
- int4 * ptr ;
1745
1744
} CHKVAL ;
1746
1745
1747
1746
/*
1748
1747
* is there value 'val' in array or not ?
1749
- */
1748
+ */
1750
1749
static bool
1751
1750
checkcondition_arr ( void * checkval , int4 val ) {
1752
- #ifdef BS_DEBUG
1753
- elog (NOTICE ,"OPERAND %d" , val );
1754
- #endif
1755
- if ( val > * (((CHKVAL * )checkval )-> ptr ) ) {
1756
- while ( ((CHKVAL * )checkval )-> ptr < ((CHKVAL * )checkval )-> arre ) {
1757
- ((CHKVAL * )checkval )-> ptr ++ ;
1758
- if ( * (((CHKVAL * )checkval )-> ptr ) == val ) return true;
1759
- if ( val < * (((CHKVAL * )checkval )-> ptr ) ) return false;
1760
- }
1761
- } else if ( val < * (((CHKVAL * )checkval )-> ptr ) ) {
1762
- while ( ((CHKVAL * )checkval )-> ptr > ((CHKVAL * )checkval )-> arrb ) {
1763
- ((CHKVAL * )checkval )-> ptr -- ;
1764
- if ( * (((CHKVAL * )checkval )-> ptr ) == val ) return true;
1765
- if ( val > * (((CHKVAL * )checkval )-> ptr ) ) return false;
1766
- }
1767
- } else {
1768
- return true;
1751
+ int4 * StopLow = ((CHKVAL * )checkval )-> arrb ;
1752
+ int4 * StopHigh = ((CHKVAL * )checkval )-> arre ;
1753
+ int4 * StopMiddle ;
1754
+
1755
+ /* Loop invariant: StopLow <= val < StopHigh */
1756
+
1757
+ while (StopLow < StopHigh ) {
1758
+ StopMiddle = StopLow + (StopHigh - StopLow ) / 2 ;
1759
+ if (* StopMiddle == val )
1760
+ return (true);
1761
+ else if (* StopMiddle < val )
1762
+ StopLow = StopMiddle + 1 ;
1763
+ else
1764
+ StopHigh = StopMiddle ;
1769
1765
}
1770
- return false;
1766
+ return false;
1771
1767
}
1772
1768
1773
1769
static bool
@@ -1818,8 +1814,7 @@ execconsistent( QUERYTYPE *query, ArrayType *array, bool calcnot ) {
1818
1814
CHKVAL chkval ;
1819
1815
1820
1816
chkval .arrb = ARRPTR (array );
1821
- chkval .arre = chkval .arrb + ARRNELEMS (array ) - 1 ;
1822
- chkval .ptr = chkval .arrb + ARRNELEMS (array )/2 ;
1817
+ chkval .arre = chkval .arrb + ARRNELEMS (array );
1823
1818
return execute (
1824
1819
GETQUERY (query ) + query -> size - 1 ,
1825
1820
(void * )& chkval , calcnot ,
@@ -1854,8 +1849,7 @@ boolop(PG_FUNCTION_ARGS) {
1854
1849
1855
1850
PREPAREARR (val );
1856
1851
chkval .arrb = ARRPTR (val );
1857
- chkval .arre = chkval .arrb + ARRNELEMS (val ) - 1 ;
1858
- chkval .ptr = chkval .arrb + ARRNELEMS (val )/2 ;
1852
+ chkval .arre = chkval .arrb + ARRNELEMS (val );
1859
1853
result = execute (
1860
1854
GETQUERY (query ) + query -> size - 1 ,
1861
1855
& chkval , true,
0 commit comments