Speedup to checkfreeandused() routine.

This commit is contained in:
Bobbi Webber-Manners 2020-06-06 01:47:51 -04:00
parent 202a201826
commit cc032abe62
2 changed files with 39 additions and 33 deletions

View File

@ -3,7 +3,7 @@
* *
* Bobbi January-June 2020 * Bobbi January-June 2020
* *
* TODO: Speed up freelist/usedlist checking at the end (aux mem) * TODO: zeroblock() is NO-OP at present
* TODO: Need code to write out modified freelist if there are fixes * TODO: Need code to write out modified freelist if there are fixes
* TODO: Get both ProDOS-8 and GNO versions to build from this source * TODO: Get both ProDOS-8 and GNO versions to build from this source
* TODO: Trimming unused directory blocks * TODO: Trimming unused directory blocks
@ -32,6 +32,7 @@
* v0.70 Changed sort options to support mtime & ctime. Improved UI a bit. * v0.70 Changed sort options to support mtime & ctime. Improved UI a bit.
* v0.71 Added support for allocating aux LC memory. * v0.71 Added support for allocating aux LC memory.
* v0.72 Initial support for freelist and usedlist in aux mem. (Slow!) * v0.72 Initial support for freelist and usedlist in aux mem. (Slow!)
* v0.73 Speedup to checkfreeandused();
*/ */
//#pragma debug 9 //#pragma debug 9
@ -191,6 +192,7 @@ static uint totblks; /* Total # blocks on volume */
static uchar *freelist; /* Free-list bitmap */ static uchar *freelist; /* Free-list bitmap */
static uchar *usedlist; /* Bit map of used blocks */ static uchar *usedlist; /* Bit map of used blocks */
static uchar flloaded = 0; /* 1 if free-list has been loaded */ static uchar flloaded = 0; /* 1 if free-list has been loaded */
static uint flsize; /* Size of free-list in blocks */
#endif #endif
static char currdir[NMLEN+1]; /* Name of current directory */ static char currdir[NMLEN+1]; /* Name of current directory */
static struct block *blocks = NULL; /* List of directory disk blocks */ static struct block *blocks = NULL; /* List of directory disk blocks */
@ -795,7 +797,7 @@ uint askfix(void) {
* Read the free list * Read the free list
*/ */
int readfreelist(uchar device) { int readfreelist(uchar device) {
uint i, flblk, flsize; uint i, flblk;
char *p; char *p;
#ifdef AUXMEM #ifdef AUXMEM
bzero(buf, BLKSZ); bzero(buf, BLKSZ);
@ -1940,7 +1942,7 @@ void interactive(void) {
revers(1); revers(1);
hlinechar(' '); hlinechar(' ');
fputs("S O R T D I R v0.72 alpha Use ^ to return to previous question", stdout); fputs("S O R T D I R v0.73 alpha Use ^ to return to previous question", stdout);
hlinechar(' '); hlinechar(' ');
revers(0); revers(0);
@ -2027,7 +2029,6 @@ q6:
fixopts[0] = ((f == '-') ? 'n' : f); fixopts[0] = ((f == '-') ? 'n' : f);
#ifdef FREELIST #ifdef FREELIST
q7:
if (w == 'v') { if (w == 'v') {
subtitle("Zero free space?"); subtitle("Zero free space?");
do { do {
@ -2047,11 +2048,7 @@ q7:
wrt = getchar(); wrt = getchar();
} while (strchr("-w^", wrt) == NULL); } while (strchr("-w^", wrt) == NULL);
if (wrt == '^') if (wrt == '^')
#ifdef FREELIST
goto q7;
#else
goto q6; goto q6;
#endif
if (wrt == 'w') if (wrt == 'w')
dowrite = 1; dowrite = 1;
} }
@ -2107,37 +2104,46 @@ done:
* block should either be marked free or marked used. * block should either be marked free or marked used.
*/ */
void checkfreeandused(uchar device) { void checkfreeandused(uchar device) {
uint i, freeblks = 0; uchar fl, ul, bit;
printf("Total blks %u\n", totblks); uint byte, blk = 1, blkcnt = 0;
for (i = 0; i < totblks; ++i) printf("Total blks %u", totblks);
if (isfree(i)) for (byte = 0; byte < flsize * 256; ++byte) {
++freeblks; #ifdef AUXMEM
printf("Free blks %u\n", freeblks); copyaux(freelist + byte, &fl, 1, FROMAUX);
// printf("Percentage full\t\t%.1f\n", copyaux(usedlist + byte, &ul, 1, FROMAUX);
// 100.0 * (float)(totblks - freeblks) / totblks); #else
for (i = 0; i < totblks; ++i) { fl = freelist[byte];
uint idx = i / 8; ul = usedlist[byte];
#ifndef AUXMEM
if (!(freelist[idx] ^ usedlist[idx])) /* Speed-up */
continue;
#endif #endif
if (isfree(i)) { for (bit = 0; bit < 8; ++bit) {
if (isused(i)) { if (blk > totblks)
err(NONFATAL, err_blfree1, i); break;
if (askfix() == 1) if ((fl << bit) & 0x80) {
marknotfree(i); /* Free */
} if ((ul << bit) & 0x80) {
} else { /* ... and used */
if (!isused(i)) { err(NONFATAL, err_blfree1, blk);
err(NONFATAL, err_blused1, i); if (askfix() == 1)
if (askfix() == 1) marknotfree(blk);
markfree(i); }
} else {
/* Not free */
++blkcnt;
if (!((ul << bit) & 0x80)) {
/* ... and not used */
err(NONFATAL, err_blused1, blk);
if (askfix() == 1)
markfree(blk);
}
} }
++blk;
} }
} }
printf("\nFree blks %u\n", totblks - blkcnt);
// TODO: NEED SOME CODE TO WRITE OUT MODIFIED FREE LIST!! // TODO: NEED SOME CODE TO WRITE OUT MODIFIED FREE LIST!!
if (dozero) if (dozero)
zerofreeblocks(device, freeblks); zerofreeblocks(device, totblks - blkcnt);
} }
/* /*

Binary file not shown.