#3505 Make checkFolderForContentsOfType cheaper

master
Andrey Kleshchev 2025-02-06 18:02:34 +02:00 committed by Andrey Kleshchev
parent 93a88e6025
commit df0634f0c4
3 changed files with 45 additions and 6 deletions

View File

@ -4231,14 +4231,9 @@ void LLFolderBridge::staticFolderOptionsMenu()
bool LLFolderBridge::checkFolderForContentsOfType(LLInventoryModel* model, LLInventoryCollectFunctor& is_type)
{
LLInventoryModel::cat_array_t cat_array;
LLInventoryModel::item_array_t item_array;
model->collectDescendentsIf(mUUID,
cat_array,
item_array,
return model->hasMatchingDescendents(mUUID,
LLInventoryModel::EXCLUDE_TRASH,
is_type);
return !item_array.empty();
}
void LLFolderBridge::buildContextMenuOptions(U32 flags, menuentry_vec_t& items, menuentry_vec_t& disabled_items)

View File

@ -1305,6 +1305,47 @@ void LLInventoryModel::collectDescendentsIf(const LLUUID& id,
}
}
bool LLInventoryModel::hasMatchingDescendents(const LLUUID& id,
bool include_trash,
LLInventoryCollectFunctor& matches)
{
if (!include_trash)
{
const LLUUID trash_id = findCategoryUUIDForType(LLFolderType::FT_TRASH);
if (trash_id.notNull() && (trash_id == id))
return false;
}
cat_array_t* cat_array = get_ptr_in_map(mParentChildCategoryTree, id);
if (cat_array)
{
for (auto& cat : *cat_array)
{
if (matches(cat, NULL))
{
return true;
}
if (hasMatchingDescendents(cat->getUUID(), include_trash, matches))
{
return true;
}
}
}
item_array_t* item_array = get_ptr_in_map(mParentChildItemTree, id);
if (item_array)
{
for (auto& item : *item_array)
{
if (matches(NULL, item))
{
return true;
}
}
}
return false;
}
void LLInventoryModel::addChangedMaskForLinks(const LLUUID& object_id, U32 mask)
{
const LLInventoryObject *obj = getObject(object_id);

View File

@ -287,6 +287,9 @@ public:
item_array_t& items,
bool include_trash,
LLInventoryCollectFunctor& add);
bool hasMatchingDescendents(const LLUUID& id,
bool include_trash,
LLInventoryCollectFunctor& add);
// Collect all items in inventory that are linked to item_id.
// Assumes item_id is itself not a linked item.