From a35ffd976f57c898a8a16153dca6945cc1b7e1dd Mon Sep 17 00:00:00 2001 From: terminx Date: Sun, 18 Nov 2018 18:05:51 +0000 Subject: [PATCH] Rework osdfunc_fileinfo() git-svn-id: https://svn.eduke32.com/eduke32@7150 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/build/src/osd.cpp | 45 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/source/build/src/osd.cpp b/source/build/src/osd.cpp index 5e1df1f48..92aed15d0 100644 --- a/source/build/src/osd.cpp +++ b/source/build/src/osd.cpp @@ -270,52 +270,61 @@ static int osdfunc_echo(osdfuncparm_t const * const parm) static int osdfunc_fileinfo(osdfuncparm_t const * const parm) { - int32_t i,j; - if (parm->numparms != 1) return OSDCMD_SHOWHELP; - if ((i = kopen4load(parm->parms[0],0)) < 0) + int32_t h; + + if ((h = kopen4load(parm->parms[0],0)) < 0) { OSD_Printf("fileinfo: File \"%s\" not found.\n", parm->parms[0]); return OSDCMD_OK; } - char buf[256]; - uint32_t length = kfilelength(i); - int32_t crctime = timerGetTicks(); - uint32_t crc = 0; + int32_t crctime = timerGetTicks(); + uint32_t crcval = 0; + int32_t siz = 0; + + static constexpr int ReadSize = 65536; + auto *buf = (uint8_t *)Xmalloc(ReadSize); + do { - j = kread(i,buf,256); - crc = Bcrc32((uint8_t *)buf,j,crc); + siz = kread(h, buf, ReadSize); + crcval = Bcrc32((uint8_t *)buf, siz, crcval); } - while (j == 256); + while (siz == ReadSize); + crctime = timerGetTicks() - crctime; - klseek(i, 0, BSEEK_SET); + klseek(h, 0, BSEEK_SET); int32_t xxhtime = timerGetTicks(); + XXH32_state_t xxh; XXH32_reset(&xxh, 0x1337); + do { - j = kread(i, buf, 256); - XXH32_update(&xxh, (uint8_t *) buf, j); + siz = kread(h, buf, ReadSize); + XXH32_update(&xxh, (uint8_t *)buf, siz); } - while (j == 256); - uint32_t xxhash = XXH32_digest(&xxh); + while (siz == ReadSize); + + uint32_t const xxhash = XXH32_digest(&xxh); xxhtime = timerGetTicks() - xxhtime; - kclose(i); + Bfree(buf); OSD_Printf("fileinfo: %s\n" " File size: %d\n" " CRC-32: %08X (%g sec)\n" " xxHash: %08X (%g sec)\n", - parm->parms[0], length, - crc, (double)crctime/timerGetFreq(), + parm->parms[0], kfilelength(h), + crcval, (double)crctime/timerGetFreq(), xxhash, (double)xxhtime/timerGetFreq()); + kclose(h); + return OSDCMD_OK; }