1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 17:39:40 +00:00

Add bound for pointers cache size, as it specified in docs

This commit is contained in:
Andrei Kortunov 2021-04-10 11:20:12 +04:00
parent 124a33d8a3
commit c989fac67b
2 changed files with 7 additions and 5 deletions

View file

@ -132,9 +132,11 @@ void MWWorld::Cells::writeCell (ESM::ESMWriter& writer, CellStore& cell) const
MWWorld::Cells::Cells (const MWWorld::ESMStore& store, std::vector<ESM::ESMReader>& reader) MWWorld::Cells::Cells (const MWWorld::ESMStore& store, std::vector<ESM::ESMReader>& reader)
: mStore (store), mReader (reader), : mStore (store), mReader (reader),
mIdCache (Settings::Manager::getInt("pointers cache size", "Cells"), std::pair<std::string, CellStore *> ("", (CellStore*)nullptr)),
mIdCacheIndex (0) mIdCacheIndex (0)
{} {
int cacheSize = std::max(Settings::Manager::getInt("pointers cache size", "Cells"), 0);
mIdCache = IdCache(cacheSize, std::pair<std::string, CellStore *> ("", (CellStore*)nullptr));
}
MWWorld::CellStore *MWWorld::Cells::getExterior (int x, int y) MWWorld::CellStore *MWWorld::Cells::getExterior (int x, int y)
{ {
@ -259,8 +261,7 @@ MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name, CellStore& cell,
MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name) MWWorld::Ptr MWWorld::Cells::getPtr (const std::string& name)
{ {
// First check the cache // First check the cache
for (std::vector<std::pair<std::string, CellStore *> >::iterator iter (mIdCache.begin()); for (IdCache::iterator iter (mIdCache.begin()); iter!=mIdCache.end(); ++iter)
iter!=mIdCache.end(); ++iter)
if (iter->first==name && iter->second) if (iter->first==name && iter->second)
{ {
Ptr ptr = getPtr (name, *iter->second); Ptr ptr = getPtr (name, *iter->second);

View file

@ -28,11 +28,12 @@ namespace MWWorld
/// \brief Cell container /// \brief Cell container
class Cells class Cells
{ {
typedef std::vector<std::pair<std::string, CellStore *> > IdCache;
const MWWorld::ESMStore& mStore; const MWWorld::ESMStore& mStore;
std::vector<ESM::ESMReader>& mReader; std::vector<ESM::ESMReader>& mReader;
mutable std::map<std::string, CellStore> mInteriors; mutable std::map<std::string, CellStore> mInteriors;
mutable std::map<std::pair<int, int>, CellStore> mExteriors; mutable std::map<std::pair<int, int>, CellStore> mExteriors;
std::vector<std::pair<std::string, CellStore *> > mIdCache; IdCache mIdCache;
std::size_t mIdCacheIndex; std::size_t mIdCacheIndex;
Cells (const Cells&); Cells (const Cells&);