forked from len0rd/rockbox
Obvious optimizations (i wasn't quite awake yet) + Code formatting policy.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6365 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
67772bbf1b
commit
7e3f91d3d8
1 changed files with 104 additions and 103 deletions
|
|
@ -162,10 +162,9 @@ int deletefentry(char *fname) {
|
|||
if(!getfentrybyfilename(fname))
|
||||
return 0;
|
||||
int restrecord = currentferecord+1;
|
||||
if(currentferecord==tagdbheader.filecount) /* file is last entry */
|
||||
if(currentferecord!=tagdbheader.filecount) /* file is not last entry */
|
||||
shiftdown(FILERECORD2OFFSET(currentferecord),FILERECORD2OFFSET(restrecord),(tagdbheader.filecount-restrecord)*FILEENTRY_SIZE);
|
||||
ftruncate(tagdb_fd,lseek(tagdb_fd,0,SEEK_END)-FILEENTRY_SIZE);
|
||||
else
|
||||
shiftdown(FILERECORD2OFFSET(currentferecord),FILERECORD2OFFSET(restrecord));
|
||||
tagdbheader.filecount--;
|
||||
update_fentryoffsets(restrecord,tagdbheader.filecount);
|
||||
writetagdbheader();
|
||||
|
|
@ -177,15 +176,13 @@ int update_fentryoffsets(int start, int end) {
|
|||
for(int i=start;i<end;i++) {
|
||||
getfentrybyrecord(i);
|
||||
if(fe.songentry!=-1) {
|
||||
int *p;
|
||||
void *songentry=(void *)sbuf+tagdbheader.filelen+2;
|
||||
lseek(tagdb_fd,fe.songentry,SEEK_SET);
|
||||
read(tagdb_fd,songentry,SONGENTRY_SIZE);
|
||||
p=(int *)(songentry+tagdbheader.songlen+8);
|
||||
if(*p!=currentfeoffset) {
|
||||
*p=currentfeoffset;
|
||||
lseek(tagdb_fd,fe.songentry,SEEK_SET);
|
||||
write(tagdb_fd,songentry,SONGENTRY_SIZE);
|
||||
int p;
|
||||
lseek(tagdb_fd,fe.songentry+tagdbheader.songlen+8,SEEK_SET);
|
||||
read(tagdb_fd,&p,sizeof(int));
|
||||
if(p!=currentfeoffset) {
|
||||
p=currentfeoffset;
|
||||
lseek(tagdb_fd,fe.songentry+tagdbheader.songlen+8,SEEK_SET);
|
||||
write(tagdb_fd,&p,sizeof(int));
|
||||
}
|
||||
}
|
||||
if(fe.rundbentry!=-1) {
|
||||
|
|
@ -194,14 +191,14 @@ int update_fentryoffsets(int start, int end) {
|
|||
}
|
||||
}
|
||||
|
||||
int tagdb_shiftdown(int targetoffset, int startingoffset) {
|
||||
int tagdb_shiftdown(int targetoffset, int startingoffset, int bytes) {
|
||||
int amount;
|
||||
if(targetoffset>=startingoffset) {
|
||||
splash(HZ*2,"Woah. no beeping way. (tagdb_shiftdown)");
|
||||
return 0;
|
||||
}
|
||||
lseek(tagdb_fd,startingoffset,SEEK_SET);
|
||||
while(amount=read(tagdb_fd,sbuf,1024)) {
|
||||
while(amount=read(tagdb_fd,sbuf,bytes > 1024 ? 1024 : bytes)) {
|
||||
int written;
|
||||
startingoffset+=amount;
|
||||
lseek(tagdb_fd,targetoffset,SEEK_SET);
|
||||
|
|
@ -212,36 +209,40 @@ int tagdb_shiftdown(int targetoffset, int startingoffset) {
|
|||
return 0;
|
||||
}
|
||||
lseek(tagdb_fd,startingoffset,SEEK_SET);
|
||||
bytes-=amount;
|
||||
}
|
||||
ftruncate(tagdb_fd,lseek(tagdb_fd,0,SEEK_END) - (startingoffset-targetoffset));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tagdb_shiftup(int targetoffset, int startingoffset) {
|
||||
int tagdb_shiftup(int targetoffset, int startingoffset, int bytes) {
|
||||
int amount,amount2;
|
||||
int readpos,writepos,filelen;
|
||||
int ok;
|
||||
if(targetoffset<=startingoffset) {
|
||||
splash(HZ*2,"Um. no. (tagdb_shiftup)");
|
||||
return 0;
|
||||
}
|
||||
filelen=lseek(tagdb_fd,0,SEEK_END);
|
||||
readpos=filelen;
|
||||
readpos=startingoffset+bytes;
|
||||
do {
|
||||
amount=readpos-startingoffset>1024 ? 1024 : readpos-startingoffset;
|
||||
amount=bytes>1024 ? 1024 : bytes;
|
||||
readpos-=amount;
|
||||
writepos=readpos+(targetoffset-startingoffset);
|
||||
writepos=readpos+targetoffset-startingoffset;
|
||||
lseek(tagdb_fd,readpos,SEEK_SET);
|
||||
amount2=read(tagdb_fd,sbuf,amount);
|
||||
if(amount2!=amount) {
|
||||
splash(HZ*2,"Something went very wrong. expect database corruption. (tagdb_shiftup)");
|
||||
return 0;
|
||||
}
|
||||
lseek(tagdb_fd,writepos,SEEK_SET);
|
||||
amount=write(tagdb_fd,sbuf,amount2);
|
||||
if(amount2!=amount) {
|
||||
splash(HZ*2,"Something went very wrong. expect database corruption. (tagdb_shiftup)");
|
||||
return 0;
|
||||
}
|
||||
bytes-=amount;
|
||||
} while (amount>0);
|
||||
if(amount==0)
|
||||
if(bytes==0)
|
||||
return 1;
|
||||
else {
|
||||
splash(HZ*2,"Something went wrong, >.>;; (tagdb_shiftup)");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue