fix up font_cache/LRU boundry errors from r30763
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31050 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
62f5027650
commit
e62cccb81e
1 changed files with 35 additions and 17 deletions
|
@ -78,12 +78,13 @@ void font_cache_create(
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
static int search(struct font_cache* fcache,
|
static int search(struct font_cache* fcache,
|
||||||
unsigned short char_code,
|
unsigned short char_code,
|
||||||
|
int size,
|
||||||
int *p_insertion_point )
|
int *p_insertion_point )
|
||||||
{
|
{
|
||||||
struct font_cache_entry *p;
|
struct font_cache_entry *p;
|
||||||
int left, right, mid=-1, c;
|
int left, right, mid=-1, c;
|
||||||
left = 0;
|
left = 0;
|
||||||
right = fcache->_size - 1;
|
right = size;
|
||||||
|
|
||||||
/* go for a lucky guess */
|
/* go for a lucky guess */
|
||||||
mid = char_code +
|
mid = char_code +
|
||||||
|
@ -115,6 +116,7 @@ static int search(struct font_cache* fcache,
|
||||||
while (left <= right);
|
while (left <= right);
|
||||||
|
|
||||||
/* not found */
|
/* not found */
|
||||||
|
p = lru_data(&fcache->_lru, fcache->_index[mid]);
|
||||||
*p_insertion_point = mid;
|
*p_insertion_point = mid;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +133,20 @@ struct font_cache_entry* font_cache_get(
|
||||||
int insertion_point;
|
int insertion_point;
|
||||||
int index_to_replace;
|
int index_to_replace;
|
||||||
|
|
||||||
if( search(fcache, char_code, &insertion_point))
|
/* check bounds */
|
||||||
|
p = lru_data(&fcache->_lru, fcache->_index[0]);
|
||||||
|
if( char_code < p->_char_code )
|
||||||
|
insertion_point = -1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p = lru_data(&fcache->_lru, fcache->_index[fcache->_capacity - 1]);
|
||||||
|
if( char_code > p->_char_code )
|
||||||
|
{
|
||||||
|
insertion_point = fcache->_capacity - 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if( search(fcache, char_code, fcache->_size - 1, &insertion_point))
|
||||||
{
|
{
|
||||||
short lru_handle = fcache->_index[insertion_point];
|
short lru_handle = fcache->_index[insertion_point];
|
||||||
p = lru_data(&fcache->_lru, lru_handle);
|
p = lru_data(&fcache->_lru, lru_handle);
|
||||||
|
@ -141,19 +156,22 @@ struct font_cache_entry* font_cache_get(
|
||||||
return lru_data(&fcache->_lru, lru_handle);
|
return lru_data(&fcache->_lru, lru_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* not found */
|
else
|
||||||
{
|
{
|
||||||
p = lru_data(&fcache->_lru,
|
p = lru_data(&fcache->_lru,
|
||||||
fcache->_index[insertion_point+1]);
|
fcache->_index[insertion_point+1]);
|
||||||
if ( char_code > p->_char_code )
|
if ( char_code > p->_char_code )
|
||||||
insertion_point++;
|
insertion_point++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* not found */
|
||||||
|
|
||||||
/* find index to replace */
|
/* find index to replace */
|
||||||
short lru_handle_to_replace = fcache->_lru._head;
|
short lru_handle_to_replace = fcache->_lru._head;
|
||||||
p = lru_data(&fcache->_lru, lru_handle_to_replace);
|
p = lru_data(&fcache->_lru, lru_handle_to_replace);
|
||||||
search(fcache, p->_char_code, &index_to_replace);
|
search(fcache, p->_char_code, fcache->_size - 1, &index_to_replace);
|
||||||
|
|
||||||
if (insertion_point < index_to_replace)
|
if (insertion_point < index_to_replace)
|
||||||
{
|
{
|
||||||
/* shift memory up */
|
/* shift memory up */
|
||||||
|
|
Loading…
Reference in a new issue