From 5aaac8e47e90891c3868e88978becf4ff991fe14 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 30 Jun 2021 18:29:00 +0200 Subject: [PATCH] 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. --- components/esm/esmreader.cpp | 2 +- components/esm/esmreader.hpp | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/esm/esmreader.cpp b/components/esm/esmreader.cpp index a30ad2c069..0cf7c3f81f 100644 --- a/components/esm/esmreader.cpp +++ b/components/esm/esmreader.cpp @@ -198,7 +198,7 @@ void ESMReader::skipHSubSize(int size) { skipHSub(); if (static_cast (mCtx.leftSub) != size) - fail("skipHSubSize() mismatch"); + reportSubSizeMismatch(mCtx.leftSub, size); } void ESMReader::skipHSubUntil(const char *name) diff --git a/components/esm/esmreader.hpp b/components/esm/esmreader.hpp index 6129147d33..608222a1bb 100644 --- a/components/esm/esmreader.hpp +++ b/components/esm/esmreader.hpp @@ -134,11 +134,7 @@ public: { getSubHeader(); if (mCtx.leftSub != sizeof(X)) - { - fail("getHT(): subrecord size mismatch,requested " - + std::to_string(sizeof(X)) + ", got" - + std::to_string(mCtx.leftSub)); - } + reportSubSizeMismatch(sizeof(X), mCtx.leftSub); getT(x); } @@ -261,6 +257,13 @@ public: size_t getFileSize() const { return mFileSize; } 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(); Files::IStreamPtr mEsm;