diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index cd4c7dd82fb8..69a10339f0c0 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -3691,6 +3691,7 @@ void RasterizerSceneGLES3::_render_uv2(const PagedArray draw_buffers; + draw_buffers.reserve(4); draw_buffers.push_back(GL_COLOR_ATTACHMENT0); draw_buffers.push_back(GL_COLOR_ATTACHMENT1); draw_buffers.push_back(GL_COLOR_ATTACHMENT2); diff --git a/drivers/gles3/shader_gles3.cpp b/drivers/gles3/shader_gles3.cpp index 83f74865f678..bc046566a0c7 100644 --- a/drivers/gles3/shader_gles3.cpp +++ b/drivers/gles3/shader_gles3.cpp @@ -578,6 +578,7 @@ bool ShaderGLES3::_load_from_cache(Version *p_version) { ERR_FAIL_COND_V_MSG(cache_variant_count != variant_count, false, "shader cache variant count mismatch, expected " + itos(variant_count) + " got " + itos(cache_variant_count)); //should not happen but check LocalVector> variants; + variants.reserve(cache_variant_count); for (int i = 0; i < cache_variant_count; i++) { uint32_t cache_specialization_count = f->get_32(); OAHashMap variant; diff --git a/platform/windows/display_server_windows.cpp b/platform/windows/display_server_windows.cpp index 0769603d8eb2..97a364cf70e4 100644 --- a/platform/windows/display_server_windows.cpp +++ b/platform/windows/display_server_windows.cpp @@ -2848,6 +2848,7 @@ Error DisplayServerWindows::dialog_show(String p_title, String p_description, Ve Char16String title = p_title.utf16(); Char16String message = p_description.utf16(); LocalVector buttons; + buttons.reserve(p_buttons.size()); for (String s : p_buttons) { buttons.push_back(s.utf16()); } @@ -6662,6 +6663,7 @@ void DisplayServerWindows::register_windows_driver() { DisplayServerWindows::~DisplayServerWindows() { LocalVector::Element *> to_remove; + to_remove.reserve(file_dialogs.size()); for (List::Element *E = file_dialogs.front(); E; E = E->next()) { FileDialogData *fd = E->get(); if (fd->listener_thread.is_started()) { diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp index aa4445a7ba84..da1b1369f517 100644 --- a/scene/3d/lightmap_gi.cpp +++ b/scene/3d/lightmap_gi.cpp @@ -1044,6 +1044,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa LocalVector new_probe_positions; HashMap positions_used; + new_probe_positions.reserve(8); for (uint32_t i = 0; i < 8; i++) { //insert bounding endpoints Vector3i pos; if (i & 1) { @@ -1259,6 +1260,8 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa LocalVector bsp_planes; LocalVector bsp_simplex_indices; PackedInt32Array tetrahedrons; + bsp_simplices.reserve(solved_simplices.size()); + bsp_simplex_indices.reserve(solved_simplices.size()); for (int i = 0; i < solved_simplices.size(); i++) { //Prepare a special representation of the simplex, which uses a BSP Tree diff --git a/scene/3d/retarget_modifier_3d.cpp b/scene/3d/retarget_modifier_3d.cpp index 90cc316a5670..a7ff7117b8df 100644 --- a/scene/3d/retarget_modifier_3d.cpp +++ b/scene/3d/retarget_modifier_3d.cpp @@ -274,6 +274,7 @@ void RetargetModifier3D::_retarget_global_pose() { } LocalVector source_poses; + source_poses.reserve(source_bone_ids.size()); if (influence < 1.0) { for (int source_bone_id : source_bone_ids) { source_poses.push_back(source_bone_id < 0 ? Transform3D() : source_skeleton->get_bone_global_rest(source_bone_id).interpolate_with(source_skeleton->get_bone_global_pose(source_bone_id), influence)); @@ -308,6 +309,7 @@ void RetargetModifier3D::_retarget_pose() { } LocalVector source_poses; + source_poses.reserve(source_bone_ids.size()); if (influence < 1.0) { for (int source_bone_id : source_bone_ids) { source_poses.push_back(source_bone_id < 0 ? Transform3D() : source_skeleton->get_bone_rest(source_bone_id).interpolate_with(source_skeleton->get_bone_pose(source_bone_id), influence)); diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp index 9cf5b19a5a36..07e11e46be6b 100644 --- a/scene/3d/skeleton_3d.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -1163,11 +1163,13 @@ void Skeleton3D::_process_modifiers() { real_t influence = mod->get_influence(); if (influence < 1.0) { LocalVector old_poses; + old_poses.reserve(get_bone_count()); for (int i = 0; i < get_bone_count(); i++) { old_poses.push_back(get_bone_pose(i)); } mod->process_modification(); LocalVector new_poses; + new_poses.reserve(get_bone_count()); for (int i = 0; i < get_bone_count(); i++) { new_poses.push_back(get_bone_pose(i)); } diff --git a/scene/property_utils.cpp b/scene/property_utils.cpp index 9cae7d2a3a8a..b5674e3ab8f8 100644 --- a/scene/property_utils.cpp +++ b/scene/property_utils.cpp @@ -226,6 +226,7 @@ static bool _collect_inheritance_chain(const Ref &p_state, const Nod } if (inheritance_states.size() > 0) { + r_states_stack.reserve(r_states_stack.size() + inheritance_states.size()); for (int i = inheritance_states.size() - 1; i >= 0; --i) { r_states_stack.push_back(inheritance_states[i]); } diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index 8c0e08790295..b023fbc7ed60 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -2173,6 +2173,7 @@ Error ArrayMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, flo //create surfacetools for each surface.. LocalVector> surfaces_tools; + surfaces_tools.reserve(lightmap_surfaces.size()); for (int i = 0; i < lightmap_surfaces.size(); i++) { Ref st; diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index c230cf1b7047..f5a422c57663 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -1057,6 +1057,7 @@ void SurfaceTool::append_from(const Ref &p_existing, int p_surface, const vertex_array.push_back(v); } + index_array.reserve(index_array.size() + nindices.size()); for (const int &index : nindices) { int dst_index = index + vfrom; index_array.push_back(dst_index); diff --git a/servers/rendering/rendering_device.cpp b/servers/rendering/rendering_device.cpp index 2fbafcbda37b..28288f975763 100644 --- a/servers/rendering/rendering_device.cpp +++ b/servers/rendering/rendering_device.cpp @@ -2164,6 +2164,7 @@ RDD::RenderPassID RenderingDevice::_render_pass_create(RenderingDeviceDriver *p_ LocalVector attachments; LocalVector attachment_remap; + attachment_remap.reserve(p_attachments.size()); for (int i = 0; i < p_attachments.size(); i++) { if (p_attachments[i].usage_flags == AttachmentFormat::UNUSED_ATTACHMENT) { @@ -2229,6 +2230,9 @@ RDD::RenderPassID RenderingDevice::_render_pass_create(RenderingDeviceDriver *p_ for (int i = 0; i < p_passes.size(); i++) { const FramebufferPass *pass = &p_passes[i]; RDD::Subpass &subpass = subpasses[i]; + subpass.color_references.reserve(pass->color_attachments.size()); + subpass.input_references.reserve(pass->input_attachments.size()); + subpass.resolve_references.reserve(pass->resolve_attachments.size()); TextureSamples texture_samples = TEXTURE_SAMPLES_1; bool is_multisample_first = true; @@ -2415,6 +2419,8 @@ RenderingDevice::FramebufferFormatID RenderingDevice::framebuffer_format_create_ Vector samples; LocalVector load_ops; LocalVector store_ops; + load_ops.reserve(p_attachments.size()); + store_ops.reserve(p_attachments.size()); for (int64_t i = 0; i < p_attachments.size(); i++) { load_ops.push_back(RDD::ATTACHMENT_LOAD_OP_CLEAR); store_ops.push_back(RDD::ATTACHMENT_STORE_OP_STORE); @@ -2554,6 +2560,7 @@ RID RenderingDevice::framebuffer_create_multipass(const Vector &p_texture_a Vector attachments; LocalVector textures; LocalVector trackers; + trackers.reserve(p_texture_attachments.size()); attachments.resize(p_texture_attachments.size()); Size2i size; bool size_set = false; @@ -3181,6 +3188,7 @@ RID RenderingDevice::uniform_set_create(const Collection &p_uniforms, RID p_shad RDD::BoundUniform &driver_uniform = driver_uniforms[i]; driver_uniform.type = uniform.uniform_type; driver_uniform.binding = uniform.binding; + driver_uniform.ids.reserve(uniform.get_id_count()); // Mark immutable samplers to be skipped when creating uniform set. driver_uniform.immutable_sampler = uniform.immutable_sampler; diff --git a/servers/rendering/shader_preprocessor.cpp b/servers/rendering/shader_preprocessor.cpp index 4a9d97fc4adc..575b45f43f42 100644 --- a/servers/rendering/shader_preprocessor.cpp +++ b/servers/rendering/shader_preprocessor.cpp @@ -368,6 +368,7 @@ String ShaderPreprocessor::vector_to_string(const LocalVector &p_v, in String ShaderPreprocessor::tokens_to_string(const LocalVector &p_tokens) { LocalVector result; + result.reserve(p_tokens.size()); for (const Token &token : p_tokens) { result.push_back(token.text); }