From 541b44b873738a6b954125b31bca5f18c328bade Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Thu, 24 Oct 2024 15:17:01 -0400
Subject: Add LL::ResultSet subclass VectorResultSet for the simple case.

Update existing simple LL::ResultSet subclasses.
---
 indra/newview/llagentlistener.cpp     | 24 +++++++--------------
 indra/newview/llinventorylistener.cpp | 40 +++++++++++------------------------
 2 files changed, 20 insertions(+), 44 deletions(-)

(limited to 'indra/newview')

diff --git a/indra/newview/llagentlistener.cpp b/indra/newview/llagentlistener.cpp
index 2810cd6706..3d07ead95d 100644
--- a/indra/newview/llagentlistener.cpp
+++ b/indra/newview/llagentlistener.cpp
@@ -729,15 +729,11 @@ void LLAgentListener::getID(LLSD const& event_data)
     Response response(llsd::map("id", gAgentID), event_data);
 }
 
-struct AvResultSet : public LL::ResultSet
+struct AvResultSet : public LL::VectorResultSet<LLVOAvatar*>
 {
-    AvResultSet() : LL::ResultSet("nearby_avatars") {}
-    std::vector<LLVOAvatar*> mAvatars;
-
-    int getLength() const override { return narrow(mAvatars.size()); }
-    LLSD getSingle(int index) const override
+    AvResultSet() : super("nearby_avatars") {}
+    LLSD getSingleFrom(LLVOAvatar* const& av) const override
     {
-        auto av = mAvatars[index];
         LLAvatarName av_name;
         LLAvatarNameCache::get(av->getID(), &av_name);
         LLVector3 region_pos = av->getCharacterPosition();
@@ -749,15 +745,11 @@ struct AvResultSet : public LL::ResultSet
     }
 };
 
-struct ObjResultSet : public LL::ResultSet
+struct ObjResultSet : public LL::VectorResultSet<LLViewerObject*>
 {
-    ObjResultSet() : LL::ResultSet("nearby_objects") {}
-    std::vector<LLViewerObject*> mObjects;
-
-    int getLength() const override { return narrow(mObjects.size()); }
-    LLSD getSingle(int index) const override
+    ObjResultSet() : super("nearby_objects") {}
+    LLSD getSingleFrom(LLViewerObject* const& obj) const override
     {
-        auto obj = mObjects[index];
         return llsd::map("id", obj->getID(),
                          "global_pos", ll_sd_from_vector3d(obj->getPositionGlobal()),
                          "region_pos", ll_sd_from_vector3(obj->getPositionRegion()),
@@ -791,7 +783,7 @@ void LLAgentListener::getNearbyAvatarsList(LLSD const& event_data)
         {
             if ((dist_vec_squared(avatar->getPositionGlobal(), agent_pos) <= radius))
             {
-                avresult->mAvatars.push_back(avatar);
+                avresult->mVector.push_back(avatar);
             }
         }
     }
@@ -813,7 +805,7 @@ void LLAgentListener::getNearbyObjectsList(LLSD const& event_data)
         {
             if ((dist_vec_squared(object->getPositionGlobal(), agent_pos) <= radius))
             {
-                objresult->mObjects.push_back(object);
+                objresult->mVector.push_back(object);
             }
         }
     }
diff --git a/indra/newview/llinventorylistener.cpp b/indra/newview/llinventorylistener.cpp
index 88b07c0b0b..13ca12a69a 100644
--- a/indra/newview/llinventorylistener.cpp
+++ b/indra/newview/llinventorylistener.cpp
@@ -107,15 +107,11 @@ LLInventoryListener::LLInventoryListener()
 
 // This struct captures (possibly large) category results from
 // getDirectDescendants() and collectDescendantsIf().
-struct CatResultSet: public LL::ResultSet
+struct CatResultSet: public LL::VectorResultSet<LLInventoryModel::cat_array_t::value_type>
 {
-    CatResultSet(): LL::ResultSet("categories") {}
-    LLInventoryModel::cat_array_t mCategories;
-
-    int getLength() const override { return narrow(mCategories.size()); }
-    LLSD getSingle(int index) const override
+    CatResultSet(): super("categories") {}
+    LLSD getSingleFrom(const LLPointer<LLViewerInventoryCategory>& cat) const override
     {
-        auto cat = mCategories[index];
         return llsd::map("id", cat->getUUID(),
                          "name", cat->getName(),
                          "parent_id", cat->getParentUUID(),
@@ -125,15 +121,11 @@ struct CatResultSet: public LL::ResultSet
 
 // This struct captures (possibly large) item results from
 // getDirectDescendants() and collectDescendantsIf().
-struct ItemResultSet: public LL::ResultSet
+struct ItemResultSet: public LL::VectorResultSet<LLInventoryModel::item_array_t::value_type>
 {
-    ItemResultSet(): LL::ResultSet("items") {}
-    LLInventoryModel::item_array_t mItems;
-
-    int getLength() const override { return narrow(mItems.size()); }
-    LLSD getSingle(int index) const override
+    ItemResultSet(): super("items") {}
+    LLSD getSingleFrom(const LLPointer<LLViewerInventoryItem>& item) const override
     {
-        auto item = mItems[index];
         return llsd::map("id", item->getUUID(),
                          "name", item->getName(),
                          "parent_id", item->getParentUUID(),
@@ -160,14 +152,14 @@ void LLInventoryListener::getItemsInfo(LLSD const &data)
         LLViewerInventoryItem* item = gInventory.getItem(it);
         if (item)
         {
-            itemresult->mItems.push_back(item);
+            itemresult->mVector.push_back(item);
         }
         else
         {
             LLViewerInventoryCategory *cat = gInventory.getCategory(it);
             if (cat)
             {
-                catresult->mCategories.push_back(cat);
+                catresult->mVector.push_back(cat);
             }
         }
     }
@@ -202,8 +194,8 @@ void LLInventoryListener::getDirectDescendants(LLSD const &data)
     auto catresult = new CatResultSet;
     auto itemresult = new ItemResultSet;
 
-    catresult->mCategories = *cats;
-    itemresult->mItems = *items;
+    catresult->mVector = *cats;
+    itemresult->mVector = *items;
 
     response["categories"] = catresult->getKeyLength();
     response["items"] = itemresult->getKeyLength();
@@ -260,8 +252,8 @@ void LLInventoryListener::collectDescendantsIf(LLSD const &data)
     // collectDescendentsIf() method so it doesn't steal too many cycles.
     gInventory.collectDescendentsIf(
         folder_id,
-        catresult->mCategories,
-        itemresult->mItems,
+        catresult->mVector,
+        itemresult->mVector,
         LLInventoryModel::EXCLUDE_TRASH,
         collector);
 
@@ -269,14 +261,6 @@ void LLInventoryListener::collectDescendantsIf(LLSD const &data)
     response["items"] = itemresult->getKeyLength();
 }
 
-/*==========================================================================*|
-void LLInventoryListener::getSingle(LLSD const& data)
-{
-    auto result = LL::ResultSet::getInstance(data["result"]);
-    sendReply(llsd::map("single", result->getSingle(data["index"])), data);
-}
-|*==========================================================================*/
-
 void LLInventoryListener::getSlice(LLSD const& data)
 {
     auto result = LL::ResultSet::getInstance(data["result"]);
-- 
cgit v1.2.3