diff --git a/core/io/plist.cpp b/core/io/plist.cpp index 26b8c39495a4..672d846d550f 100644 --- a/core/io/plist.cpp +++ b/core/io/plist.cpp @@ -658,7 +658,7 @@ bool PList::load_string(const String &p_string, String &r_err_out) { int pos = 0; bool in_plist = false; bool done_plist = false; - List> stack; + LocalVector> stack; String key; while (pos >= 0) { int open_token_s = p_string.find_char('<', pos); @@ -701,7 +701,7 @@ bool PList::load_string(const String &p_string, String &r_err_out) { // Add subnode end enter it. Ref dict = PListNode::new_dict(); dict->data_type = PList::PLNodeType::PL_NODE_TYPE_DICT; - if (!stack.back()->get()->push_subnode(dict, key)) { + if (!stack.back()->push_subnode(dict, key)) { r_err_out = "Can't push subnode, invalid parent type."; return false; } @@ -721,7 +721,7 @@ bool PList::load_string(const String &p_string, String &r_err_out) { if (token == "/dict") { // Exit current dict. - if (stack.is_empty() || stack.back()->get()->data_type != PList::PLNodeType::PL_NODE_TYPE_DICT) { + if (stack.is_empty() || stack.back()->data_type != PList::PLNodeType::PL_NODE_TYPE_DICT) { r_err_out = "Mismatched tag."; return false; } @@ -733,7 +733,7 @@ bool PList::load_string(const String &p_string, String &r_err_out) { if (!stack.is_empty()) { // Add subnode end enter it. Ref arr = PListNode::new_array(); - if (!stack.back()->get()->push_subnode(arr, key)) { + if (!stack.back()->push_subnode(arr, key)) { r_err_out = "Can't push subnode, invalid parent type."; return false; } @@ -753,7 +753,7 @@ bool PList::load_string(const String &p_string, String &r_err_out) { if (token == "/array") { // Exit current array. - if (stack.is_empty() || stack.back()->get()->data_type != PList::PLNodeType::PL_NODE_TYPE_ARRAY) { + if (stack.is_empty() || stack.back()->data_type != PList::PLNodeType::PL_NODE_TYPE_ARRAY) { r_err_out = "Mismatched tag."; return false; } @@ -800,7 +800,7 @@ bool PList::load_string(const String &p_string, String &r_err_out) { r_err_out = vformat("Invalid value type: %s.", token); return false; } - if (stack.is_empty() || !stack.back()->get()->push_subnode(var, key)) { + if (stack.is_empty() || !stack.back()->push_subnode(var, key)) { r_err_out = "Can't push subnode, invalid parent type."; return false; } diff --git a/core/object/object.cpp b/core/object/object.cpp index ef1ca8132cbd..a55ebc79023c 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -401,7 +401,7 @@ void Object::set_indexed(const Vector &p_names, const Variant &p_val r_valid = &valid; } - List value_stack; + LocalVector value_stack; value_stack.push_back(get(p_names[0], r_valid)); @@ -411,7 +411,7 @@ void Object::set_indexed(const Vector &p_names, const Variant &p_val } for (int i = 1; i < p_names.size() - 1; i++) { - value_stack.push_back(value_stack.back()->get().get_named(p_names[i], valid)); + value_stack.push_back(value_stack.back().get_named(p_names[i], valid)); if (r_valid) { *r_valid = valid; } @@ -425,7 +425,7 @@ void Object::set_indexed(const Vector &p_names, const Variant &p_val value_stack.push_back(p_value); // p_names[p_names.size() - 1] for (int i = p_names.size() - 1; i > 0; i--) { - value_stack.back()->prev()->get().set_named(p_names[i], value_stack.back()->get(), valid); + value_stack[value_stack.size() - 2].set_named(p_names[i], value_stack.back(), valid); value_stack.pop_back(); if (r_valid) { @@ -437,7 +437,7 @@ void Object::set_indexed(const Vector &p_names, const Variant &p_val } } - set(p_names[0], value_stack.back()->get(), r_valid); + set(p_names[0], value_stack.back(), r_valid); value_stack.pop_back(); ERR_FAIL_COND(!value_stack.is_empty()); diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index c281d70d9285..7e59b161dc48 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -57,6 +57,16 @@ class LocalVector { return data; } + T &back() { + CRASH_BAD_UNSIGNED_INDEX(0, count); + return data[count - 1]; + } + + const T &back() const { + CRASH_BAD_UNSIGNED_INDEX(0, count); + return data[count - 1]; + } + _FORCE_INLINE_ void push_back(T p_elem) { if (unlikely(count == capacity)) { capacity = tight ? (capacity + 1) : MAX((U)1, capacity << 1); @@ -71,6 +81,14 @@ class LocalVector { } } + void pop_back() { + ERR_FAIL_COND(count == 0); + count--; + if constexpr (!std::is_trivially_destructible_v && !force_trivial) { + data[count].~T(); + } + } + void remove_at(U p_index) { ERR_FAIL_UNSIGNED_INDEX(p_index, count); count--; diff --git a/editor/debugger/editor_visual_profiler.cpp b/editor/debugger/editor_visual_profiler.cpp index c1de540a0da3..c7bf55f437e6 100644 --- a/editor/debugger/editor_visual_profiler.cpp +++ b/editor/debugger/editor_visual_profiler.cpp @@ -51,7 +51,7 @@ void EditorVisualProfiler::add_frame_metric(const Metric &p_metric) { frame_metrics.write[last_metric] = p_metric; - List stack; + LocalVector stack; for (int i = 0; i < frame_metrics[last_metric].areas.size(); i++) { String name = frame_metrics[last_metric].areas[i].name; frame_metrics.write[last_metric].areas.write[i].color_cache = _get_color_from_signature(name); @@ -62,7 +62,7 @@ void EditorVisualProfiler::add_frame_metric(const Metric &p_metric) { } if (stack.size()) { - full_name = stack.back()->get() + name; + full_name = stack.back() + name; } else { full_name = name; } diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 9bf21a543884..e22eb45147f5 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -346,11 +346,11 @@ Vector FileSystemDock::get_uncollapsed_paths() const { // BFS to find all uncollapsed paths of the resource directory. TreeItem *res_subtree = root->get_first_child()->get_next(); if (res_subtree) { - List queue; + LocalVector queue; queue.push_back(res_subtree); while (!queue.is_empty()) { - TreeItem *ti = queue.back()->get(); + TreeItem *ti = queue.back(); queue.pop_back(); if (!ti->is_collapsed() && ti->get_child_count() > 0) { Variant path = ti->get_metadata(0); diff --git a/editor/plugins/tiles/tile_map_layer_editor.cpp b/editor/plugins/tiles/tile_map_layer_editor.cpp index 2a6759824195..be4546ddf536 100644 --- a/editor/plugins/tiles/tile_map_layer_editor.cpp +++ b/editor/plugins/tiles/tile_map_layer_editor.cpp @@ -1203,10 +1203,10 @@ HashMap TileMapLayerEditorTilesPlugin::_draw_bucket_fill( if (p_contiguous) { // Replace continuous tiles like the source. RBSet already_checked; - List to_check; + LocalVector to_check; to_check.push_back(p_coords); while (!to_check.is_empty()) { - Vector2i coords = to_check.back()->get(); + Vector2i coords = to_check.back(); to_check.pop_back(); if (!already_checked.has(coords)) { if (source_cell.source_id == edited_layer->get_cell_source_id(coords) && @@ -2726,10 +2726,10 @@ RBSet TileMapLayerEditorTerrainsPlugin::_get_cells_for_bucket_fill(Vec if (p_contiguous) { // Replace continuous tiles like the source. RBSet already_checked; - List to_check; + LocalVector to_check; to_check.push_back(p_coords); while (!to_check.is_empty()) { - Vector2i coords = to_check.back()->get(); + Vector2i coords = to_check.back(); to_check.pop_back(); if (!already_checked.has(coords)) { // Get the candidate cell pattern. diff --git a/modules/mono/editor/code_completion.cpp b/modules/mono/editor/code_completion.cpp index 94222f3d67d1..80dcf5d51acd 100644 --- a/modules/mono/editor/code_completion.cpp +++ b/modules/mono/editor/code_completion.cpp @@ -147,11 +147,11 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr } break; case CompletionKind::SCENE_PATHS: { Ref dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES); - List directories; + LocalVector directories; directories.push_back(dir_access->get_current_dir()); while (!directories.is_empty()) { - dir_access->change_dir(directories.back()->get()); + dir_access->change_dir(directories.back()); directories.pop_back(); dir_access->list_dir_begin();