diff --git a/include/orm/tiny/concerns/hasattributes.hpp b/include/orm/tiny/concerns/hasattributes.hpp index 897d3dc41..0beae87f6 100644 --- a/include/orm/tiny/concerns/hasattributes.hpp +++ b/include/orm/tiny/concerns/hasattributes.hpp @@ -2133,10 +2133,6 @@ namespace Orm::Tiny::Concerns return attributes; } - C serializableAttributes; - if constexpr (HasReserveMethod) - serializableAttributes.reserve(attributes.size()); - // Get visible attributes only /* Compute visible keys on attributes map/vector, the intersection is needed to compute only keys that really exists. */ @@ -2144,6 +2140,10 @@ namespace Orm::Tiny::Concerns ranges::set_intersection(AttributeUtils::keys(attributes), visible, ranges::inserter(visibleKeys, visibleKeys.cend())); + C serializableAttributes; + if constexpr (HasReserveMethod) + serializableAttributes.reserve(attributes.size()); + for (const auto &[key, value] : attributes) if (visibleKeys.contains(key)) { if constexpr (std::is_same_v) @@ -2170,8 +2170,6 @@ namespace Orm::Tiny::Concerns if (hidden.empty()) return std::move(attributes); - QVariantMap serializableAttributes; - /* Remove hidden attributes, from the map container returned by the getSerializableVisibleAttributes()! */ /* Compute hidden keys on attributes map, the intersection is needed to compute @@ -2180,6 +2178,8 @@ namespace Orm::Tiny::Concerns ranges::set_intersection(AttributeUtils::keys(attributes), hidden, ranges::inserter(hiddenKeys, hiddenKeys.cend())); + QVariantMap serializableAttributes; + for (auto it = attributes.constBegin(); it != attributes.constEnd(); ++it ) @@ -2200,9 +2200,6 @@ namespace Orm::Tiny::Concerns if (hidden.empty()) return std::move(attributes); - QVector serializableAttributes; - serializableAttributes.reserve(attributes.size()); - /* Remove hidden attributes, from the vector container returned by the getSerializableVisibleAttributes()! */ /* Compute hidden keys on attributes vector, the intersection is needed @@ -2211,6 +2208,9 @@ namespace Orm::Tiny::Concerns ranges::set_intersection(AttributeUtils::keys(attributes), hidden, ranges::inserter(hiddenKeys, hiddenKeys.cend())); + QVector serializableAttributes; + serializableAttributes.reserve(attributes.size()); + for (auto &&[key, value] : attributes) if (!hiddenKeys.contains(key)) #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) diff --git a/include/orm/tiny/concerns/hasrelationships.hpp b/include/orm/tiny/concerns/hasrelationships.hpp index a693b3523..e78759bad 100644 --- a/include/orm/tiny/concerns/hasrelationships.hpp +++ b/include/orm/tiny/concerns/hasrelationships.hpp @@ -1473,10 +1473,6 @@ namespace Concerns if (visible.empty()) return relations; - RelationsContainerType serializableRelations; - if constexpr (HasReserveMethod) - serializableRelations.reserve(relations.size()); - // Get visible relations only /* Compute visible keys on relations map, the intersection is needed to compute only keys that really exists. */ @@ -1485,6 +1481,10 @@ namespace Concerns AttributeUtils::keys(relations), visible, ranges::inserter(visibleKeys, visibleKeys.cend())); + RelationsContainerType serializableRelations; + if constexpr (HasReserveMethod) + serializableRelations.reserve(relations.size()); + for (const auto &[key, value] : relations) if (visibleKeys.contains(key)) serializableRelations.emplace(key, value); @@ -1502,9 +1502,6 @@ namespace Concerns if (hidden.empty()) return std::move(relations); - RelationsContainer serializableRelations; - serializableRelations.reserve(relations.size()); - /* Remove hidden relations, from the map container returned by the getSerializableVisibleRelations()! */ /* Compute hidden keys on relations map, the intersection is needed to compute @@ -1514,6 +1511,9 @@ namespace Concerns AttributeUtils::keys(relations), hidden, ranges::inserter(hiddenKeys, hiddenKeys.cend())); + RelationsContainer serializableRelations; + serializableRelations.reserve(relations.size()); + for (auto &&[key, value] : relations) if (!hiddenKeys.contains(key)) serializableRelations.emplace(std::move(key), std::move(value)); // try_emplace() not needed