mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-01 13:09:42 +00:00
Teensy optimisation for esmtool
- Use an unordered_set instead of a list to keep track of skipped records. - Reduce the number of conditions when parsing 4-letters records by using a switch-case instead of cascading conditions. - Add a const
This commit is contained in:
parent
00de80c884
commit
e97e4d07dd
5 changed files with 16 additions and 16 deletions
|
@ -2,6 +2,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <unordered_set>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
@ -322,7 +323,7 @@ int load(Arguments& info)
|
||||||
std::string filename = info.filename;
|
std::string filename = info.filename;
|
||||||
std::cout << "Loading file: " << filename << std::endl;
|
std::cout << "Loading file: " << filename << std::endl;
|
||||||
|
|
||||||
std::list<uint32_t> skipped;
|
std::unordered_set<uint32_t> skipped;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -364,17 +365,17 @@ int load(Arguments& info)
|
||||||
// Loop through all records
|
// Loop through all records
|
||||||
while(esm.hasMoreRecs())
|
while(esm.hasMoreRecs())
|
||||||
{
|
{
|
||||||
ESM::NAME n = esm.getRecName();
|
const ESM::NAME n = esm.getRecName();
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
esm.getRecHeader(flags);
|
esm.getRecHeader(flags);
|
||||||
|
|
||||||
EsmTool::RecordBase *record = EsmTool::RecordBase::create(n);
|
EsmTool::RecordBase *record = EsmTool::RecordBase::create(n);
|
||||||
if (record == nullptr)
|
if (record == nullptr)
|
||||||
{
|
{
|
||||||
if (std::find(skipped.begin(), skipped.end(), n.intval) == skipped.end())
|
if (skipped.count(n.intval) == 0)
|
||||||
{
|
{
|
||||||
std::cout << "Skipping " << n.toString() << " records." << std::endl;
|
std::cout << "Skipping " << n.toString() << " records." << std::endl;
|
||||||
skipped.push_back(n.intval);
|
skipped.emplace(n.intval);
|
||||||
}
|
}
|
||||||
|
|
||||||
esm.skipRecord();
|
esm.skipRecord();
|
||||||
|
|
|
@ -172,7 +172,7 @@ void printTransport(const std::vector<ESM::Transport::Dest>& transport)
|
||||||
namespace EsmTool {
|
namespace EsmTool {
|
||||||
|
|
||||||
RecordBase *
|
RecordBase *
|
||||||
RecordBase::create(ESM::NAME type)
|
RecordBase::create(const ESM::NAME type)
|
||||||
{
|
{
|
||||||
RecordBase *record = nullptr;
|
RecordBase *record = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -110,15 +110,14 @@ struct FIXED_STRING<4> : public FIXED_STRING_BASE<FIXED_STRING, 4>
|
||||||
void assign(const std::string& value)
|
void assign(const std::string& value)
|
||||||
{
|
{
|
||||||
intval = 0;
|
intval = 0;
|
||||||
size_t length = value.size();
|
switch(value.size()) {
|
||||||
if (length == 0) return;
|
case 4: data[3] = value[3];
|
||||||
data[0] = value[0];
|
case 3: data[2] = value[2];
|
||||||
if (length == 1) return;
|
case 2: data[1] = value[1];
|
||||||
data[1] = value[1];
|
case 1: data[0] = value[0];
|
||||||
if (length == 2) return;
|
default: break;
|
||||||
data[2] = value[2];
|
}
|
||||||
if (length == 3) return;
|
|
||||||
data[3] = value[3];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char const* ro_data() const { return data; }
|
char const* ro_data() const { return data; }
|
||||||
|
|
|
@ -373,7 +373,7 @@ void ESMReader::setEncoder(ToUTF8::Utf8Encoder* encoder)
|
||||||
mEncoder = encoder;
|
mEncoder = encoder;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ESMReader::getFileOffset()
|
size_t ESMReader::getFileOffset() const
|
||||||
{
|
{
|
||||||
return mEsm->tellg();
|
return mEsm->tellg();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
void openRaw(const std::string &filename);
|
void openRaw(const std::string &filename);
|
||||||
|
|
||||||
/// Get the current position in the file. Make sure that the file has been opened!
|
/// Get the current position in the file. Make sure that the file has been opened!
|
||||||
size_t getFileOffset();
|
size_t getFileOffset() const;
|
||||||
|
|
||||||
// This is a quick hack for multiple esm/esp files. Each plugin introduces its own
|
// This is a quick hack for multiple esm/esp files. Each plugin introduces its own
|
||||||
// terrain palette, but ESMReader does not pass a reference to the correct plugin
|
// terrain palette, but ESMReader does not pass a reference to the correct plugin
|
||||||
|
|
Loading…
Reference in a new issue