Avoid const_cast in List::erase by requiring mutable elements
This commit is contained in:
parent
607b230ffe
commit
4a00d2c7b8
|
@ -224,7 +224,7 @@ private:
|
||||||
Element *last = nullptr;
|
Element *last = nullptr;
|
||||||
int size_cache = 0;
|
int size_cache = 0;
|
||||||
|
|
||||||
bool erase(const Element *p_I) {
|
bool erase(Element *p_I) {
|
||||||
ERR_FAIL_NULL_V(p_I, false);
|
ERR_FAIL_NULL_V(p_I, false);
|
||||||
ERR_FAIL_COND_V(p_I->data != this, false);
|
ERR_FAIL_COND_V(p_I->data != this, false);
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ private:
|
||||||
p_I->next_ptr->prev_ptr = p_I->prev_ptr;
|
p_I->next_ptr->prev_ptr = p_I->prev_ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
memdelete_allocator<Element, A>(const_cast<Element *>(p_I));
|
memdelete_allocator<Element, A>(p_I);
|
||||||
size_cache--;
|
size_cache--;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -430,7 +430,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* erase an element in the list, by iterator pointing to it. Return true if it was found/erased.
|
* erase an element in the list, by iterator pointing to it. Return true if it was found/erased.
|
||||||
*/
|
*/
|
||||||
bool erase(const Element *p_I) {
|
bool erase(Element *p_I) {
|
||||||
if (_data && p_I) {
|
if (_data && p_I) {
|
||||||
bool ret = _data->erase(p_I);
|
bool ret = _data->erase(p_I);
|
||||||
|
|
||||||
|
|
|
@ -1470,7 +1470,7 @@ void VisualShaderGraphPlugin::disconnect_nodes(VisualShader::Type p_type, int p_
|
||||||
if (visual_shader.is_valid() && visual_shader->get_shader_type() == p_type) {
|
if (visual_shader.is_valid() && visual_shader->get_shader_type() == p_type) {
|
||||||
graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
|
graph->disconnect_node(itos(p_from_node), p_from_port, itos(p_to_node), p_to_port);
|
||||||
|
|
||||||
for (const List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) {
|
for (List<VisualShader::Connection>::Element *E = connections.front(); E; E = E->next()) {
|
||||||
if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
|
if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
|
||||||
connections.erase(E);
|
connections.erase(E);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -313,7 +313,7 @@ bool GraphEdit::is_node_connected(const StringName &p_from, int p_from_port, con
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
|
void GraphEdit::disconnect_node(const StringName &p_from, int p_from_port, const StringName &p_to, int p_to_port) {
|
||||||
for (const List<Ref<Connection>>::Element *E = connections.front(); E; E = E->next()) {
|
for (List<Ref<Connection>>::Element *E = connections.front(); E; E = E->next()) {
|
||||||
if (E->get()->from_node == p_from && E->get()->from_port == p_from_port && E->get()->to_node == p_to && E->get()->to_port == p_to_port) {
|
if (E->get()->from_node == p_from && E->get()->from_port == p_from_port && E->get()->to_node == p_to && E->get()->to_port == p_to_port) {
|
||||||
connection_map[p_from].erase(E->get());
|
connection_map[p_from].erase(E->get());
|
||||||
connection_map[p_to].erase(E->get());
|
connection_map[p_to].erase(E->get());
|
||||||
|
|
|
@ -1330,7 +1330,7 @@ void VisualShader::disconnect_nodes(Type p_type, int p_from_node, int p_from_por
|
||||||
ERR_FAIL_INDEX(p_type, TYPE_MAX);
|
ERR_FAIL_INDEX(p_type, TYPE_MAX);
|
||||||
Graph *g = &graph[p_type];
|
Graph *g = &graph[p_type];
|
||||||
|
|
||||||
for (const List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
|
for (List<Connection>::Element *E = g->connections.front(); E; E = E->next()) {
|
||||||
if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
|
if (E->get().from_node == p_from_node && E->get().from_port == p_from_port && E->get().to_node == p_to_node && E->get().to_port == p_to_port) {
|
||||||
g->connections.erase(E);
|
g->connections.erase(E);
|
||||||
g->nodes[p_from_node].next_connected_nodes.erase(p_to_node);
|
g->nodes[p_from_node].next_connected_nodes.erase(p_to_node);
|
||||||
|
|
Loading…
Reference in New Issue