diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-07-04 16:43:49 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-08-04 13:35:37 +0200 |
commit | c717d5c64baa5c63aca977e49b0ca2b5b0b0f4e0 (patch) | |
tree | ff2c84944e52305cc0b23599737ea9359febfd22 /core/templates/vector.h | |
parent | 20e4b90fe947d30bf8767fad536a263735be61fb (diff) |
Arrays: Zero new items of trivial types on resize() (bindings only)
This is not enabled by default in the core version for performance reasons,
as Vector/CowData are used in critical code paths where not zero'ing memory
which is going to be set later on can be important.
But for bindings / the scripting API, we make zero the new items by default
(which already happened for built types like Vector3, etc., but not for
trivial types like int, float).
Fixes #43033.
Co-authored-by: David Hoppenbrouwers <david@salt-inc.org>
Diffstat (limited to 'core/templates/vector.h')
-rw-r--r-- | core/templates/vector.h | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/core/templates/vector.h b/core/templates/vector.h index f3f5ed76a7..51595a75f5 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -89,6 +89,7 @@ public: _FORCE_INLINE_ void set(int p_index, const T &p_elem) { _cowdata.set(p_index, p_elem); } _FORCE_INLINE_ int size() const { return _cowdata.size(); } Error resize(int p_size) { return _cowdata.resize(p_size); } + Error resize_zeroed(int p_size) { return _cowdata.template resize<true>(p_size); } _FORCE_INLINE_ const T &operator[](int p_index) const { return _cowdata.get(p_index); } Error insert(int p_pos, T p_val) { return _cowdata.insert(p_pos, p_val); } int find(const T &p_val, int p_from = 0) const { return _cowdata.find(p_val, p_from); } |