@@ -1741,33 +1741,29 @@ makepol(WORKSTATE *state) {
17411741typedef struct {
17421742int4 * arrb ;
17431743int4 * arre ;
1744- int4 * ptr ;
17451744}CHKVAL ;
17461745
17471746/*
17481747 * is there value 'val' in array or not ?
1749- */
1748+ */
17501749static bool
17511750checkcondition_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 ;
17691765}
1770- return false;
1766+ return false;
17711767}
17721768
17731769static bool
@@ -1818,8 +1814,7 @@ execconsistent( QUERYTYPE *query, ArrayType *array, bool calcnot ) {
18181814CHKVAL chkval ;
18191815
18201816chkval .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 );
18231818return execute (
18241819GETQUERY (query )+ query -> size - 1 ,
18251820(void * )& chkval ,calcnot ,
@@ -1854,8 +1849,7 @@ boolop(PG_FUNCTION_ARGS) {
18541849
18551850PREPAREARR (val );
18561851chkval .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 );
18591853result = execute (
18601854GETQUERY (query )+ query -> size - 1 ,
18611855& chkval , true,