Refactor save size calculation with SaveSizeCounter

SaveSizeCounter is introduced and used for calculating the save size of objects. The previous method of calculating save size directly in each class was replaced with a call to the SaveSizeCounter's calc method. This results in a cleaner, more maintainable code as the size calculation logic is now centralized in one class. It is more efficient and scalable as any changes to the calculation can be made in one place and will be reflected everywhere.
This commit is contained in:
IlushaShurupov 2023-08-01 07:41:09 +03:00
parent a918c83ec1
commit 0cefb47b66
6 changed files with 30 additions and 15 deletions

View file

@ -91,8 +91,7 @@ tp::alni ScriptSection::save_script_table_to_file_size(ScriptSection* self, Arch
}
// instructions
ASSERT(false)
// size += iter->mBytecode.mInstructions.saveSize();
size += tp::SaveSizeCounter::calc(iter->mBytecode.mInstructions);
}
size += sizeof(tp::alni); // objects mem offset
@ -125,7 +124,6 @@ void ScriptSection::save_script_table_to_file(ScriptSection* self, ArchiverOut&
}
// mInstructions
ASSERT(false)
file << iter->mBytecode.mInstructions;
}
@ -163,8 +161,7 @@ void load_constants(ScriptSection* self, ArchiverIn& file, tp::alni start_addr)
}
// instructions
ASSERT(false)
//file.setAddress(file.getAddress() + script->mBytecode.mInstructions.saveSize());
file.setAddress(file.getAddress() + tp::SaveSizeCounter::calc(script->mBytecode.mInstructions));
}
file.setAddress(addres);