Reduce a bit the code bloat in hot paths/small functions

There is no need to bloat hot/small functions with
a ton of function calls and involving locales
for simple error messages.
pull/3094/head
jvoisin 4 years ago
parent 9bae89cc95
commit 22153cca7b

@ -199,9 +199,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener)
esm.skipRecord();
}
else {
std::stringstream error;
error << "Unknown record: " << n.toString();
throw std::runtime_error(error.str());
throw std::runtime_error("Unknown record: " + n.toString());
}
} else {
RecordId id = it->second->load(esm);

@ -135,11 +135,8 @@ void ESMReader::getHExact(void*p, int size)
{
getSubHeader();
if (size != static_cast<int> (mCtx.leftSub))
{
std::stringstream error;
error << "getHExact(): size mismatch (requested " << size << ", got " << mCtx.leftSub << ")";
fail(error.str());
}
fail("Size mismatch, requested " + std::to_string(size) + " but got "
+ std::to_string(mCtx.leftSub));
getExact(p, size);
}

@ -135,9 +135,9 @@ public:
getSubHeader();
if (mCtx.leftSub != sizeof(X))
{
std::stringstream error;
error << "getHT(): subrecord size mismatch (requested " << sizeof(X) << ", got " << mCtx.leftSub << ")";
fail(error.str());
fail("getHT(): subrecord size mismatch,requested "
+ std::to_string(sizeof(X)) + ", got"
+ std::to_string(mCtx.leftSub));
}
getT(x);
}

@ -65,31 +65,23 @@ size_t LowLevelFile::size ()
long oldPosition = ftell (mHandle);
if (oldPosition == -1)
{
std::ostringstream os;
os << "An ftell() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An ftell() call failed: " + std::string(strerror(errno)));
}
if (fseek (mHandle, 0, SEEK_END) != 0)
{
std::ostringstream os;
os << "An fseek() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An fseek() call failed: " + std::string(strerror(errno)));
}
long size = ftell (mHandle);
if (size == -1)
{
std::ostringstream os;
os << "An ftell() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An ftell() call failed: " + std::string(strerror(errno)));
}
if (fseek (mHandle, oldPosition, SEEK_SET) != 0)
{
std::ostringstream os;
os << "An fseek() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An fseek() call failed: " + std::string(strerror(errno)));
}
return size_t (size);
@ -101,9 +93,7 @@ void LowLevelFile::seek (size_t position)
if (fseek (mHandle, position, SEEK_SET) != 0)
{
std::ostringstream os;
os << "An fseek() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An fseek() call failed: " + std::string(strerror(errno)));
}
}
@ -114,9 +104,7 @@ size_t LowLevelFile::tell ()
long position = ftell (mHandle);
if (position == -1)
{
std::ostringstream os;
os << "An ftell() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An ftell() call failed: " + std::string(strerror(errno)));
}
return size_t (position);
@ -193,25 +181,19 @@ size_t LowLevelFile::size ()
if (oldPosition == size_t (-1))
{
std::ostringstream os;
os << "An lseek() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An lseek() call failed: " + std::string(strerror(errno)));
}
size_t size = ::lseek (mHandle, 0, SEEK_END);
if (size == size_t (-1))
{
std::ostringstream os;
os << "An lseek() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An lseek() call failed: " + std::string(strerror(errno)));
}
if (lseek (mHandle, oldPosition, SEEK_SET) == -1)
{
std::ostringstream os;
os << "An lseek() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An lseek() call failed: " + std::string(strerror(errno)));
}
return size;
@ -223,9 +205,7 @@ void LowLevelFile::seek (size_t position)
if (::lseek (mHandle, position, SEEK_SET) == -1)
{
std::ostringstream os;
os << "An lseek() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error ("An lseek() call failed: " + std::string(strerror(errno)));
}
}
@ -237,9 +217,7 @@ size_t LowLevelFile::tell ()
if (position == size_t (-1))
{
std::ostringstream os;
os << "An lseek() call failed: " << strerror(errno);
throw std::runtime_error (os.str ());
throw std::runtime_error("An lseek() call failed: " + std::string(strerror(errno)));
}
return position;

Loading…
Cancel
Save