From 9b8eb9d6fca2df187b432b4623207d0cdc12a625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Wed, 1 Nov 2023 13:06:17 +0100 Subject: [PATCH] Use `for`- instead of `while`-loop, improve comments --- src/engine/shared/datafile.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/engine/shared/datafile.cpp b/src/engine/shared/datafile.cpp index 15d7fd7fb..ca164b368 100644 --- a/src/engine/shared/datafile.cpp +++ b/src/engine/shared/datafile.cpp @@ -926,14 +926,13 @@ void CDataFileWriter::Finish() io_write(m_File, &UncompressedSize, sizeof(UncompressedSize)); } - // write m_pItems + // write items sorted by type for(int i = 0; i < MAX_ITEM_TYPES; i++) { if(m_pItemTypes[i].m_Num) { - // write all m_pItems in of this type - int k = m_pItemTypes[i].m_First; - while(k != -1) + // write all items of this type + for(int k = m_pItemTypes[i].m_First; k != -1; k = m_pItems[k].m_Next) { CDatafileItem Item; Item.m_TypeAndID = (i << 16) | m_pItems[k].m_ID; @@ -949,9 +948,6 @@ void CDataFileWriter::Finish() io_write(m_File, &Item, sizeof(Item)); if(m_pItems[k].m_pData != nullptr) io_write(m_File, m_pItems[k].m_pData, m_pItems[k].m_Size); - - // next - k = m_pItems[k].m_Next; } } }