aboutsummaryrefslogtreecommitdiffstats
path: root/nihil.ucl/object.cc
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-29 17:16:22 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-29 17:16:22 +0100
commit4fa6821e0645ff61a9380cd090abff472205c630 (patch)
treebd95f13b2dc0bd9692681f50c365d2914a520bfe /nihil.ucl/object.cc
parente5180acf5f2dfac788e8c12886095ed1ac66fae5 (diff)
downloadnihil-4fa6821e0645ff61a9380cd090abff472205c630.tar.gz
nihil-4fa6821e0645ff61a9380cd090abff472205c630.tar.bz2
add clang-tidy support
Diffstat (limited to 'nihil.ucl/object.cc')
-rw-r--r--nihil.ucl/object.cc21
1 files changed, 6 insertions, 15 deletions
diff --git a/nihil.ucl/object.cc b/nihil.ucl/object.cc
index 9a150fb..53fc4c7 100644
--- a/nihil.ucl/object.cc
+++ b/nihil.ucl/object.cc
@@ -33,10 +33,12 @@ object::object(object &&other) noexcept
: m_object(std::exchange(other.m_object, nullptr))
{}
-object::object(object const &other) noexcept
+object::object(object const &other)
: m_object(nullptr)
{
- *this = other;
+ m_object = ::ucl_object_copy(other.get_ucl_object());
+ if (m_object == nullptr)
+ throw std::runtime_error("failed to copy UCL object");
}
auto object::operator=(this object &self, object &&other) noexcept
@@ -47,20 +49,9 @@ auto object::operator=(this object &self, object &&other) noexcept
return self;
}
-auto object::operator=(this object &self, object const &other)
- -> object &
+auto object::operator=(this object &self, object const &other) -> object &
{
- if (&self != &other) {
- auto *new_uobj = ::ucl_object_copy(other.get_ucl_object());
- if (new_uobj == nullptr)
- throw std::runtime_error("failed to copy UCL object");
-
- if (self.m_object != nullptr)
- ::ucl_object_unref(self.m_object);
- self.m_object = new_uobj;
- }
-
- return self;
+ return self = object(other);
}
auto object::ref(this object const &self) -> object