-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] Fix sharing of typed arrays from constructor #89197
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -46,10 +46,15 @@ class TypedArray : public Array { | |||||||||
_ref(p_array); | ||||||||||
} | ||||||||||
_FORCE_INLINE_ TypedArray(const Variant &p_variant) : | ||||||||||
Array(Array(p_variant), Variant::OBJECT, T::get_class_static(), Variant()) { | ||||||||||
TypedArray(Array(p_variant)) { | ||||||||||
} | ||||||||||
_FORCE_INLINE_ TypedArray(const Array &p_array) : | ||||||||||
Array(p_array, Variant::OBJECT, T::get_class_static(), Variant()) { | ||||||||||
_FORCE_INLINE_ TypedArray(const Array &p_array) { | ||||||||||
set_typed(Variant::OBJECT, T::get_class_static(), Variant()); | ||||||||||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Alternatively, to reduce duplication even further |
||||||||||
if (is_same_typed(p_array)) { | ||||||||||
_ref(p_array); | ||||||||||
} else { | ||||||||||
assign(p_array); | ||||||||||
} | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively this block can be replaced by: if (p_array.get_typed_builtin() == Variant::OBJECT && p_array.get_typed_class_name() == T::get_class_static() && p_array.get_typed_script() == Variant()) {
_ref(p_array);
} else {
set_typed(Variant::OBJECT, T::get_class_static(), Variant());
assign(p_array);
} To avoid doing the typing part, though in either case it will allocate private data possibly unnecessarily There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Then, I would keep the simplest version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I will and a future cleanup or improvement can hand that |
||||||||||
} | ||||||||||
_FORCE_INLINE_ TypedArray() { | ||||||||||
set_typed(Variant::OBJECT, T::get_class_static(), Variant()); | ||||||||||
|
@@ -78,10 +83,15 @@ struct VariantInternalAccessor<const TypedArray<T> &> { | |||||||||
_ref(p_array); \ | ||||||||||
} \ | ||||||||||
_FORCE_INLINE_ TypedArray(const Variant &p_variant) : \ | ||||||||||
Array(Array(p_variant), m_variant_type, StringName(), Variant()) { \ | ||||||||||
TypedArray(Array(p_variant)) { \ | ||||||||||
} \ | ||||||||||
_FORCE_INLINE_ TypedArray(const Array &p_array) : \ | ||||||||||
Array(p_array, m_variant_type, StringName(), Variant()) { \ | ||||||||||
_FORCE_INLINE_ TypedArray(const Array &p_array) { \ | ||||||||||
set_typed(m_variant_type, StringName(), Variant()); \ | ||||||||||
if (is_same_typed(p_array)) { \ | ||||||||||
_ref(p_array); \ | ||||||||||
} else { \ | ||||||||||
assign(p_array); \ | ||||||||||
} \ | ||||||||||
} \ | ||||||||||
_FORCE_INLINE_ TypedArray() { \ | ||||||||||
set_typed(m_variant_type, StringName(), Variant()); \ | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified this by delegating to avoid copying code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm all in to simplify the code.