Skip to content

Commit c6c0800

Browse files
committed
nitpicks
1 parent c5fd55e commit c6c0800

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

‎Framework/Core/include/Framework/Variant.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class Variant
322322

323323
template <typename T>
324324
requires(!is_specialization_v<T, std::vector>)
325-
Variant(T value) : mType{variant_trait_v<T>}
325+
Variant(T value) : mType{variant_trait_v<T>}, mSize{1}
326326
{
327327
variant_helper<decltype(value)>::set(&mStore, value);
328328
}
@@ -345,8 +345,7 @@ class Variant
345345
variant_helper<std::vector<std::string>>::set(&mStore, values);
346346
}
347347

348-
// A temporary vector cannot hand over its buffer to a Variant,
349-
// so creating one only to copy it is an error
348+
// Prevent constructing from a temporary vector to avoid double allocation
350349
template <typename T>
351350
Variant(std::vector<T>&&) = delete;
352351

@@ -366,7 +365,7 @@ class Variant
366365
// Assignment from a temporary vector has to be allowed because it is used, but copies
367366
// to make sure Variant owns its content
368367
template <typename T>
369-
Variant& operator=(std::vector<T>&& other) noexcept
368+
Variant& operator=(std::vector<T>&& other) //not noexcept because it allocates
370369
{
371370
*this = Variant(other);
372371
return *this;
@@ -430,7 +429,7 @@ class Variant
430429
LabeledArray<int>, LabeledArray<float>, LabeledArray<double>, LabeledArray<std::string>>::type;
431430
storage_t mStore;
432431
VariantType mType = VariantType::Unknown;
433-
size_t mSize = 1;
432+
size_t mSize = 0;
434433
};
435434

436435
inline Variant emptyDict() { return Variant(VariantType::Dict); }

0 commit comments

Comments
 (0)