From 28fee038e0e14e0538eefade38961e9ae1665d81 Mon Sep 17 00:00:00 2001 From: Rye Date: Sun, 11 Jan 2026 13:37:58 -0500 Subject: Optimize inventory parsing and inventory panel creation using std::unordered_map and reduce temporaries during inventory parse --- indra/llinventory/llinventory.cpp | 18 ++++++++---------- indra/newview/llinventorymodel.h | 8 ++++---- indra/newview/llinventorypanel.cpp | 3 +-- indra/newview/llinventorypanel.h | 2 +- indra/newview/llpanelobjectinventory.cpp | 2 +- indra/newview/llpanelobjectinventory.h | 2 +- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/indra/llinventory/llinventory.cpp b/indra/llinventory/llinventory.cpp index 3defad8f3b..f126accfb8 100644 --- a/indra/llinventory/llinventory.cpp +++ b/indra/llinventory/llinventory.cpp @@ -1017,10 +1017,9 @@ bool LLInventoryItem::fromLLSD(const LLSD& sd, bool is_new) if (i->first == INV_THUMBNAIL_LABEL) { const LLSD &thumbnail_map = i->second; - const std::string w = INV_ASSET_ID_LABEL; - if (thumbnail_map.has(w)) + if (thumbnail_map.has(INV_ASSET_ID_LABEL)) { - mThumbnailUUID = thumbnail_map[w]; + mThumbnailUUID = thumbnail_map[INV_ASSET_ID_LABEL]; } /* Example: asset_id @@ -1033,7 +1032,7 @@ bool LLInventoryItem::fromLLSD(const LLSD& sd, bool is_new) 1 */ continue; - } + } if (i->first == INV_THUMBNAIL_ID_LABEL) { @@ -1044,10 +1043,9 @@ bool LLInventoryItem::fromLLSD(const LLSD& sd, bool is_new) if (i->first == INV_FAVORITE_LABEL) { const LLSD& favorite_map = i->second; - const std::string w = INV_TOGGLED_LABEL; - if (favorite_map.has(w)) + if (favorite_map.has(INV_TOGGLED_LABEL)) { - mFavorite = favorite_map[w].asBoolean(); + mFavorite = favorite_map[INV_TOGGLED_LABEL].asBoolean(); } continue; } @@ -1111,7 +1109,7 @@ bool LLInventoryItem::fromLLSD(const LLSD& sd, bool is_new) LLSD const &label = i->second; if (label.isString()) { - mType = LLAssetType::lookup(label.asString().c_str()); + mType = LLAssetType::lookup(label.asStringRef().c_str()); } else if (label.isInteger()) { @@ -1126,7 +1124,7 @@ bool LLInventoryItem::fromLLSD(const LLSD& sd, bool is_new) LLSD const &label = i->second; if (label.isString()) { - mInventoryType = LLInventoryType::lookup(label.asString().c_str()); + mInventoryType = LLInventoryType::lookup(label.asStringRef().c_str()); } else if (label.isInteger()) { @@ -1290,7 +1288,7 @@ void LLInventoryCategory::packMessage(LLMessageSystem* msg) const bool LLInventoryCategory::fromLLSD(const LLSD& sd) { - std::string w; + std::string_view w; w = INV_FOLDER_ID_LABEL_WS; if (sd.has(w)) diff --git a/indra/newview/llinventorymodel.h b/indra/newview/llinventorymodel.h index 9fbabec8f3..05ada9121a 100644 --- a/indra/newview/llinventorymodel.h +++ b/indra/newview/llinventorymodel.h @@ -201,13 +201,13 @@ private: // the inventory using several different identifiers. // mInventory member data is the 'master' list of inventory, and // mCategoryMap and mItemMap store uuid->object mappings. - typedef std::map > cat_map_t; - typedef std::map > item_map_t; + typedef std::unordered_map > cat_map_t; + typedef std::unordered_map> item_map_t; cat_map_t mCategoryMap; item_map_t mItemMap; // This last set of indices is used to map parents to children. - typedef std::map parent_cat_map_t; - typedef std::map parent_item_map_t; + typedef std::unordered_map parent_cat_map_t; + typedef std::unordered_map parent_item_map_t; parent_cat_map_t mParentChildCategoryTree; parent_item_map_t mParentChildItemTree; diff --git a/indra/newview/llinventorypanel.cpp b/indra/newview/llinventorypanel.cpp index 8d57a4e7bb..06dd830416 100644 --- a/indra/newview/llinventorypanel.cpp +++ b/indra/newview/llinventorypanel.cpp @@ -2125,8 +2125,7 @@ LLFolderViewItem* LLInventoryPanel::getItemByID(const LLUUID& id) { LL_PROFILE_ZONE_SCOPED; - std::map::iterator map_it; - map_it = mItemMap.find(id); + auto map_it = mItemMap.find(id); if (map_it != mItemMap.end()) { return map_it->second; diff --git a/indra/newview/llinventorypanel.h b/indra/newview/llinventorypanel.h index dc2e304ab3..ca2d5814bc 100644 --- a/indra/newview/llinventorypanel.h +++ b/indra/newview/llinventorypanel.h @@ -300,7 +300,7 @@ protected: LLPointer mGroupedItemBridge; Params mParams; // stored copy of parameter block - std::map mItemMap; + std::unordered_map mItemMap; /** * Pointer to LLInventoryFolderViewModelBuilder. * diff --git a/indra/newview/llpanelobjectinventory.cpp b/indra/newview/llpanelobjectinventory.cpp index a31a54bb67..d27ce81e4f 100644 --- a/indra/newview/llpanelobjectinventory.cpp +++ b/indra/newview/llpanelobjectinventory.cpp @@ -1830,7 +1830,7 @@ void LLPanelObjectInventory::onFocusReceived() LLFolderViewItem* LLPanelObjectInventory::getItemByID( const LLUUID& id ) { - std::map::iterator map_it = mItemMap.find(id); + auto map_it = mItemMap.find(id); if (map_it != mItemMap.end()) { return map_it->second; diff --git a/indra/newview/llpanelobjectinventory.h b/indra/newview/llpanelobjectinventory.h index 154639e4bb..13e27b489c 100644 --- a/indra/newview/llpanelobjectinventory.h +++ b/indra/newview/llpanelobjectinventory.h @@ -109,7 +109,7 @@ protected: bool isSelectionRemovable(); private: - std::map mItemMap; + std::unordered_map mItemMap; LLScrollContainer* mScroller; LLFolderView* mFolders; -- cgit v1.3