Repository: godotengine/godot
File: editor/scene/2d/particles_2d_editor_plugin.cpp (C++)

Code before:
void Particles2DEditorPlugin::_set_show_gizmos(Node *p_node, bool p_show) {
	GPUParticles2D *gpu_particles = Object::cast_to<GPUParticles2D>(p_node);
	if (gpu_particles) {
		gpu_particles->set_show_gizmos(p_show);
	}
	CPUParticles2D *cpu_particles = Object::cast_to<CPUParticles2D>(p_node);
	if (cpu_particles) {
		cpu_particles->set_show_gizmos(p_show);
	}

	// The `selection_changed` signal is deferred. A node could be deleted before the signal is emitted.
	if (p_show) {
		p_node->connect(SceneStringName(tree_exiting), callable_mp(this, &Particles2DEditorPlugin::_node_removed).bind(p_node));
	} else {
		p_node->disconnect(SceneStringName(tree_exiting), callable_mp(this, &Particles2DEditorPlugin::_node_removed));
	}
}

void Particles2DEditorPlugin::_selection_changed() {
	List<Node *> current_selection = EditorNode::get_singleton()->get_editor_selection()->get_top_selected_node_list();
	if (selected_particles.is_empty() && current_selection.is_empty()) {
		return;
	}

	// Turn gizmos on for nodes that are newly selected.
	HashSet<Node *> nodes_in_current_selection;
	for (Node *node : current_selection) {
		nodes_in_current_selection.insert(node);
		if (!selected_particles.has(node)) {
			_set_show_gizmos(node, true);
			selected_particles.insert(node);
		}
	}

	// Turn gizmos off for nodes that are no longer selected.
	LocalVector<Node *> to_erase;
	for (Node *node : selected_particles) {
		if (!nodes_in_current_selection.has(node)) {
			_set_show_gizmos(node, false);
			to_erase.push_back(node);
		}
	}

	for (Node *node : to_erase) {
		selected_particles.erase(node);
	}
}

void Particles2DEditorPlugin::_node_removed(Node *p_node) {
	if (selected_particles.has(p_node)) {
		_set_show_gizmos(p_node, false);

Review comment (suggestion):
```suggestion
	HashSet<const Node *> nodes_in_current_selection;
```

Code after:
void Particles2DEditorPlugin::_set_show_gizmos(Node *p_node, bool p_show) {
	GPUParticles2D *gpu_particles = Object::cast_to<GPUParticles2D>(p_node);
	if (gpu_particles) {
		gpu_particles->set_show_gizmos(p_show);
	}
	CPUParticles2D *cpu_particles = Object::cast_to<CPUParticles2D>(p_node);
	if (cpu_particles) {
		cpu_particles->set_show_gizmos(p_show);
	}

	// The `selection_changed` signal is deferred. A node could be deleted before the signal is emitted.
	if (p_show) {
		p_node->connect(SceneStringName(tree_exiting), callable_mp(this, &Particles2DEditorPlugin::_node_removed).bind(p_node));
	} else {
		p_node->disconnect(SceneStringName(tree_exiting), callable_mp(this, &Particles2DEditorPlugin::_node_removed));
	}
}

void Particles2DEditorPlugin::_selection_changed() {
	const List<Node *> &current_selection = EditorNode::get_singleton()->get_editor_selection()->get_top_selected_node_list();
	if (selected_particles.is_empty() && current_selection.is_empty()) {
		return;
	}

	// Turn gizmos on for nodes that are newly selected.
	HashSet<const Node *> nodes_in_current_selection;
	for (Node *node : current_selection) {
		nodes_in_current_selection.insert(node);
		if (!selected_particles.has(node)) {
			_set_show_gizmos(node, true);
			selected_particles.insert(node);
		}
	}

	// Turn gizmos off for nodes that are no longer selected.
	LocalVector<Node *> to_erase;
	for (Node *node : selected_particles) {
		if (!nodes_in_current_selection.has(node)) {
			_set_show_gizmos(node, false);
			to_erase.push_back(node);
		}
	}

	for (Node *node : to_erase) {
		selected_particles.erase(node);
	}
}

void Particles2DEditorPlugin::_node_removed(Node *p_node) {
	if (selected_particles.erase(p_node)) {
		_set_show_gizmos(p_node, false);