Browse Source

Merge pull request #190 from dpogue/pagemap

plResManager performance fix
Adam Johnson 12 years ago
parent
commit
31a9862167
  1. 16
      Sources/Plasma/CoreLib/plString.cpp
  2. 6
      Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.cpp
  3. 9
      Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h
  4. 5
      Sources/Plasma/PubUtilLib/plResMgr/plPageInfo.cpp
  5. 4
      Sources/Plasma/PubUtilLib/plResMgr/plPageInfo.h
  6. 77
      Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp
  7. 3
      Sources/Plasma/PubUtilLib/plResMgr/plResManager.h

16
Sources/Plasma/CoreLib/plString.cpp

@ -74,8 +74,8 @@ void plString::IConvertFromUtf8(const char *utf8, size_t size, bool steal)
return;
}
if ((long)size < 0)
size = strnlen(utf8, -(long)size);
if ((int32_t)size < 0)
size = strnlen(utf8, -(int32_t)size);
#ifdef _DEBUG
// Check to make sure the string is actually valid UTF-8
@ -113,8 +113,8 @@ void plString::IConvertFromUtf16(const uint16_t *utf16, size_t size)
return;
}
if ((long)size < 0)
size = u16slen(utf16, -(long)size);
if ((int32_t)size < 0)
size = u16slen(utf16, -(int32_t)size);
// Calculate the UTF-8 size
size_t convlen = 0;
@ -189,8 +189,8 @@ void plString::IConvertFromWchar(const wchar_t *wstr, size_t size)
return;
}
if ((long)size < 0)
size = wcsnlen(wstr, -(long)size);
if ((int32_t)size < 0)
size = wcsnlen(wstr, -(int32_t)size);
// Calculate the UTF-8 size
size_t convlen = 0;
@ -251,8 +251,8 @@ void plString::IConvertFromIso8859_1(const char *astr, size_t size)
return;
}
if ((long)size < 0)
size = strnlen(astr, -(long)size);
if ((int32_t)size < 0)
size = strnlen(astr, -(int32_t)size);
// Calculate the UTF-8 size
size_t convlen = 0;

6
Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.cpp

@ -76,12 +76,6 @@ plLocation& plLocation::operator=(const plLocation& rhs)
return *this;
}
hsBool plLocation::operator==(const plLocation& u) const
{
// Ignore the itinerant flag when comparing, because
return (fSequenceNumber == u.fSequenceNumber) && ((fFlags & ~kItinerant) == (u.fFlags & ~kItinerant));
}
void plLocation::Set(uint32_t seqNum)
{
fSequenceNumber = seqNum;

9
Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h

@ -89,7 +89,7 @@ protected:
kNormalLocStartIdx = kLocalLocEndIdx + 1,
kReservedLocStart = 0xff000000, // Reserved locations are ones that aren't real game locations,
kReservedLocStart = 0xff000000, // Reserved locations are ones that aren't real game locations,
kGlobalServerLocIdx = kReservedLocStart, // Global pool room for the server. Only the server gets this one
kReservedLocAvailableStart = kGlobalServerLocIdx + 1, // This is the start of the *really* available ones
@ -119,7 +119,12 @@ public:
void Read(hsStream* s);
void Write(hsStream* s) const;
hsBool operator==(const plLocation& loc) const;
hsBool operator==(const plLocation& loc) const
{
// Ignore the itinerant flag when comparing, because
return (fSequenceNumber == loc.fSequenceNumber) &&
((fFlags & ~kItinerant) == (loc.fFlags & ~kItinerant));
}
hsBool operator!=(const plLocation& loc) const { return !(loc == *this); }
plLocation& operator=(const plLocation& loc);
bool operator<(const plLocation& loc ) const { return fSequenceNumber < loc.fSequenceNumber; }

5
Sources/Plasma/PubUtilLib/plResMgr/plPageInfo.cpp

@ -120,11 +120,6 @@ void plPageInfo::AddClassVersion(uint16_t classIdx, uint16_t version)
fClassVersions.push_back(cv);
}
const plLocation& plPageInfo::GetLocation() const
{
return fLocation;
}
void plPageInfo::Read( hsStream *s )
{
delete [] fAge;

4
Sources/Plasma/PubUtilLib/plResMgr/plPageInfo.h

@ -65,7 +65,7 @@ protected:
char* fPage;
uint16_t fMajorVersion;
ClassVerVec fClassVersions;
uint32_t fChecksum;
uint32_t fChecksum;
uint32_t fDataStart, fIndexStart;
void IInit( void );
@ -90,7 +90,7 @@ public:
void SetStrings( const char *age, const char *page );
void SetLocation(const plLocation& loc);
const plLocation& GetLocation() const;
const plLocation& GetLocation() const { return fLocation; }
uint16_t GetMajorVersion() const { return fMajorVersion; }
void SetMajorVersion(uint16_t major) { fMajorVersion = major; }

77
Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp

@ -140,7 +140,8 @@ hsBool plResManager::IInit()
pathIterator.GetPathAndName(fileName);
plRegistryPageNode* node = new plRegistryPageNode(fileName);
fAllPages.insert(node);
plPageInfo pi = node->GetPageInfo();
fAllPages[pi.GetLocation()] = node;
}
}
@ -217,9 +218,9 @@ void plResManager::IShutdown()
// Shut down the registry (finally!)
ILockPages();
PageSet::const_iterator it;
PageMap::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); it++)
delete *it;
delete it->second;
fAllPages.clear();
fLoadedPages.clear();
@ -240,11 +241,11 @@ void plResManager::AddSinglePage(const char* pagePath)
plRegistryPageNode* plResManager::FindSinglePage(const char* path) const
{
PageSet::const_iterator it;
PageMap::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); it++)
{
if (hsStrCaseEQ((*it)->GetPagePath(), path))
return *it;
if (hsStrCaseEQ((it->second)->GetPagePath(), path))
return it->second;
}
return nil;
@ -255,7 +256,8 @@ void plResManager::RemoveSinglePage(const char* path)
plRegistryPageNode* node = FindSinglePage(path);
if (node)
{
fAllPages.erase(node);
plLocation loc = node->GetPageInfo().GetLocation();
fAllPages.erase(loc);
delete node;
}
}
@ -1303,21 +1305,22 @@ void plResManager::PageInAge(const char *age)
hsBool plResManager::VerifyPages()
{
hsTArray<plRegistryPageNode*> invalidPages, newerPages;
PageMap::iterator it = fAllPages.begin();
// Step 1: verify major/minor version changes
if (plResMgrSettings::Get().GetFilterNewerPageVersions() ||
plResMgrSettings::Get().GetFilterOlderPageVersions())
{
PageSet::iterator it = fAllPages.begin();
while (it != fAllPages.end())
{
plRegistryPageNode* page = *it;
it++;
plLocation loc = it->first;
plRegistryPageNode* page = it->second;
++it;
if (page->GetPageCondition() == kPageTooNew && plResMgrSettings::Get().GetFilterNewerPageVersions())
{
newerPages.Append(page);
fAllPages.erase(page);
fAllPages.erase(loc);
}
else if (
(page->GetPageCondition() == kPageCorrupt ||
@ -1325,7 +1328,7 @@ hsBool plResManager::VerifyPages()
&& plResMgrSettings::Get().GetFilterOlderPageVersions())
{
invalidPages.Append(page);
fAllPages.erase(page);
fAllPages.erase(loc);
}
}
}
@ -1345,7 +1348,8 @@ hsBool plResManager::VerifyPages()
}
// Step 2 of verification: make sure no sequence numbers conflict
PageSet::iterator it = fAllPages.begin();
// This isn't possible with a std::map
/*PageSet::iterator it = fAllPages.begin();
for (; it != fAllPages.end(); it++)
{
plRegistryPageNode* page = *it;
@ -1362,15 +1366,15 @@ hsBool plResManager::VerifyPages()
break;
}
}
}
}*/
// Redo our loaded pages list, since Verify() might force the page's keys to load or unload
fLoadedPages.clear();
it = fAllPages.begin();
while (it != fAllPages.end())
{
plRegistryPageNode* page = *it;
it++;
plRegistryPageNode* page = it->second;
++it;
if (page->IsLoaded())
fLoadedPages.insert(page);
@ -1511,7 +1515,7 @@ void plResManager::DumpUnusedKeys(plRegistryPageNode* page) const
plRegistryPageNode* plResManager::CreatePage(const plLocation& location, const char* age, const char* page)
{
plRegistryPageNode* pageNode = new plRegistryPageNode(location, age, page, fDataPath.c_str());
fAllPages.insert(pageNode);
fAllPages[location] = pageNode;
return pageNode;
}
@ -1520,7 +1524,9 @@ plRegistryPageNode* plResManager::CreatePage(const plLocation& location, const c
void plResManager::AddPage(plRegistryPageNode* page)
{
fAllPages.insert(page);
plLocation loc = page->GetPageInfo().GetLocation();
fAllPages[loc] = page;
if (page->IsLoaded())
fLoadedPages.insert(page);
}
@ -1627,15 +1633,11 @@ plRegistryPageNode* plResManager::FindPage(const plLocation& location) const
if (fLastFoundPage != nil && fLastFoundPage->GetPageInfo().GetLocation() == location)
return fLastFoundPage;
PageSet::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); it++)
PageMap::const_iterator it = fAllPages.find(location);
if (it != fAllPages.end())
{
const plLocation& pageloc = (*it)->GetPageInfo().GetLocation();
if (pageloc == location)
{
fLastFoundPage = *it;
return fLastFoundPage;
}
fLastFoundPage = it->second;
return it->second;
}
return nil;
@ -1645,13 +1647,13 @@ plRegistryPageNode* plResManager::FindPage(const plLocation& location) const
plRegistryPageNode* plResManager::FindPage(const char* age, const char* page) const
{
PageSet::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); it++)
PageMap::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); ++it)
{
const plPageInfo& info = (*it)->GetPageInfo();
const plPageInfo& info = (it->second)->GetPageInfo();
if (hsStrCaseEQ(info.GetAge(), age) &&
hsStrCaseEQ(info.GetPage(), page))
return *it;
return it->second;
}
return nil;
@ -1786,13 +1788,14 @@ hsBool plResManager::IterateAllPages(plRegistryPageIterator* iterator)
{
ILockPages();
PageSet::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); it++)
PageMap::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); ++it)
{
plRegistryPageNode* page = *it;
if (page->GetPageInfo().GetLocation() == plLocation::kGlobalFixedLoc)
if (it->first == plLocation::kGlobalFixedLoc)
continue;
plRegistryPageNode* page = it->second;
if (!iterator->EatPage(page))
{
IUnlockPages();
@ -1830,10 +1833,10 @@ void plResManager::IUnlockPages()
fLoadedPages.clear();
PageSet::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); it++)
PageMap::const_iterator it;
for (it = fAllPages.begin(); it != fAllPages.end(); ++it)
{
plRegistryPageNode* page = *it;
plRegistryPageNode* page = it->second;
if (page->IsLoaded())
fLoadedPages.insert(page);
}

3
Sources/Plasma/PubUtilLib/plResMgr/plResManager.h

@ -235,7 +235,8 @@ protected:
hsBool fPagesNeedCleanup; // True if something modified the page lists while they were locked.
typedef std::set<plRegistryPageNode*> PageSet;
PageSet fAllPages; // All the pages, loaded or not
typedef std::map<plLocation, plRegistryPageNode*> PageMap;
PageMap fAllPages; // All the pages, loaded or not
PageSet fLoadedPages; // Just the loaded pages
mutable plRegistryPageNode* fLastFoundPage;

Loading…
Cancel
Save