forked from len0rd/rockbox
Dircache: A bit of follow-up code cleanup suggested by Amaury Pouly.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30040 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
3b29aa49d3
commit
287d69d7c4
1 changed files with 27 additions and 32 deletions
|
|
@ -599,8 +599,8 @@ int dircache_load(void)
|
||||||
dotdot = dot - sizeof("..");
|
dotdot = dot - sizeof("..");
|
||||||
|
|
||||||
/* d_names are in reverse order, so the last entry points to the first string */
|
/* d_names are in reverse order, so the last entry points to the first string */
|
||||||
intptr_t offset_d_names = maindata.d_names_start - d_names_start;
|
ptrdiff_t offset_d_names = maindata.d_names_start - d_names_start,
|
||||||
intptr_t offset_entries = maindata.root_entry - dircache_root;
|
offset_entries = maindata.root_entry - dircache_root;
|
||||||
|
|
||||||
/* offset_entries is less likely to differ, so check if it's 0 in the loop
|
/* offset_entries is less likely to differ, so check if it's 0 in the loop
|
||||||
* offset_d_names however is almost always non-zero, since dircache_save()
|
* offset_d_names however is almost always non-zero, since dircache_save()
|
||||||
|
|
@ -846,10 +846,11 @@ int dircache_build(int last_size)
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* struct dircache_entrys are allocated from the beginning,
|
/* We'll use the entire audiobuf to allocate the dircache
|
||||||
* their corresponding d_name from the end
|
* struct dircache_entrys are allocated from the beginning
|
||||||
|
* and their corresponding d_name from the end
|
||||||
* after generation the buffer will be compacted with DIRCACHE_RESERVE
|
* after generation the buffer will be compacted with DIRCACHE_RESERVE
|
||||||
* free bytes in between */
|
* free bytes inbetween */
|
||||||
audiobuf = (char*)(((intptr_t)audiobuf & ~0x03) + 0x04);
|
audiobuf = (char*)(((intptr_t)audiobuf & ~0x03) + 0x04);
|
||||||
dircache_root = (struct dircache_entry*)audiobuf;
|
dircache_root = (struct dircache_entry*)audiobuf;
|
||||||
d_names_start = d_names_end = audiobufend - 1;
|
d_names_start = d_names_end = audiobufend - 1;
|
||||||
|
|
@ -858,35 +859,29 @@ int dircache_build(int last_size)
|
||||||
|
|
||||||
/* Start a non-transparent rebuild. */
|
/* Start a non-transparent rebuild. */
|
||||||
int res = dircache_do_rebuild();
|
int res = dircache_do_rebuild();
|
||||||
|
if (res < 0)
|
||||||
|
return res;
|
||||||
|
|
||||||
/** compact the dircache buffer **/
|
/* now compact the dircache buffer */
|
||||||
if (res >= 0)
|
char* dst = ((char*)&dircache_root[entry_count] + DIRCACHE_RESERVE);
|
||||||
{
|
ptrdiff_t offset = d_names_start - dst, size_to_move;
|
||||||
char* dst = ((char*)&dircache_root[entry_count] + DIRCACHE_RESERVE);
|
if (offset <= 0) /* something went wrong */
|
||||||
ssize_t offset = d_names_start - dst;
|
return -1;
|
||||||
if (offset > 0)
|
|
||||||
{
|
/* memmove d_names down, there's a possibility of overlap */
|
||||||
ssize_t size_to_move = dircache_size -
|
size_to_move = dircache_size - entry_count*sizeof(struct dircache_entry);
|
||||||
entry_count*sizeof(struct dircache_entry);
|
memmove(dst, d_names_start, size_to_move);
|
||||||
/* move d_names down, use memmove if overlap */
|
|
||||||
if (offset > size_to_move)
|
/* fix up pointers to the d_names */
|
||||||
memcpy(dst, d_names_start, size_to_move);
|
for(unsigned i = 0; i < entry_count; i++)
|
||||||
else
|
dircache_root[i].d_name -= offset;
|
||||||
memmove(dst, d_names_start, size_to_move);
|
|
||||||
|
d_names_end -= offset;
|
||||||
/* fix up pointers to the d_names */
|
/* equivalent to dircache_size + DIRCACHE_RESERVE */
|
||||||
for(unsigned i = 0; i < entry_count; i++)
|
allocated_size = (d_names_end - (char*)dircache_root);
|
||||||
dircache_root[i].d_name -= offset;
|
reserve_used = 0;
|
||||||
|
audiobuf += allocated_size;
|
||||||
|
|
||||||
d_names_end -= offset;
|
|
||||||
/* equivalent to dircache_size + DIRCACHE_RESERVE */
|
|
||||||
allocated_size = (d_names_end - (char*)dircache_root);
|
|
||||||
reserve_used = 0;
|
|
||||||
audiobuf += allocated_size;
|
|
||||||
}
|
|
||||||
else /* something went wrong */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue