From 7a3c74e739461dd8f21de13e48dcc9560089b151 Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Sat, 3 Jan 2026 16:51:57 +0100 Subject: [PATCH] Add documentation to `Vector::reserve` and `Vector::reserve_exact`. --- core/templates/vector.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/templates/vector.h b/core/templates/vector.h index 562fdc8107..5ee45485b6 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -121,11 +121,20 @@ public: return _cowdata.template resize(p_size); } + /// Reserves capacity for at least p_size total elements. + /// You can use `reserve` before repeated insertions to improve performance. + /// The capacity grows in 1.5x increments when possible, and uses `p_size` + /// exactly otherwise. Error reserve(Size p_size) { ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER); return _cowdata.reserve(p_size); } + /// Reserves capacity for exactly p_size total elements. + /// This can be useful to reduce RAM use of large vectors, but wastes CPU + /// time if more than p_size elements are added after the `reserve_exact` call. + /// Prefer using `reserve`, unless the vector (or copies of it) will never + /// grow again after p_size elements are inserted. Error reserve_exact(Size p_size) { ERR_FAIL_COND_V(p_size < 0, ERR_INVALID_PARAMETER); return _cowdata.reserve_exact(p_size);