From 88a401a2809b82a77c04fe65a29a60b1ae9c4c26 Mon Sep 17 00:00:00 2001 From: Blake Martin Date: Tue, 22 Aug 2017 15:10:19 -0500 Subject: [PATCH] Fixed a logic error introduced with the chunk offset + potentially sped up serialization a bit. --- easy_profiler_core/profile_manager.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/easy_profiler_core/profile_manager.h b/easy_profiler_core/profile_manager.h index 5c8ee90..73fdea3 100644 --- a/easy_profiler_core/profile_manager.h +++ b/easy_profiler_core/profile_manager.h @@ -456,7 +456,8 @@ public: // Temp to avoid extra load due to this* aliasing. uint16_t chunkOffset = m_chunkOffset; char* data = (char*)&m_chunks.back().data[0] + chunkOffset; - m_chunkOffset = chunkOffset + n + sizeof(uint16_t); + chunkOffset += n + sizeof(uint16_t); + m_chunkOffset = chunkOffset; unaligned_store16(data, n); data += sizeof(uint16_t); @@ -475,14 +476,11 @@ public: m_chunks.emplace_back(); char* data = (char*)&m_chunks.back().data[0]; - std::memcpy(data, &n, sizeof(uint16_t)); unaligned_store16(data, n); data += sizeof(uint16_t); - - // If there is enough space for at least another payload size, - // set it to zero. - if (chunkOffset < N-1) - unaligned_zero16(data + n); + + // We assume here that it takes more than one element to fill a chunk. + unaligned_zero16(data + n); return data; } @@ -538,11 +536,12 @@ public: const char* data = (char*)current->data; int_fast32_t chunkOffset = 0; // signed int so overflow is not checked. uint16_t payloadSize = unaligned_load16(data); - while (chunkOffset < MAX_CHUNK_OFFSET && unaligned_load16(data, &payloadSize) != 0) { + while ((chunkOffset < MAX_CHUNK_OFFSET) & (payloadSize != 0)) { const uint16_t chunkSize = sizeof(uint16_t) + payloadSize; _outputStream.write(data, chunkSize); data += chunkSize; chunkOffset += chunkSize; + unaligned_load16(data, &payloadSize); } current = current->prev;