From 36e38027d844d6e95d4677760526d2fd2ce2b452 Mon Sep 17 00:00:00 2001 From: Misa Date: Fri, 3 Jul 2020 03:23:54 -0700 Subject: [PATCH] Simplify m_headers init, hardcode 128 less I don't know how no one realized that the for-loop to (poorly) initialize m_headers was basically unnecessary, and that the memset() should've just been used instead. Well, except it should also be replaced with SDL_memset(), but that's besides the point. Also, I decided to hardcode the 128 thing less, in case people want to fork the source code and make a build where it's changed. --- desktop_version/src/BinaryBlob.cpp | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/desktop_version/src/BinaryBlob.cpp b/desktop_version/src/BinaryBlob.cpp index 2a8ceb8b..a134fc97 100644 --- a/desktop_version/src/BinaryBlob.cpp +++ b/desktop_version/src/BinaryBlob.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include /* FIXME: Abstract to FileSystemUtils! */ #include @@ -10,16 +10,7 @@ binaryBlob::binaryBlob() { numberofHeaders = 0; - for (int i = 0; i < 128; i += 1) - { - m_headers[i].valid = false; - - for (int j = 0; j < 48; j += 1) - { - m_headers[i].name[j] = '\0'; - } - } - ::memset(m_headers, 0, 128 * sizeof(resourceheader)); + SDL_memset(m_headers, 0, sizeof(m_headers)); } #ifdef VVV_COMPILEMUSIC @@ -63,7 +54,7 @@ void binaryBlob::writeBinaryBlob(const char* _name) FILE *file = fopen(_name, "wb"); if (file != NULL) { - fwrite((char*) &m_headers, 1, sizeof(resourceheader) * 128, file); + fwrite((char*) &m_headers, 1, sizeof(m_headers), file); for (int i = 0; i < numberofHeaders; i += 1) { @@ -92,11 +83,11 @@ bool binaryBlob::unPackBinary(const char* name) size = PHYSFS_fileLength(handle); - PHYSFS_readBytes(handle, &m_headers, sizeof(resourceheader) * 128); + PHYSFS_readBytes(handle, &m_headers, sizeof(m_headers)); - int offset = 0 + (sizeof(resourceheader) * 128); + int offset = 0 + (sizeof(m_headers)); - for (int i = 0; i < 128; i += 1) + for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1) { /* Name can be stupid, just needs to be terminated */ m_headers[i].name[47] = '\0'; @@ -128,7 +119,7 @@ bool binaryBlob::unPackBinary(const char* name) printf("The complete reloaded file size: %lli\n", size); - for (int i = 0; i < 128; i += 1) + for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1) { if (m_headers[i].valid == false) { @@ -143,7 +134,7 @@ bool binaryBlob::unPackBinary(const char* name) void binaryBlob::clear() { - for (int i = 0; i < 128; i += 1) + for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1) { if (m_headers[i].valid) { @@ -155,7 +146,7 @@ void binaryBlob::clear() int binaryBlob::getIndex(const char* _name) { - for (int i = 0; i < 128; i += 1) + for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1) { if (strcmp(_name, m_headers[i].name) == 0) { @@ -178,7 +169,7 @@ char* binaryBlob::getAddress(int _index) std::vector binaryBlob::getExtra() { std::vector result; - for (int i = 0; i < 128; i += 1) + for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1) { if (m_headers[i].valid #define FOREACH_TRACK(track_name) && strcmp(m_headers[i].name, track_name) != 0