diff options
| author | Rye <rye@alchemyviewer.org> | 2026-01-10 04:54:34 -0500 |
|---|---|---|
| committer | Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> | 2026-01-21 22:07:08 +0200 |
| commit | 8b3558e59f9c67abe4c958f01206bb630ee2311f (patch) | |
| tree | 12a6082d55b3fdbff69787c65a4b09797cab37f0 | |
| parent | 1b12a1dc76ee33a7e0394773492f92c1fdaa9c31 (diff) | |
Optimize map usage in name cache with unordered_map for maps with frequent find access
| -rw-r--r-- | indra/llmessage/llavatarnamecache.cpp | 18 | ||||
| -rw-r--r-- | indra/llmessage/llavatarnamecache.h | 10 | ||||
| -rw-r--r-- | indra/llmessage/llcachename.cpp | 15 | ||||
| -rw-r--r-- | indra/llmessage/llcachename.h | 3 |
4 files changed, 23 insertions, 23 deletions
diff --git a/indra/llmessage/llavatarnamecache.cpp b/indra/llmessage/llavatarnamecache.cpp index ebafc53a4d..86b36315dc 100644 --- a/indra/llmessage/llavatarnamecache.cpp +++ b/indra/llmessage/llavatarnamecache.cpp @@ -276,7 +276,7 @@ void LLAvatarNameCache::handleAvNameCacheSuccess(const LLSD &data, const LLSD &h // Provide some fallback for agents that return errors void LLAvatarNameCache::handleAgentError(const LLUUID& agent_id) { - std::map<LLUUID,LLAvatarName>::iterator existing = mCache.find(agent_id); + cache_t::iterator existing = mCache.find(agent_id); if (existing == mCache.end()) { // there is no existing cache entry, so make a temporary name from legacy @@ -311,7 +311,7 @@ void LLAvatarNameCache::processName(const LLUUID& agent_id, const LLAvatarName& bool updated_account = true; // assume obsolete value for new arrivals by default - std::map<LLUUID, LLAvatarName>::iterator it = mCache.find(agent_id); + cache_t::iterator it = mCache.find(agent_id); if (it != mCache.end() && (*it).second.getAccountName() == av_name.getAccountName()) { @@ -418,7 +418,7 @@ void LLAvatarNameCache::legacyNameCallback(const LLUUID& agent_id, // Retrieve the name and set it to never (or almost never...) expire: when we are using the legacy // protocol, we do not get an expiration date for each name and there's no reason to ask the // data again and again so we set the expiration time to the largest value admissible. - std::map<LLUUID,LLAvatarName>::iterator av_record = LLAvatarNameCache::getInstance()->mCache.find(agent_id); + cache_t::iterator av_record = LLAvatarNameCache::getInstance()->mCache.find(agent_id); LLAvatarName& av_name = av_record->second; av_name.setExpires(MAX_UNREFRESHED_TIME); } @@ -631,7 +631,7 @@ bool LLAvatarNameCache::getName(const LLUUID& agent_id, LLAvatarName *av_name) if (mRunning) { // ...only do immediate lookups when cache is running - std::map<LLUUID,LLAvatarName>::iterator it = mCache.find(agent_id); + cache_t::iterator it = mCache.find(agent_id); if (it != mCache.end()) { *av_name = it->second; @@ -682,7 +682,7 @@ LLAvatarNameCache::callback_connection_t LLAvatarNameCache::getNameCallback(cons if (mRunning) { // ...only do immediate lookups when cache is running - std::map<LLUUID,LLAvatarName>::iterator it = mCache.find(agent_id); + cache_t::iterator it = mCache.find(agent_id); if (it != mCache.end()) { const LLAvatarName& av_name = it->second; @@ -753,13 +753,11 @@ void LLAvatarNameCache::insert(const LLUUID& agent_id, const LLAvatarName& av_na LLUUID LLAvatarNameCache::findIdByName(const std::string& name) { - std::map<LLUUID, LLAvatarName>::iterator it; - std::map<LLUUID, LLAvatarName>::iterator end = mCache.end(); - for (it = mCache.begin(); it != end; ++it) + for (const auto& [id, avatar_name] : mCache) { - if (it->second.getUserName() == name) + if (avatar_name.getUserName() == name) { - return it->first; + return id; } } diff --git a/indra/llmessage/llavatarnamecache.h b/indra/llmessage/llavatarnamecache.h index 0ddaee2aa1..6743943495 100644 --- a/indra/llmessage/llavatarnamecache.h +++ b/indra/llmessage/llavatarnamecache.h @@ -30,8 +30,10 @@ #include "llavatarname.h" // for convenience #include "llsingleton.h" +#include "lluuid.h" #include <boost/signals2.hpp> #include <set> +#include <unordered_map> class LLSD; class LLUUID; @@ -161,23 +163,23 @@ private: std::string mNameLookupURL; // Accumulated agent IDs for next query against service - typedef std::set<LLUUID> ask_queue_t; + using ask_queue_t = std::set<LLUUID>; ask_queue_t mAskQueue; // Agent IDs that have been requested, but with no reply. // Maps agent ID to frame time request was made. - typedef std::map<LLUUID, F64> pending_queue_t; + using pending_queue_t = std::unordered_map<LLUUID, F64>; pending_queue_t mPendingQueue; // Callbacks to fire when we received a name. // May have multiple callbacks for a single ID, which are // represented as multiple slots bound to the signal. // Avoid copying signals via pointers. - typedef std::map<LLUUID, callback_signal_t*> signal_map_t; + using signal_map_t = std::unordered_map<LLUUID, callback_signal_t*>; signal_map_t mSignalMap; // The cache at last, i.e. avatar names we know about. - typedef std::map<LLUUID, LLAvatarName> cache_t; + using cache_t = std::unordered_map<LLUUID, LLAvatarName>; cache_t mCache; // Time when unrefreshed cached names were checked last. diff --git a/indra/llmessage/llcachename.cpp b/indra/llmessage/llcachename.cpp index 56dfaef873..95b7bb8c3d 100644 --- a/indra/llmessage/llcachename.cpp +++ b/indra/llmessage/llcachename.cpp @@ -179,12 +179,11 @@ void ReplySender::flush() } } - -typedef std::set<LLUUID> AskQueue; -typedef std::list<PendingReply*> ReplyQueue; -typedef std::map<LLUUID,U32> PendingQueue; -typedef std::map<LLUUID, LLCacheNameEntry*> Cache; -typedef std::map<std::string, LLUUID> ReverseCache; +using AskQueue = std::set<LLUUID>; +using ReplyQueue = std::list<PendingReply*>; +using PendingQueue = std::unordered_map<LLUUID, U32>; +using Cache = std::unordered_map<LLUUID, LLCacheNameEntry*>; +using ReverseCache = std::unordered_map<std::string, LLUUID>; class LLCacheName::Impl { @@ -214,7 +213,7 @@ public: Impl(LLMessageSystem* msg); ~Impl(); - bool getName(const LLUUID& id, std::string& first, std::string& last, std::map<std::string, std::string>& default_names); + bool getName(const LLUUID& id, std::string& first, std::string& last, cache_map_t& default_names); boost::signals2::connection addPending(const LLUUID& id, const LLCacheNameCallback& callback); void addPending(const LLUUID& id, const LLHost& host); @@ -401,7 +400,7 @@ void LLCacheName::exportFile(std::ostream& ostr) } -bool LLCacheName::Impl::getName(const LLUUID& id, std::string& first, std::string& last, std::map<std::string, std::string>& default_names) +bool LLCacheName::Impl::getName(const LLUUID& id, std::string& first, std::string& last, cache_map_t &default_names) { if(id.isNull()) { diff --git a/indra/llmessage/llcachename.h b/indra/llmessage/llcachename.h index 609387b6de..a333eac0f5 100644 --- a/indra/llmessage/llcachename.h +++ b/indra/llmessage/llcachename.h @@ -136,7 +136,8 @@ public: void localizeCacheName(std::string key, std::string value); private: - std::map<std::string, std::string> mCacheName; + using cache_map_t = std::unordered_map<std::string, std::string>; + cache_map_t mCacheName; class Impl; Impl& impl; |
