From cba18b006af4160992b45a931fbdca06f82c15a1 Mon Sep 17 00:00:00 2001
From: Guillermo Venegas <guillermovcra@gmail.com>
Date: Mon, 24 Mar 2025 16:03:55 +0100
Subject: [PATCH] Cleanup: UI: Avoid overallocation while adding button
 decorators

This will likely reserve a larger vector more than actually needed.
Reserve only the same count of decorators to be added, since they
likely match the number of buttons that needs to be temporally
retrieved.

Decorators buttons are added along animatable property buttons in each
`layout.prop` function call, when a property is a `XYZ` vector property,
drawing this property adds 3 inputs buttons and for each inputs buttons
this need to insert an aligned property decorator, since this decorators
are added just after the buttons are added this likely just takes out
temporally this last 3 elements and inserts them back with each
corresponding decorator.

Pull Request: https://projects.blender.org/blender/blender/pulls/136191
---
 source/blender/editors/interface/interface_layout.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/source/blender/editors/interface/interface_layout.cc b/source/blender/editors/interface/interface_layout.cc
index 0bdbb28ab5f..2fb52018908 100644
--- a/source/blender/editors/interface/interface_layout.cc
+++ b/source/blender/editors/interface/interface_layout.cc
@@ -2496,7 +2496,7 @@ void uiItemFullR(uiLayout *layout,
 
     /* Move temporarily last buts to avoid multiple reallocations while inserting decorators. */
     blender::Vector<std::unique_ptr<uiBut>> tmp;
-    tmp.reserve(block->buttons.capacity());
+    tmp.reserve(ui_decorate.len);
     while (but_decorate && but_decorate != block->buttons.last().get()) {
       tmp.append(block->buttons.pop_last());
     }
-- 
GitLab