mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-30 09:54:10 +03:00
Refactor extra binary blob tracks to not use STL data marshalling
Just like I refactored text splitting to no longer use std::vectors, std::strings, or temporary heap allocations, decreasing memory usage and improving performance; there's no reason to use a temporary heap-allocated std::vector to grab all extra binary blob indices, when instead the iteration can just be more immediate. Instead, what I've done is replaced binaryBlob::getExtra() with binaryBlob::nextExtra(), which takes in a pointer to an index variable, and will increment the index variable until it reaches an extra track. After the caller processes the extra track, it is the caller's responsibility to increment the variable again before passing it back to getExtra(). This avoids all heap allocations and brings down the memory usage of processing extra tracks.
This commit is contained in:
@@ -181,18 +181,24 @@ char* binaryBlob::getAddress(int _index)
|
||||
return m_memblocks[_index];
|
||||
}
|
||||
|
||||
std::vector<int> binaryBlob::getExtra()
|
||||
bool binaryBlob::nextExtra(size_t* start)
|
||||
{
|
||||
std::vector<int> result;
|
||||
for (size_t i = 0; i < SDL_arraysize(m_headers); i += 1)
|
||||
size_t* idx;
|
||||
|
||||
if (start == NULL)
|
||||
{
|
||||
if (m_headers[i].valid
|
||||
#define FOREACH_TRACK(_, track_name) && SDL_strcmp(m_headers[i].name, track_name) != 0
|
||||
return false;
|
||||
}
|
||||
|
||||
for (idx = start; *idx < SDL_arraysize(m_headers); *idx += 1)
|
||||
{
|
||||
if (m_headers[*idx].valid
|
||||
#define FOREACH_TRACK(_, track_name) && SDL_strcmp(m_headers[*idx].name, track_name) != 0
|
||||
TRACK_NAMES(_)
|
||||
#undef FOREACH_TRACK
|
||||
) {
|
||||
result.push_back(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user