Skip to content

Commit 8c2271a

Browse files
committed
Fixes + improvements
- fix GCC 8 warnings, - fix previous commit, - make threads progress refresh 2x faster, - reduce sleep delay with --all switch in threads.
1 parent 8dc4737 commit 8c2271a

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

src/zopfli/defines.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ required by Zopfli KrzYmod.
1616

1717
#define VERYEAR 18
1818
#define VERMONTH 8
19-
#define VERCOMMIT 1
19+
#define VERCOMMIT 2
2020

2121
#define BESTSTATSDBVER 1
2222

src/zopfli/deflate.c

+27-19
Original file line numberDiff line numberDiff line change
@@ -1206,20 +1206,24 @@ typedef struct ZopfliBestStats {
12061206

12071207
static int StatsDBLoad(ZopfliBestStats* statsdb) {
12081208
FILE *file;
1209-
size_t b = 0, i = 0;
1209+
size_t b = 0, i = 0, j = 0;
12101210
unsigned char check;
1211-
char crc32bits[16];
1211+
char crc32bits[9];
12121212
char DBfile[32];
12131213
char LocBuf[56];
12141214
unsigned char sizetsize = sizeof(size_t);
12151215
sprintf(crc32bits,"%08lx",statsdb->blockcrc);
12161216
sprintf(DBfile,"%x-%lu.dat",statsdb->mode,(unsigned long)statsdb->blocksize);
12171217
sprintf(LocBuf,"ZopfliDB");
1218-
while(i<8) {
1219-
sprintf(LocBuf,"%s/%c",LocBuf,crc32bits[i++]);
1220-
sprintf(LocBuf,"%s%c",LocBuf,crc32bits[i++]);
1218+
while(i<(sizeof(crc32bits) / sizeof(crc32bits[0]))) {
1219+
if((i % 2) == 0) {
1220+
LocBuf[8+i+j] = '/';
1221+
++j;
1222+
}
1223+
LocBuf[8+i+j] = crc32bits[i];
1224+
++i;
12211225
}
1222-
sprintf(LocBuf,"%s/%s",LocBuf,DBfile);
1226+
sprintf(LocBuf+21,"%s",DBfile);
12231227
file = fopen(LocBuf, "rb");
12241228
if(!file) return 0;
12251229
b += fread(&check,sizeof(check),1,file);
@@ -1259,9 +1263,9 @@ static int DoDir(char* dir) {
12591263

12601264
static int StatsDBSave(ZopfliBestStats* statsdb) {
12611265
FILE *file;
1262-
size_t b = 0, i = 0;
1266+
size_t b = 0, i = 0, j = 0;
12631267
unsigned char check = BESTSTATSDBVER;
1264-
char crc32bits[16];
1268+
char crc32bits[9];
12651269
char DBfile[32];
12661270
char LocBuf[56];
12671271
unsigned char sizetsize = sizeof(size_t);
@@ -1270,13 +1274,17 @@ static int StatsDBSave(ZopfliBestStats* statsdb) {
12701274
sprintf(crc32bits,"%08lx",statsdb->blockcrc);
12711275
sprintf(DBfile,"%x-%lu.dat",statsdb->mode,(unsigned long)statsdb->blocksize);
12721276
sprintf(LocBuf,"ZopfliDB");
1273-
if(!DoDir(LocBuf)) return 0;
1274-
while(i<8) {
1275-
sprintf(LocBuf,"%s/%c",LocBuf,crc32bits[i++]);
1276-
sprintf(LocBuf,"%s%c",LocBuf,crc32bits[i++]);
1277-
if(!DoDir(LocBuf)) return 0;
1277+
while(i<(sizeof(crc32bits) / sizeof(crc32bits[0]))) {
1278+
if((i % 2) == 0) {
1279+
LocBuf[8+i+j] = 0;
1280+
if(!DoDir(LocBuf)) return 0;
1281+
LocBuf[8+i+j] = '/';
1282+
++j;
1283+
}
1284+
LocBuf[8+i+j] = crc32bits[i];
1285+
++i;
12781286
}
1279-
sprintf(LocBuf,"%s/%s",LocBuf,DBfile);
1287+
sprintf(LocBuf+21,"%s",DBfile);
12801288
file = fopen(LocBuf, "wb");
12811289
if(!file) return 0;
12821290
for(i = 0; i < ZOPFLI_NUM_LL; ++i)
@@ -1402,7 +1410,7 @@ static void *threading(void *a) {
14021410
/* Racing condition prevention */
14031411
b->allstatscontrol = tries + 0x0100;
14041412
do {
1405-
usleep(50000);
1413+
usleep(10000);
14061414
} while(b->allstatscontrol & 0x0100);
14071415
} else {
14081416
/* No SLAVE threads, work done by MASTER thread */
@@ -1457,7 +1465,7 @@ static void *threading(void *a) {
14571465
/* Racing condition prevention */
14581466
b->allstatscontrol = tries + 0x0200;
14591467
do {
1460-
usleep(50000);
1468+
usleep(10000);
14611469
} while(b->allstatscontrol & 0x0200);
14621470
} else {
14631471
/* No SLAVE threads, work done by MASTER thread */
@@ -1603,7 +1611,7 @@ static void ZopfliUseThreads(const ZopfliOptions* options,
16031611
if(options->mode & 0x0010) {
16041612
size_t xx = 0;
16051613
for(;xx < numthreads;++xx) {
1606-
if(t[threnum].allstatscontrol & 0x0100) {
1614+
if(t[xx].allstatscontrol & 0x0100) {
16071615
statsdb[xx].mode = t[xx].allstatscontrol & 0xF;
16081616
statsdb[xx].beststats = Zmalloc(sizeof(SymbolStats));
16091617
InitStats(statsdb[xx].beststats);
@@ -1633,7 +1641,7 @@ static void ZopfliUseThreads(const ZopfliOptions* options,
16331641
if(calci>options->numiterations) calci=options->numiterations;
16341642
}
16351643
thrprogress = (int)(((zfloat)t[showthread].iterations.iteration / (zfloat)calci) * 100);
1636-
usleep(250000);
1644+
usleep(125000);
16371645
fprintf(stderr,"%3d%% T:%2d | B:%4d | M:%s%s%s%s | I:%5d (%d) - %d (%d) b \r",
16381646
thrprogress, showthread, ((unsigned int)t[showthread].iterations.block+1),
16391647
(t[showthread].mode & 0x8)? "1" : "0",
@@ -1648,7 +1656,7 @@ static void ZopfliUseThreads(const ZopfliOptions* options,
16481656
showthread=0;
16491657
showcntr=0;
16501658
}
1651-
if(showcntr>4) {
1659+
if(showcntr>8) {
16521660
if(threadsrunning>1) {
16531661
++showthread;
16541662
if(showthread>=numthreads)

0 commit comments

Comments
 (0)