I\'m looking to optimize this linear search:
static int
linear (const int *arr, int n, int key)
{
int i = 0;
while (i < n) {
unroll with fixed array indices.
int linear( const int *array, int n, int key ) {
int i = 0;
if ( array[n-1] >= key ) {
do {
if ( array[0] >= key ) return i+0;
if ( array[1] >= key ) return i+1;
if ( array[2] >= key ) return i+2;
if ( array[3] >= key ) return i+3;
array += 4;
i += 4;
} while ( true );
}
return -1;
}