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

Merge branch 'reduce_esmreader' into 'master'

Reduce a bit std::stringstream's code bloat in hot/small functions

See merge request OpenMW/openmw!933
This commit is contained in:
psi29a 2021-06-18 22:53:25 +00:00
commit 4d95855dd5
4 changed files with 17 additions and 44 deletions

View file

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

View file

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

View file

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

View file

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