@@ -1206,20 +1206,24 @@ typedef struct ZopfliBestStats {
1206
1206
1207
1207
static int StatsDBLoad (ZopfliBestStats * statsdb ) {
1208
1208
FILE * file ;
1209
- size_t b = 0 , i = 0 ;
1209
+ size_t b = 0 , i = 0 , j = 0 ;
1210
1210
unsigned char check ;
1211
- char crc32bits [16 ];
1211
+ char crc32bits [9 ];
1212
1212
char DBfile [32 ];
1213
1213
char LocBuf [56 ];
1214
1214
unsigned char sizetsize = sizeof (size_t );
1215
1215
sprintf (crc32bits ,"%08lx" ,statsdb -> blockcrc );
1216
1216
sprintf (DBfile ,"%x-%lu.dat" ,statsdb -> mode ,(unsigned long )statsdb -> blocksize );
1217
1217
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 ;
1221
1225
}
1222
- sprintf (LocBuf ,"%s/%s" , LocBuf ,DBfile );
1226
+ sprintf (LocBuf + 21 ,"%s" ,DBfile );
1223
1227
file = fopen (LocBuf , "rb" );
1224
1228
if (!file ) return 0 ;
1225
1229
b += fread (& check ,sizeof (check ),1 ,file );
@@ -1259,9 +1263,9 @@ static int DoDir(char* dir) {
1259
1263
1260
1264
static int StatsDBSave (ZopfliBestStats * statsdb ) {
1261
1265
FILE * file ;
1262
- size_t b = 0 , i = 0 ;
1266
+ size_t b = 0 , i = 0 , j = 0 ;
1263
1267
unsigned char check = BESTSTATSDBVER ;
1264
- char crc32bits [16 ];
1268
+ char crc32bits [9 ];
1265
1269
char DBfile [32 ];
1266
1270
char LocBuf [56 ];
1267
1271
unsigned char sizetsize = sizeof (size_t );
@@ -1270,13 +1274,17 @@ static int StatsDBSave(ZopfliBestStats* statsdb) {
1270
1274
sprintf (crc32bits ,"%08lx" ,statsdb -> blockcrc );
1271
1275
sprintf (DBfile ,"%x-%lu.dat" ,statsdb -> mode ,(unsigned long )statsdb -> blocksize );
1272
1276
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 ;
1278
1286
}
1279
- sprintf (LocBuf ,"%s/%s" , LocBuf ,DBfile );
1287
+ sprintf (LocBuf + 21 ,"%s" ,DBfile );
1280
1288
file = fopen (LocBuf , "wb" );
1281
1289
if (!file ) return 0 ;
1282
1290
for (i = 0 ; i < ZOPFLI_NUM_LL ; ++ i )
@@ -1402,7 +1410,7 @@ static void *threading(void *a) {
1402
1410
/* Racing condition prevention */
1403
1411
b -> allstatscontrol = tries + 0x0100 ;
1404
1412
do {
1405
- usleep (50000 );
1413
+ usleep (10000 );
1406
1414
} while (b -> allstatscontrol & 0x0100 );
1407
1415
} else {
1408
1416
/* No SLAVE threads, work done by MASTER thread */
@@ -1457,7 +1465,7 @@ static void *threading(void *a) {
1457
1465
/* Racing condition prevention */
1458
1466
b -> allstatscontrol = tries + 0x0200 ;
1459
1467
do {
1460
- usleep (50000 );
1468
+ usleep (10000 );
1461
1469
} while (b -> allstatscontrol & 0x0200 );
1462
1470
} else {
1463
1471
/* No SLAVE threads, work done by MASTER thread */
@@ -1603,7 +1611,7 @@ static void ZopfliUseThreads(const ZopfliOptions* options,
1603
1611
if (options -> mode & 0x0010 ) {
1604
1612
size_t xx = 0 ;
1605
1613
for (;xx < numthreads ;++ xx ) {
1606
- if (t [threnum ].allstatscontrol & 0x0100 ) {
1614
+ if (t [xx ].allstatscontrol & 0x0100 ) {
1607
1615
statsdb [xx ].mode = t [xx ].allstatscontrol & 0xF ;
1608
1616
statsdb [xx ].beststats = Zmalloc (sizeof (SymbolStats ));
1609
1617
InitStats (statsdb [xx ].beststats );
@@ -1633,7 +1641,7 @@ static void ZopfliUseThreads(const ZopfliOptions* options,
1633
1641
if (calci > options -> numiterations ) calci = options -> numiterations ;
1634
1642
}
1635
1643
thrprogress = (int )(((zfloat )t [showthread ].iterations .iteration / (zfloat )calci ) * 100 );
1636
- usleep (250000 );
1644
+ usleep (125000 );
1637
1645
fprintf (stderr ,"%3d%% T:%2d | B:%4d | M:%s%s%s%s | I:%5d (%d) - %d (%d) b \r" ,
1638
1646
thrprogress , showthread , ((unsigned int )t [showthread ].iterations .block + 1 ),
1639
1647
(t [showthread ].mode & 0x8 )? "1" : "0" ,
@@ -1648,7 +1656,7 @@ static void ZopfliUseThreads(const ZopfliOptions* options,
1648
1656
showthread = 0 ;
1649
1657
showcntr = 0 ;
1650
1658
}
1651
- if (showcntr > 4 ) {
1659
+ if (showcntr > 8 ) {
1652
1660
if (threadsrunning > 1 ) {
1653
1661
++ showthread ;
1654
1662
if (showthread >=numthreads )
0 commit comments