diff --git a/deps/ox/src/ox/model/modelvalue.hpp b/deps/ox/src/ox/model/modelvalue.hpp index 0b72e3c3..22967567 100644 --- a/deps/ox/src/ox/model/modelvalue.hpp +++ b/deps/ox/src/ox/model/modelvalue.hpp @@ -345,11 +345,9 @@ class ModelObject { } constexpr ModelObject(ModelObject &&other) noexcept { - for (auto &f : other.m_fieldsOrder) { - auto &field = m_fieldsOrder.emplace_back(std::move(f)); - m_fields[field->name] = &field->value; - } - m_typeName = other.m_typeName; + m_fields = std::move(other.m_fields); + m_fieldsOrder = std::move(other.m_fieldsOrder); + m_typeName = std::move(other.m_typeName); m_typeVersion = other.m_typeVersion; } @@ -430,11 +428,9 @@ class ModelObject { if (&other == this) [[unlikely]] { return *this; } - for (auto &f : other.m_fieldsOrder) { - auto &field = m_fieldsOrder.emplace_back(std::move(f)); - m_fields[field->name] = &field->value; - } - m_typeName = other.m_typeName; + m_fields = std::move(other.m_fields); + m_fieldsOrder = std::move(other.m_fieldsOrder); + m_typeName = std::move(other.m_typeName); m_typeVersion = other.m_typeVersion; return *this; } @@ -509,6 +505,14 @@ class ModelUnion { m_unionIdx = other.m_unionIdx; } + constexpr ModelUnion(ModelUnion &&other) noexcept { + m_fieldsOrder = std::move(other.m_fieldsOrder); + m_fields = std::move(other.m_fields); + m_typeName = std::move(other.m_typeName); + m_typeVersion = other.m_typeVersion; + m_unionIdx = other.m_unionIdx; + } + static constexpr Result> make(const DescriptorType *type) noexcept { UniquePtr out(new ModelUnion); oxReturnError(out->setType(type)); @@ -674,13 +678,16 @@ constexpr ModelValue::ModelValue(ModelValue &&other) noexcept { other.m_data.str = new String; break; case Type::Union: - m_data.uni = new ModelUnion(*other.m_data.uni); + m_data.uni = other.m_data.uni; + other.m_data.uni = new ModelUnion; break; case Type::Object: - m_data.obj = new ModelObject(*other.m_data.obj); + m_data.obj = other.m_data.obj; + other.m_data.obj = new ModelObject; break; case Type::Vector: - m_data.vec = new ModelValueVector(*other.m_data.vec); + m_data.vec = other.m_data.vec; + other.m_data.vec = new ModelValueVector; break; } } @@ -839,13 +846,16 @@ constexpr ModelValue &ModelValue::operator=(ModelValue &&other) noexcept { other.m_data.str = new String; break; case Type::Object: - m_data.obj = new ModelObject(*other.m_data.obj); + m_data.obj = other.m_data.obj; + other.m_data.obj = new ModelObject; break; case Type::Union: - m_data.uni = new ModelUnion(*other.m_data.uni); + m_data.uni = other.m_data.uni; + other.m_data.uni = new ModelUnion; break; case Type::Vector: - m_data.vec = new ModelValueVector(*other.m_data.vec); + m_data.vec = other.m_data.vec; + other.m_data.vec = new ModelValueVector; break; } return *this; @@ -890,9 +900,7 @@ constexpr ModelValueVector::ModelValueVector(const ModelValueVector &other) noex } constexpr ModelValueVector::ModelValueVector(ModelValueVector &&other) noexcept { - for (auto &v : other.m_vec) { - m_vec.emplace_back(std::move(v)); - } + m_vec = std::move(other.m_vec); m_templateValue = std::move(other.m_templateValue); m_typeName = std::move(other.m_typeName); m_typeVersion = other.m_typeVersion; @@ -915,9 +923,7 @@ constexpr ModelValueVector &ModelValueVector::operator=(ModelValueVector &&other if (this == &other) { return *this; } - for (auto &v : other.m_vec) { - m_vec.emplace_back(std::move(v)); - } + m_vec = std::move(other.m_vec); m_templateValue = std::move(other.m_templateValue); m_typeName = std::move(other.m_typeName); m_typeVersion = other.m_typeVersion;