Skip to content

Commit 416ba9a

Browse files
committed
Merge pull request #109517 from precup/speedy-signal-disconnect
Speed up signal disconnects in the editor
2 parents eaa80e6 + abfc63b commit 416ba9a

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

core/object/object.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,18 @@ int Object::get_persistent_signal_connection_count() const {
15221522
return count;
15231523
}
15241524

1525+
uint32_t Object::get_signal_connection_flags(const StringName &p_name, const Callable &p_callable) const {
1526+
OBJ_SIGNAL_LOCK
1527+
const SignalData *signal_data = signal_map.getptr(p_name);
1528+
if (signal_data) {
1529+
const SignalData::Slot *slot = signal_data->slot_map.getptr(p_callable);
1530+
if (slot) {
1531+
return slot->conn.flags;
1532+
}
1533+
}
1534+
return 0;
1535+
}
1536+
15251537
void Object::get_signals_connected_to_this(List<Connection> *p_connections) const {
15261538
OBJ_SIGNAL_LOCK
15271539

core/object/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ class Object {
973973
DEBUG_VIRTUAL void get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const;
974974
DEBUG_VIRTUAL void get_all_signal_connections(List<Connection> *p_connections) const;
975975
DEBUG_VIRTUAL int get_persistent_signal_connection_count() const;
976+
DEBUG_VIRTUAL uint32_t get_signal_connection_flags(const StringName &p_name, const Callable &p_callable) const;
976977
DEBUG_VIRTUAL void get_signals_connected_to_this(List<Connection> *p_connections) const;
977978

978979
DEBUG_VIRTUAL Error connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags = 0);

scene/main/node.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4191,6 +4191,11 @@ int Node::get_persistent_signal_connection_count() const {
41914191
return Object::get_persistent_signal_connection_count();
41924192
}
41934193

4194+
uint32_t Node::get_signal_connection_flags(const StringName &p_signal, const Callable &p_callable) const {
4195+
ERR_THREAD_GUARD_V(0);
4196+
return Object::get_signal_connection_flags(p_signal, p_callable);
4197+
}
4198+
41944199
void Node::get_signals_connected_to_this(List<Connection> *p_connections) const {
41954200
ERR_THREAD_GUARD;
41964201
Object::get_signals_connected_to_this(p_connections);
@@ -4214,14 +4219,13 @@ void Node::disconnect(const StringName &p_signal, const Callable &p_callable) {
42144219

42154220
#ifdef TOOLS_ENABLED
42164221
// Already under thread guard, don't check again.
4217-
int old_connection_count = Object::get_persistent_signal_connection_count();
4222+
uint32_t connection_flags = Object::get_signal_connection_flags(p_signal, p_callable);
42184223
#endif
42194224

4220-
Object::disconnect(p_signal, p_callable);
4225+
[[maybe_unused]] bool changed = Object::_disconnect(p_signal, p_callable);
42214226

42224227
#ifdef TOOLS_ENABLED
4223-
int new_connection_count = Object::get_persistent_signal_connection_count();
4224-
if (old_connection_count != new_connection_count) {
4228+
if (changed && connection_flags & CONNECT_PERSIST) {
42254229
_emit_editor_state_changed();
42264230
}
42274231
#endif

scene/main/node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ class Node : public Object {
875875
virtual void get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const override;
876876
virtual void get_all_signal_connections(List<Connection> *p_connections) const override;
877877
virtual int get_persistent_signal_connection_count() const override;
878+
virtual uint32_t get_signal_connection_flags(const StringName &p_name, const Callable &p_callable) const override;
878879
virtual void get_signals_connected_to_this(List<Connection> *p_connections) const override;
879880

880881
virtual Error connect(const StringName &p_signal, const Callable &p_callable, uint32_t p_flags = 0) override;

0 commit comments

Comments
 (0)