From 3fce3d14d6b8e367f4136efbfe87fcfcb23a4c8e Mon Sep 17 00:00:00 2001
From: Nat Goodspeed <nat@lindenlab.com>
Date: Tue, 7 Mar 2023 17:39:03 -0500
Subject: [PATCH] DRTVWR-558: Avoid extra copy of getMetadata() LLSD map.

(cherry picked from commit 2c1253c8ed2a1648317e6edd768b3fda00c56ce2)
---
 indra/llcommon/lleventdispatcher.cpp | 20 ++++++++------------
 indra/llcommon/lleventdispatcher.h   |  2 +-
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/indra/llcommon/lleventdispatcher.cpp b/indra/llcommon/lleventdispatcher.cpp
index 5d18d8f6c47..99e2e74376e 100644
--- a/indra/llcommon/lleventdispatcher.cpp
+++ b/indra/llcommon/lleventdispatcher.cpp
@@ -394,10 +394,9 @@ struct LLEventDispatcher::LLSDDispatchEntry: public LLEventDispatcher::DispatchE
         return mFunc(event);
     }
 
-    LLSD addMetadata(LLSD meta) const override
+    LLSD getMetadata() const override
     {
-        meta["required"] = mRequired;
-        return meta;
+        return llsd::map("required", mRequired);
     }
 };
 
@@ -485,15 +484,14 @@ struct LLEventDispatcher::ArrayParamsDispatchEntry: public LLEventDispatcher::Pa
         return ParamsDispatchEntry::call(desc, args, fromMap, argskey);
     }
 
-    LLSD addMetadata(LLSD meta) const override
+    LLSD getMetadata() const override
     {
         LLSD array(LLSD::emptyArray());
         // Resize to number of arguments required
         if (mArity)
             array[mArity - 1] = LLSD();
         llassert_always(array.size() == mArity);
-        meta["required"] = array;
-        return meta;
+        return llsd::map("required", array);
     }
 };
 
@@ -568,11 +566,9 @@ struct LLEventDispatcher::MapParamsDispatchEntry: public LLEventDispatcher::Para
         return ParamsDispatchEntry::call(desc, mMapper.map(args), fromMap, argskey);
     }
 
-    LLSD addMetadata(LLSD meta) const override
+    LLSD getMetadata() const override
     {
-        meta["required"] = mRequired;
-        meta["optional"] = mOptional;
-        return meta;
+        return llsd::map("required", mRequired, "optional", mOptional);
     }
 };
 
@@ -733,10 +729,10 @@ LLSD LLEventDispatcher::getMetadata(const std::string& name) const
     {
         return LLSD();
     }
-    LLSD meta;
+    LLSD meta{ found->second->getMetadata() };
     meta["name"] = name;
     meta["desc"] = found->second->mDesc;
-    return found->second->addMetadata(meta);
+    return meta;
 }
 
 std::ostream& operator<<(std::ostream& out, const LLEventDispatcher& self)
diff --git a/indra/llcommon/lleventdispatcher.h b/indra/llcommon/lleventdispatcher.h
index db67d1b3618..939e3730e10 100644
--- a/indra/llcommon/lleventdispatcher.h
+++ b/indra/llcommon/lleventdispatcher.h
@@ -472,7 +472,7 @@ class LL_COMMON_API LLEventDispatcher
 
         virtual LLSD call(const std::string& desc, const LLSD& event,
                           bool fromMap, const std::string& argskey) const = 0;
-        virtual LLSD addMetadata(LLSD) const = 0;
+        virtual LLSD getMetadata() const = 0;
 
         template <typename... ARGS>
         LLSD callFail(ARGS&&... args) const
-- 
GitLab