summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRye Mutt <rye@alchemyviewer.org>2024-07-04 05:02:46 -0400
committerRye Mutt <rye@alchemyviewer.org>2024-07-05 02:56:25 -0400
commit6cf176900f0c89e20557742dbcd1174799440f8f (patch)
tree187a9665453a058f283b7adb2487493daa6890e5
parent7df1edbde100d1c07bd4d2edcfa76ea7a870de42 (diff)
Add move construction/assignment support for LLSD type
-rw-r--r--indra/llcommon/llsd.cpp37
-rw-r--r--indra/llcommon/llsd.h21
2 files changed, 40 insertions, 18 deletions
diff --git a/indra/llcommon/llsd.cpp b/indra/llcommon/llsd.cpp
index 0576182c98..2bbe06e72f 100644
--- a/indra/llcommon/llsd.cpp
+++ b/indra/llcommon/llsd.cpp
@@ -106,6 +106,9 @@ public:
static void reset(Impl*& var, Impl* impl);
///< safely set var to refer to the new impl (possibly shared)
+ static void move(Impl*& var, Impl*& impl);
+ ///< safely move impl from one object to another
+
static Impl& safe( Impl*);
static const Impl& safe(const Impl*);
///< since a NULL Impl* is used for undefined, this ensures there is
@@ -232,7 +235,7 @@ namespace
};
- class ImplBoolean
+ class ImplBoolean final
: public ImplBase<LLSD::TypeBoolean, LLSD::Boolean, LLSD::Boolean, LLSD::Boolean&&>
{
public:
@@ -255,7 +258,7 @@ namespace
{ return mValue ? "true" : ""; }
- class ImplInteger
+ class ImplInteger final
: public ImplBase<LLSD::TypeInteger, LLSD::Integer, LLSD::Integer, LLSD::Integer&&>
{
public:
@@ -273,7 +276,7 @@ namespace
{ return llformat("%d", mValue); }
- class ImplReal
+ class ImplReal final
: public ImplBase<LLSD::TypeReal, LLSD::Real, LLSD::Real, LLSD::Real&&>
{
public:
@@ -297,7 +300,7 @@ namespace
{ return llformat("%lg", mValue); }
- class ImplString
+ class ImplString final
: public ImplBase<LLSD::TypeString, LLSD::String, const LLSD::String&, LLSD::String&&>
{
public:
@@ -357,7 +360,7 @@ namespace
}
- class ImplUUID
+ class ImplUUID final
: public ImplBase<LLSD::TypeUUID, LLSD::UUID, const LLSD::UUID&, LLSD::UUID&&>
{
public:
@@ -371,7 +374,7 @@ namespace
};
- class ImplDate
+ class ImplDate final
: public ImplBase<LLSD::TypeDate, LLSD::Date, const LLSD::Date&, LLSD::Date&&>
{
public:
@@ -398,7 +401,7 @@ namespace
};
- class ImplURI
+ class ImplURI final
: public ImplBase<LLSD::TypeURI, LLSD::URI, const LLSD::URI&, LLSD::URI&&>
{
public:
@@ -412,7 +415,7 @@ namespace
};
- class ImplBinary
+ class ImplBinary final
: public ImplBase<LLSD::TypeBinary, LLSD::Binary, const LLSD::Binary&, LLSD::Binary&&>
{
public:
@@ -425,7 +428,7 @@ namespace
};
- class ImplMap : public LLSD::Impl
+ class ImplMap final : public LLSD::Impl
{
private:
typedef std::map<LLSD::String, LLSD, std::less<>> DataMap;
@@ -539,7 +542,6 @@ namespace
DataMap::iterator i = mData.lower_bound(k);
if (i == mData.end() || mData.key_comp()(k, i->first))
{
-
return mData.emplace_hint(i, std::make_pair(k, LLSD()))->second;
}
@@ -577,7 +579,7 @@ namespace
{
//std::cout << " " << (*iter).first << ": " << (*iter).second << std::endl;
Impl::calcStats((*iter).second, type_counts, share_counts);
- iter++;
+ ++iter;
}
// Add in the values for this map
@@ -774,6 +776,16 @@ void LLSD::Impl::reset(Impl*& var, Impl* impl)
var = impl;
}
+void LLSD::Impl::move(Impl*& var, Impl*& impl)
+{
+ if (var && var->mUseCount != STATIC_USAGE_COUNT && --var->mUseCount == 0)
+ {
+ delete var; // destroy var if usage falls to 0 and not static
+ }
+ var = impl; // Steal impl to var without incrementing use since this is a move
+ impl = nullptr; // null out old-impl pointer
+}
+
LLSD::Impl& LLSD::Impl::safe(Impl* impl)
{
static Impl theUndefined(STATIC_USAGE_COUNT);
@@ -954,6 +966,9 @@ LLSD::~LLSD() { FREE_LLSD_OBJECT; Impl::reset(impl, 0)
LLSD::LLSD(const LLSD& other) : impl(0) { ALLOC_LLSD_OBJECT; assign(other); }
void LLSD::assign(const LLSD& other) { Impl::assign(impl, other.impl); }
+LLSD::LLSD(LLSD&& other) noexcept : impl(nullptr) { ALLOC_LLSD_OBJECT; Impl::move(impl, other.impl); }
+void LLSD::assign(LLSD&& other) { Impl::move(impl, other.impl); }
+LLSD& LLSD::operator=(LLSD&& other) noexcept { Impl::move(impl, other.impl); return *this; }
void LLSD::clear() { Impl::assignUndefined(impl); }
diff --git a/indra/llcommon/llsd.h b/indra/llcommon/llsd.h
index 77f1606554..781e8d58e9 100644
--- a/indra/llcommon/llsd.h
+++ b/indra/llcommon/llsd.h
@@ -161,6 +161,13 @@ public:
//@}
+ /** @name Movable */
+ //@{
+ LLSD(LLSD&& other) noexcept;
+ void assign(LLSD&& other);
+ LLSD& operator=(LLSD&& other) noexcept;
+ //@}
+
void clear(); ///< resets to Undefined
@@ -330,14 +337,14 @@ public:
LLSD& operator[](const std::string_view);
LLSD& operator[](const char* c)
- {
- return c ? (*this)[std::string_view(c)] : *this;
- }
+ {
+ return c ? (*this)[std::string_view(c)] : *this;
+ }
const LLSD& operator[](const std::string_view) const;
- const LLSD& operator[](const char* c) const
- {
- return c ? (*this)[std::string_view(c)] : *this;
- }
+ const LLSD& operator[](const char* c) const
+ {
+ return c ? (*this)[std::string_view(c)] : *this;
+ }
//@}
/** @name Array Values */