From 482fd1b8f1affac8c8ef208656db346a09971e29 Mon Sep 17 00:00:00 2001 From: Kitty Barnett Date: Tue, 29 Mar 2011 08:19:14 +0200 Subject: [PATCH] - internal : cache the UUID to the shared root folder (if present) -> worst case is when the #RLV folder doesn't exist (=no change in iterating compared to before) --HG-- branch : RLVa --- indra/newview/rlvinventory.cpp | 42 ++++++++++++++++++++++++++++------ indra/newview/rlvinventory.h | 37 ++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/indra/newview/rlvinventory.cpp b/indra/newview/rlvinventory.cpp index c9d4a8b5d2..8efb4c59a6 100644 --- a/indra/newview/rlvinventory.cpp +++ b/indra/newview/rlvinventory.cpp @@ -63,6 +63,30 @@ public: // RlvInventory member functions // +// Checked: 2011-03-28 (RLVa-1.3.0g) | Modified: RLVa-1.3.0g +RlvInventory::RlvInventory() + : m_fFetchStarted(false), m_fFetchComplete(false) +{ +} + +// Checked: 2011-03-28 (RLVa-1.3.0g) | Added: RLVa-1.3.0g +RlvInventory::~RlvInventory() +{ + if (gInventory.containsObserver(this)) + gInventory.removeObserver(this); +} + +// Checked: 2011-03-28 (RLVa-1.3.0g) | Added: RLVa-1.3.0g +void RlvInventory::changed(U32 mask) +{ + const LLInventoryModel::changed_items_t& idsChanged = gInventory.getChangedIDs(); + if (std::find(idsChanged.begin(), idsChanged.end(), m_idRlvRoot) != idsChanged.end()) + { + m_idRlvRoot.setNull(); + gInventory.removeObserver(this); + } +} + // Checked: 2010-02-28 (RLVa-1.2.0a) | Modified: RLVa-1.0.0h void RlvInventory::fetchSharedInventory() { @@ -213,25 +237,29 @@ bool RlvInventory::getPath(const uuid_vec_t& idItems, LLInventoryModel::cat_arra return (folders.count() != 0); } -// Checked: 2010-02-28 (RLVa-1.2.0a) | Modified: RLVa-1.0.0h -LLViewerInventoryCategory* RlvInventory::getSharedRoot() const +// Checked: 2011-03-28 (RLVa-1.3.0g) | Modified: RLVa-1.3.0g +const LLUUID& RlvInventory::getSharedRootID() const { - if (gInventory.isInventoryUsable()) + if ( (m_idRlvRoot.isNull()) && (gInventory.isInventoryUsable()) ) { LLInventoryModel::cat_array_t* pFolders; LLInventoryModel::item_array_t* pItems; gInventory.getDirectDescendentsOf(gInventory.getRootFolderID(), pFolders, pItems); if (pFolders) { // NOTE: we might have multiple #RLV folders so we'll just go with the first one we come across - LLViewerInventoryCategory* pFolder; + const LLViewerInventoryCategory* pFolder; for (S32 idxFolder = 0, cntFolder = pFolders->count(); idxFolder < cntFolder; idxFolder++) { - if ( ((pFolder = pFolders->get(idxFolder)) != NULL) && (RlvInventory::cstrSharedRoot == pFolder->getName()) ) - return pFolder; + if ( ((pFolder = pFolders->get(idxFolder)) != NULL) && (cstrSharedRoot == pFolder->getName()) ) + { + if (!gInventory.containsObserver((RlvInventory*)this)) + gInventory.addObserver((RlvInventory*)this); + m_idRlvRoot = pFolder->getUUID(); + } } } } - return NULL; + return m_idRlvRoot; } // Checked: 2010-02-28 (RLVa-1.2.0a) | Modified: RLVa-1.0.1a diff --git a/indra/newview/rlvinventory.h b/indra/newview/rlvinventory.h index 07eb7c20c6..7a88e7764b 100644 --- a/indra/newview/rlvinventory.h +++ b/indra/newview/rlvinventory.h @@ -29,30 +29,35 @@ // RlvInventory class declaration // -// TODO-RLVa: [RLVa-1.2.0] Make all of this static rather than a singleton? -class RlvInventory : public LLSingleton +class RlvInventory : public LLSingleton, public LLInventoryObserver { protected: - RlvInventory() : m_fFetchStarted(false), m_fFetchComplete(false) {} + RlvInventory(); +public: + ~RlvInventory(); + + // LLInventoryObserver override + /*virtual*/ void changed(U32 mask); /* * #RLV Shared inventory */ public: // Find all folders that match a supplied criteria (clears the output array) - bool findSharedFolders(const std::string& strCriteria, LLInventoryModel::cat_array_t& folders) const; + bool findSharedFolders(const std::string& strCriteria, LLInventoryModel::cat_array_t& folders) const; // Gets the shared path for any shared items present in idItems (clears the output array) - bool getPath(const uuid_vec_t& idItems, LLInventoryModel::cat_array_t& folders) const; + bool getPath(const uuid_vec_t& idItems, LLInventoryModel::cat_array_t& folders) const; // Returns a pointer to the shared root folder (if there is one) - LLViewerInventoryCategory* getSharedRoot() const; + LLViewerInventoryCategory* getSharedRoot() const; + const LLUUID& getSharedRootID() const; // Returns a subfolder of idParent that starts with strFolderName (exact match > partial match) - LLViewerInventoryCategory* getSharedFolder(const LLUUID& idParent, const std::string& strFolderName) const; + LLViewerInventoryCategory* getSharedFolder(const LLUUID& idParent, const std::string& strFolderName) const; // Looks up a folder from a path (relative to the shared root) - LLViewerInventoryCategory* getSharedFolder(const std::string& strPath) const; + LLViewerInventoryCategory* getSharedFolder(const std::string& strPath) const; // Returns the path of the supplied folder (relative to the shared root) - std::string getSharedPath(const LLViewerInventoryCategory* pFolder) const; + std::string getSharedPath(const LLViewerInventoryCategory* pFolder) const; // Returns TRUE if the supplied folder is a descendent of the #RLV folder - bool isSharedFolder(const LLUUID& idFolder); + bool isSharedFolder(const LLUUID& idFolder); /* * Inventory fetching @@ -76,8 +81,9 @@ public: * Member variables */ protected: - bool m_fFetchStarted; // TRUE if we fired off an inventory fetch - bool m_fFetchComplete; // TRUE if everything was fetched + bool m_fFetchStarted; // TRUE if we fired off an inventory fetch + bool m_fFetchComplete; // TRUE if everything was fetched + mutable LLUUID m_idRlvRoot; private: static const std::string cstrSharedRoot; @@ -227,6 +233,13 @@ public: // RlvInventory inlined member functions // +// Checked: 2011-03-28 (RLVa-1.3.0g) | Modified: RLVa-1.3.0g +inline LLViewerInventoryCategory* RlvInventory::getSharedRoot() const +{ + const LLUUID& idRlvRoot = getSharedRootID(); + return (idRlvRoot.notNull()) ? gInventory.getCategory(idRlvRoot) : NULL; +} + // Checked: 2010-03-19 (RLVa-1.2.0a) | Modified: RLVa-1.2.0a inline bool RlvInventory::isFoldedFolder(const LLInventoryCategory* pFolder, bool fCheckComposite) {