Commit dfa9e2c5 authored by Yunqing Wang's avatar Yunqing Wang Committed by Code Review
Browse files

Merge "Use insertion sort instead of quick sort"

parents 1b2abc5f 5abafcc3
...@@ -1432,86 +1432,55 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x, ...@@ -1432,86 +1432,55 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x,
return bsi.segment_rd; return bsi.segment_rd;
} }
static void swap(int *x,int *y) static void insertsortmv(int arr[], int len)
{ {
int tmp; int i, j, k;
tmp = *x; for ( i = 1 ; i <= len-1 ; i++ )
*x = *y; {
*y = tmp; for ( j = 0 ; j < i ; j++ )
} {
if ( arr[j] > arr[i] )
{
int temp;
static void quicksortmv(int arr[],int left, int right) temp = arr[i];
{
int lidx,ridx,pivot; for ( k = i; k >j; k--)
arr[k] = arr[k - 1] ;
lidx = left;
ridx = right; arr[j] = temp ;
}
if( left < right) }
{ }
pivot = (left + right)/2;
while(lidx <=pivot && ridx >=pivot)
{
while(arr[lidx] < arr[pivot] && lidx <= pivot)
lidx++;
while(arr[ridx] > arr[pivot] && ridx >= pivot)
ridx--;
swap(&arr[lidx], &arr[ridx]);
lidx++;
ridx--;
if(lidx-1 == pivot)
{
ridx++;
pivot = ridx;
}
else if(ridx+1 == pivot)
{
lidx--;
pivot = lidx;
}
}
quicksortmv(arr, left, pivot - 1);
quicksortmv(arr, pivot + 1, right);
}
} }
static void quicksortsad(int arr[],int idx[], int left, int right) static void insertsortsad(int arr[],int idx[], int len)
{ {
int lidx,ridx,pivot; int i, j, k;
lidx = left; for ( i = 1 ; i <= len-1 ; i++ )
ridx = right; {
for ( j = 0 ; j < i ; j++ )
if( left < right) {
{ if ( arr[j] > arr[i] )
pivot = (left + right)/2; {
int temp, tempi;
while(lidx <=pivot && ridx >=pivot)
{ temp = arr[i];
while(arr[lidx] < arr[pivot] && lidx <= pivot) tempi = idx[i];
lidx++;
while(arr[ridx] > arr[pivot] && ridx >= pivot) for ( k = i; k >j; k--)
ridx--; {
swap(&arr[lidx], &arr[ridx]); arr[k] = arr[k - 1] ;
swap(&idx[lidx], &idx[ridx]); idx[k] = idx[k - 1];
lidx++; }
ridx--;
if(lidx-1 == pivot) arr[j] = temp ;
{ idx[j] = tempi;
ridx++; }
pivot = ridx; }
} }
else if(ridx+1 == pivot)
{
lidx--;
pivot = lidx;
}
}
quicksortsad(arr, idx, left, pivot - 1);
quicksortsad(arr, idx, pivot + 1, right);
}
} }
//The improved MV prediction //The improved MV prediction
...@@ -1647,8 +1616,8 @@ void vp8_mv_pred ...@@ -1647,8 +1616,8 @@ void vp8_mv_pred
mvy[i] = near_mvs[i].as_mv.col; mvy[i] = near_mvs[i].as_mv.col;
} }
quicksortmv (mvx, 0, vcnt-1); insertsortmv(mvx, vcnt);
quicksortmv (mvy, 0, vcnt-1); insertsortmv(mvy, vcnt);
mv.as_mv.row = mvx[vcnt/2]; mv.as_mv.row = mvx[vcnt/2];
mv.as_mv.col = mvy[vcnt/2]; mv.as_mv.col = mvy[vcnt/2];
...@@ -1711,10 +1680,10 @@ void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse ...@@ -1711,10 +1680,10 @@ void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse
if(cpi->common.last_frame_type != KEY_FRAME) if(cpi->common.last_frame_type != KEY_FRAME)
{ {
quicksortsad(near_sad, near_sadidx, 0, 7); insertsortsad(near_sad, near_sadidx, 8);
}else }else
{ {
quicksortsad(near_sad, near_sadidx, 0, 2); insertsortsad(near_sad, near_sadidx, 3);
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment