Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace List with LocalVector if used as simple buffer #99936

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/io/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ bool DirAccess::drives_are_shortcuts() {
}

static Error _erase_recursive(DirAccess *da) {
List<String> dirs;
List<String> files;
LocalVector<String> dirs;
LocalVector<String> files;

da->list_dir_begin();
String n = da->get_next();
Expand Down Expand Up @@ -484,7 +484,7 @@ class DirChanger {
};

Error DirAccess::_copy_dir(Ref<DirAccess> &p_target_da, const String &p_to, int p_chmod_flags, bool p_copy_links) {
List<String> dirs;
LocalVector<String> dirs;

String curdir = get_current_dir();
list_dir_begin();
Expand Down
3 changes: 2 additions & 1 deletion core/io/packed_data_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd

List<Variant> keys;
d.get_key_list(&keys);
List<DictKey> sortk;
LocalVector<DictKey> sortk;
sortk.reserve(keys.size());

for (const Variant &key : keys) {
DictKey dk;
Expand Down
14 changes: 9 additions & 5 deletions core/object/class_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ uint32_t ClassDB::get_api_hash(APIType p_api) {

uint64_t hash = hash_murmur3_one_64(HashMapHasherDefault::hash(VERSION_FULL_CONFIG));

List<StringName> class_list;
LocalVector<StringName> class_list;
class_list.reserve(classes.size());
for (const KeyValue<StringName, ClassInfo> &E : classes) {
class_list.push_back(E.key);
}
Expand All @@ -399,7 +400,7 @@ uint32_t ClassDB::get_api_hash(APIType p_api) {

{ //methods

List<StringName> snames;
LocalVector<StringName> snames;

for (const KeyValue<StringName, MethodBind *> &F : t->method_map) {
String name = F.key.operator String();
Expand Down Expand Up @@ -444,7 +445,8 @@ uint32_t ClassDB::get_api_hash(APIType p_api) {

{ //constants

List<StringName> snames;
LocalVector<StringName> snames;
snames.reserve(t->constant_map.size());

for (const KeyValue<StringName, int64_t> &F : t->constant_map) {
snames.push_back(F.key);
Expand All @@ -460,7 +462,8 @@ uint32_t ClassDB::get_api_hash(APIType p_api) {

{ //signals

List<StringName> snames;
LocalVector<StringName> snames;
snames.reserve(t->signal_map.size());

for (const KeyValue<StringName, MethodInfo> &F : t->signal_map) {
snames.push_back(F.key);
Expand All @@ -479,7 +482,8 @@ uint32_t ClassDB::get_api_hash(APIType p_api) {

{ //properties

List<StringName> snames;
LocalVector<StringName> snames;
snames.reserve(t->property_setget.size());

for (const KeyValue<StringName, PropertySetGet> &F : t->property_setget) {
snames.push_back(F.key);
Expand Down
10 changes: 5 additions & 5 deletions core/object/script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ StringName ScriptServer::get_global_class_native_base(const String &p_class) {
}

void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) {
List<StringName> classes;
LocalVector<StringName> classes;
classes.reserve(r_global_classes->size());
for (const KeyValue<StringName, GlobalScriptClass> &E : global_classes) {
classes.push_back(E.key);
}
Expand Down Expand Up @@ -764,7 +765,7 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
}

properties = p_properties;
List<StringName> to_remove;
LocalVector<StringName> to_remove;

for (KeyValue<StringName, Variant> &E : values) {
if (!new_values.has(E.key)) {
Expand All @@ -780,9 +781,8 @@ void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties, c
}
}

while (to_remove.size()) {
values.erase(to_remove.front()->get());
to_remove.pop_front();
for (const StringName &E : to_remove) {
values.erase(E);
}

if (owner && owner->get_script_instance() == this) {
Expand Down
8 changes: 4 additions & 4 deletions drivers/gles3/storage/material_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ void MaterialData::update_textures(const HashMap<StringName, Variant> &p_paramet
}
{
//for textures no longer used, unregister them
List<StringName> to_delete;
LocalVector<StringName> to_delete;
for (KeyValue<StringName, uint64_t> &E : used_global_textures) {
if (E.value != global_textures_pass) {
to_delete.push_back(E.key);
Expand All @@ -1031,10 +1031,10 @@ void MaterialData::update_textures(const HashMap<StringName, Variant> &p_paramet
}
}

while (to_delete.front()) {
used_global_textures.erase(to_delete.front()->get());
to_delete.pop_front();
for (StringName &name : to_delete) {
used_global_textures.erase(name);
}

//handle registering/unregistering global textures
if (uses_global_textures != (global_texture_E != nullptr)) {
if (uses_global_textures) {
Expand Down
6 changes: 4 additions & 2 deletions editor/animation_bezier_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,8 @@ void AnimationBezierTrackEdit::duplicate_selected_keys(real_t p_ofs, bool p_ofs_
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Animation Duplicate Keys"));

List<Pair<int, real_t>> new_selection_values;
LocalVector<Pair<int, real_t>> new_selection_values;
new_selection_values.reserve(selection.size());

for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
real_t t = animation->track_get_key_time(E->get().first, E->get().second);
Expand Down Expand Up @@ -1883,7 +1884,8 @@ void AnimationBezierTrackEdit::paste_keys(real_t p_ofs, bool p_ofs_valid) {
WARN_PRINT("Pasted animation keys from multiple tracks into single Bezier track");
}

List<Pair<int, float>> new_selection_values;
LocalVector<Pair<int, float>> new_selection_values;
new_selection_values.reserve(editor->key_clipboard.keys.size());
for (int i = 0; i < editor->key_clipboard.keys.size(); i++) {
const AnimationTrackEditor::KeyClipboard::Key key = editor->key_clipboard.keys[i];

Expand Down
9 changes: 5 additions & 4 deletions editor/animation_track_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5837,7 +5837,7 @@ void AnimationTrackEditor::_move_selection_commit() {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Animation Move Keys"));

List<_AnimMoveRestore> to_restore;
LocalVector<_AnimMoveRestore> to_restore;

float motion = moving_selection_offset;
// 1 - remove the keys.
Expand Down Expand Up @@ -6146,7 +6146,7 @@ void AnimationTrackEditor::_anim_duplicate_keys(float p_ofs, bool p_ofs_valid, i
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Animation Duplicate Keys"));

List<Pair<int, float>> new_selection_values;
LocalVector<Pair<int, float>> new_selection_values;

for (RBMap<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
const SelectedKey &sk = E->key();
Expand Down Expand Up @@ -6295,7 +6295,8 @@ void AnimationTrackEditor::_anim_paste_keys(float p_ofs, bool p_ofs_valid, int p

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Animation Paste Keys"));
List<Pair<int, float>> new_selection_values;
LocalVector<Pair<int, float>> new_selection_values;
new_selection_values.reserve(key_clipboard.keys.size());

for (int i = 0; i < key_clipboard.keys.size(); i++) {
const KeyClipboard::Key key = key_clipboard.keys[i];
Expand Down Expand Up @@ -6678,7 +6679,7 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Animation Scale Keys"));

List<_AnimMoveRestore> to_restore;
LocalVector<_AnimMoveRestore> to_restore;

// 1 - Remove the keys.
for (RBMap<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
Expand Down
7 changes: 3 additions & 4 deletions editor/audio_stream_preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ AudioStreamPreviewGenerator *AudioStreamPreviewGenerator::singleton = nullptr;
void AudioStreamPreviewGenerator::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_PROCESS: {
List<ObjectID> to_erase;
LocalVector<ObjectID> to_erase;
for (KeyValue<ObjectID, Preview> &E : previews) {
if (!E.value.generating.is_set()) {
if (E.value.thread) {
Expand All @@ -240,9 +240,8 @@ void AudioStreamPreviewGenerator::_notification(int p_what) {
}
}

while (to_erase.front()) {
previews.erase(to_erase.front()->get());
to_erase.pop_front();
for (ObjectID &E : to_erase) {
previews.erase(E);
}
} break;
}
Expand Down
2 changes: 1 addition & 1 deletion editor/debugger/editor_visual_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ void EditorVisualProfiler::_update_frame(bool p_focus_selected) {
const Metric &m = frame_metrics[cursor_metric];

List<TreeItem *> stack;
List<TreeItem *> categories;
LocalVector<TreeItem *> categories;

TreeItem *ensure_selected = nullptr;

Expand Down
3 changes: 2 additions & 1 deletion editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,8 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
}

// Store first else we will be removing as we loop.
List<int> lines;
LocalVector<int> lines;
lines.reserve(file_item->get_child_count());
for (TreeItem *breakpoint_item = file_item->get_first_child(); breakpoint_item; breakpoint_item = breakpoint_item->get_next()) {
lines.push_back(breakpoint_item->get_meta("line"));
}
Expand Down
7 changes: 3 additions & 4 deletions editor/doc_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ Error DocTools::erase_classes(const String &p_dir) {
return err;
}

List<String> to_erase;
LocalVector<String> to_erase;

da->list_dir_begin();
String path;
Expand All @@ -1263,9 +1263,8 @@ Error DocTools::erase_classes(const String &p_dir) {
}
da->list_dir_end();

while (to_erase.size()) {
da->remove(to_erase.front()->get());
to_erase.pop_front();
for (String &E : to_erase) {
da->remove(E);
}

return OK;
Expand Down
10 changes: 5 additions & 5 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ void EditorFileSystem::ScanProgress::increment() {
}

int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref<DirAccess> &da) {
List<String> dirs;
LocalVector<String> dirs;
List<String> files;

String cd = da->get_current_dir();
Expand Down Expand Up @@ -1073,15 +1073,15 @@ int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref<DirAccess> &da)

int nb_files_total_scan = 0;

for (List<String>::Element *E = dirs.front(); E; E = E->next()) {
if (da->change_dir(E->get()) == OK) {
for (String &dir : dirs) {
if (da->change_dir(dir) == OK) {
String d = da->get_current_dir();

if (d == cd || !d.begins_with(cd)) {
da->change_dir(cd); //avoid recursion
} else {
ScannedDirectory *sd = memnew(ScannedDirectory);
sd->name = E->get();
sd->name = dir;
sd->full_path = p_dir->full_path.path_join(sd->name);

nb_files_total_scan += _scan_new_dir(sd, da);
Expand All @@ -1091,7 +1091,7 @@ int EditorFileSystem::_scan_new_dir(ScannedDirectory *p_dir, Ref<DirAccess> &da)
da->change_dir("..");
}
} else {
ERR_PRINT("Cannot go into subdir '" + E->get() + "'.");
ERR_PRINT("Cannot go into subdir '" + dir + "'.");
}
}

Expand Down
8 changes: 4 additions & 4 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ void EditorNode::_plugin_over_self_own(EditorPlugin *p_plugin) {
}

void EditorNode::_resources_changed(const Vector<String> &p_resources) {
List<Ref<Resource>> changed;
LocalVector<Ref<Resource>> changed;

int rc = p_resources.size();
for (int i = 0; i < rc; i++) {
Expand Down Expand Up @@ -2301,7 +2301,7 @@ void EditorNode::edit_item(Object *p_object, Object *p_editing_owner) {
// Remove editor plugins no longer used by this editing owner. Keep the ones that can
// still be reused by the new edited object.

List<EditorPlugin *> to_remove;
LocalVector<EditorPlugin *> to_remove;
for (EditorPlugin *plugin : active_plugins[owner_id]) {
if (!available_plugins.has(plugin)) {
to_remove.push_back(plugin);
Expand Down Expand Up @@ -2414,7 +2414,7 @@ void EditorNode::hide_unused_editors(const Object *p_editing_owner) {
} else {
// If no editing owner is provided, this method will go over all owners and check if they are valid.
// This is to sweep properties that were removed from the inspector.
List<ObjectID> to_remove;
LocalVector<ObjectID> to_remove;
for (KeyValue<ObjectID, HashSet<EditorPlugin *>> &kv : active_plugins) {
Object *context = ObjectDB::get_instance(kv.key);
if (context) {
Expand Down Expand Up @@ -6230,7 +6230,7 @@ void EditorNode::reload_instances_with_path_in_edited_scenes() {
}

// Store all the paths for any selected nodes which are ancestors of the node we're replacing.
List<NodePath> selected_node_paths;
LocalVector<NodePath> selected_node_paths;
for (Node *selected_node : editor_selection->get_selected_node_list()) {
if (selected_node == original_node || original_node->is_ancestor_of(selected_node)) {
selected_node_paths.push_back(original_node->get_path_to(selected_node));
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ void EditorSettings::list_text_editor_themes() {

Ref<DirAccess> d = DirAccess::open(EditorPaths::get_singleton()->get_text_editor_themes_dir());
if (d.is_valid()) {
List<String> custom_themes;
LocalVector<String> custom_themes;
d->list_dir_begin();
String file = d->get_next();
while (!file.is_empty()) {
Expand Down
2 changes: 1 addition & 1 deletion editor/gui/editor_file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ void EditorFileDialog::update_file_list() {
}
sort_file_info_list(file_infos, file_sort);

List<String> patterns;
LocalVector<String> patterns;
// build filter
if (filter->get_selected() == filter->get_item_count() - 1) {
// match all
Expand Down
4 changes: 2 additions & 2 deletions editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ void SceneTreeEditor::_edited() {
ERR_FAIL_NULL(edited);

if (is_scene_tree_dock && tree->get_next_selected(which)) {
List<Node *> nodes_to_rename;
LocalVector<Node *> nodes_to_rename;
for (TreeItem *item = which; item; item = tree->get_next_selected(item)) {
Node *n = get_node(item->get_metadata(0));
ERR_FAIL_NULL(n);
Expand All @@ -1186,7 +1186,7 @@ void SceneTreeEditor::_edited() {
ERR_FAIL_COND(nodes_to_rename.is_empty());

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
undo_redo->create_action(TTR("Rename Nodes"), UndoRedo::MERGE_DISABLE, nodes_to_rename.front()->get(), true);
undo_redo->create_action(TTR("Rename Nodes"), UndoRedo::MERGE_DISABLE, nodes_to_rename[0], true);

TreeItem *item = which;
String new_name = edited->get_text(0);
Expand Down
2 changes: 1 addition & 1 deletion editor/import/resource_importer_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ Error ResourceImporterTexture::import(ResourceUID::ID p_source_id, const String
bool convert_editor_colors = p_options.has("editor/convert_colors_with_editor_theme") && p_options["editor/convert_colors_with_editor_theme"];

// Start importing images.
List<Ref<Image>> images_imported;
LocalVector<Ref<Image>> images_imported;

// Load the normal image.
Ref<Image> normal_image;
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/animation_blend_tree_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArray<String
return;
}

List<StringName> to_erase;
LocalVector<StringName> to_erase;

if (p_nodes.is_empty()) {
for (int i = 0; i < graph->get_child_count(); i++) {
Expand Down
Loading