1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-04-11 10:06:43 +00:00

Reduce a bit the size of getHT

Factoring common code parts outside of a template
is apparently a good practise to reduce code duplication
(and the size of openmw by around 0.5%),
and should improve a bit the performances,
since the whole `std::to_string` * 2 + string concatenation
dance results in quite a lot of code, preventing inlining on my machine.
This commit is contained in:
jvoisin 2021-06-30 18:29:00 +02:00
parent ba3d66503f
commit 5aaac8e47e
2 changed files with 9 additions and 6 deletions

View file

@ -198,7 +198,7 @@ void ESMReader::skipHSubSize(int size)
{ {
skipHSub(); skipHSub();
if (static_cast<int> (mCtx.leftSub) != size) if (static_cast<int> (mCtx.leftSub) != size)
fail("skipHSubSize() mismatch"); reportSubSizeMismatch(mCtx.leftSub, size);
} }
void ESMReader::skipHSubUntil(const char *name) void ESMReader::skipHSubUntil(const char *name)

View file

@ -134,11 +134,7 @@ public:
{ {
getSubHeader(); getSubHeader();
if (mCtx.leftSub != sizeof(X)) if (mCtx.leftSub != sizeof(X))
{ reportSubSizeMismatch(sizeof(X), mCtx.leftSub);
fail("getHT(): subrecord size mismatch,requested "
+ std::to_string(sizeof(X)) + ", got"
+ std::to_string(mCtx.leftSub));
}
getT(x); getT(x);
} }
@ -261,6 +257,13 @@ public:
size_t getFileSize() const { return mFileSize; } size_t getFileSize() const { return mFileSize; }
private: private:
[[noreturn]] void reportSubSizeMismatch(size_t want, size_t got) {
fail("subrecord size mismatch, requested " +
std::to_string(want) +
", got" +
std::to_string(got));
}
void clearCtx(); void clearCtx();
Files::IStreamPtr mEsm; Files::IStreamPtr mEsm;