Merge 9b3bcee71d
into 36847f6af0
commit
6e624af301
|
@ -190,6 +190,25 @@ struct _GlobalNilClass {
|
||||||
static _GlobalNil _nil;
|
static _GlobalNil _nil;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <class T, size_t Alignment = alignof(T)>
|
||||||
|
class UninitializedValue {
|
||||||
|
typename std::aligned_storage<sizeof(T), Alignment>::type data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UninitializedValue() {}
|
||||||
|
|
||||||
|
UninitializedValue(const UninitializedValue &) = delete;
|
||||||
|
UninitializedValue &operator=(const UninitializedValue &) = delete;
|
||||||
|
|
||||||
|
T &get() {
|
||||||
|
return *reinterpret_cast<T *>(&data);
|
||||||
|
}
|
||||||
|
|
||||||
|
T *ptr() {
|
||||||
|
return reinterpret_cast<T *>(&data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace godot
|
} // namespace godot
|
||||||
|
|
||||||
#endif // GODOT_MEMORY_HPP
|
#endif // GODOT_MEMORY_HPP
|
||||||
|
|
|
@ -459,15 +459,15 @@ Variant::operator Signal() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::operator Dictionary() const {
|
Variant::operator Dictionary() const {
|
||||||
Dictionary result;
|
UninitializedValue<Dictionary> result;
|
||||||
to_type_constructor[DICTIONARY](result._native_ptr(), _native_ptr());
|
to_type_constructor[DICTIONARY](result.ptr(), _native_ptr());
|
||||||
return result;
|
return result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::operator Array() const {
|
Variant::operator Array() const {
|
||||||
Array result;
|
UninitializedValue<Array> result;
|
||||||
to_type_constructor[ARRAY](result._native_ptr(), _native_ptr());
|
to_type_constructor[ARRAY](result.ptr(), _native_ptr());
|
||||||
return result;
|
return result.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
Variant::operator PackedByteArray() const {
|
Variant::operator PackedByteArray() const {
|
||||||
|
|
Loading…
Reference in New Issue