diff options
author | David Robillard <d@drobilla.net> | 2010-02-25 03:40:39 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-02-25 03:40:39 +0000 |
commit | e22984efe9b82ab006494aea93814a592cd44ece (patch) | |
tree | a9b1b317515b9fda4947d4fb9c2bc460e07b0c32 /src/client | |
parent | 5d87212114e2df68a086eeb55829a70bed0940d3 (diff) | |
download | ingen-e22984efe9b82ab006494aea93814a592cd44ece.tar.gz ingen-e22984efe9b82ab006494aea93814a592cd44ece.tar.bz2 ingen-e22984efe9b82ab006494aea93814a592cd44ece.zip |
Store patch connections in a map using a lexicographic <Port*,Port*> key for
fast (logarathmic) connection searching.
Replaces all O(num_connections) searches with O(lg(num_connections))
searches.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2491 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/ClientStore.cpp | 2 | ||||
-rw-r--r-- | src/client/PatchModel.cpp | 42 | ||||
-rw-r--r-- | src/client/PatchModel.hpp | 9 |
3 files changed, 26 insertions, 27 deletions
diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index 8a6e008b..2b7bb7f7 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -478,7 +478,7 @@ ClientStore::disconnect(const Path& src_port_path, const Path& dst_port_path) SharedPtr<PatchModel> patch = connection_patch(src_port_path, dst_port_path); if (patch) - patch->remove_connection(src_port_path, dst_port_path); + patch->remove_connection(src_port.get(), dst_port.get()); else LOG(error) << "Disconnection in non-existent patch: " << src_port_path << " -> " << dst_port_path << endl; diff --git a/src/client/PatchModel.cpp b/src/client/PatchModel.cpp index bf4168d6..94557bd0 100644 --- a/src/client/PatchModel.cpp +++ b/src/client/PatchModel.cpp @@ -59,7 +59,7 @@ PatchModel::remove_child(SharedPtr<ObjectModel> o) Connections::iterator next = j; ++next; - SharedPtr<ConnectionModel> cm = PtrCast<ConnectionModel>(*j); + SharedPtr<ConnectionModel> cm = PtrCast<ConnectionModel>(j->second); assert(cm); if (cm->src_port_path().parent() == o->path() @@ -68,7 +68,6 @@ PatchModel::remove_child(SharedPtr<ObjectModel> o) || cm->dst_port_path() == o->path()) { signal_removed_connection.emit(cm); _connections->erase(j); // cuts our reference - assert(!get_connection(cm->src_port_path(), cm->dst_port_path())); // no duplicates } j = next; } @@ -98,13 +97,13 @@ PatchModel::clear() SharedPtr<ConnectionModel> -PatchModel::get_connection(const Path& src_port_path, const Path& dst_port_path) const +PatchModel::get_connection(const Shared::Port* src_port, const Shared::Port* dst_port) { - for (Connections::const_iterator i = _connections->begin(); i != _connections->end(); ++i) - if ((*i)->src_port_path() == src_port_path && (*i)->dst_port_path() == dst_port_path) - return PtrCast<ConnectionModel>(*i); - - return SharedPtr<ConnectionModel>(); + Connections::iterator i = _connections->find(make_pair(src_port, dst_port)); + if (i != _connections->end()) + return PtrCast<ConnectionModel>(i->second); + else + return SharedPtr<ConnectionModel>(); } @@ -130,34 +129,31 @@ PatchModel::add_connection(SharedPtr<ConnectionModel> cm) assert(cm->dst_port()->parent().get() == this || cm->dst_port()->parent()->parent().get() == this); - SharedPtr<ConnectionModel> existing = get_connection(cm->src_port_path(), cm->dst_port_path()); + SharedPtr<ConnectionModel> existing = get_connection( + cm->src_port().get(), cm->dst_port().get()); if (existing) { assert(cm->src_port() == existing->src_port()); assert(cm->dst_port() == existing->dst_port()); } else { - _connections->push_back(new Connections::Node(cm)); + _connections->insert(make_pair(make_pair(cm->src_port().get(), cm->dst_port().get()), cm)); signal_new_connection.emit(cm); } } void -PatchModel::remove_connection(const Path& src_port_path, const Path& dst_port_path) +PatchModel::remove_connection(const Shared::Port* src_port, const Shared::Port* dst_port) { - for (Connections::iterator i = _connections->begin(); i != _connections->end(); ++i) { - SharedPtr<ConnectionModel> cm = PtrCast<ConnectionModel>(*i); - assert(cm); - if (cm->src_port_path() == src_port_path && cm->dst_port_path() == dst_port_path) { - signal_removed_connection.emit(cm); - delete _connections->erase(i); // cuts our reference - assert(!get_connection(src_port_path, dst_port_path)); // no duplicates - return; - } + Connections::iterator i = _connections->find(make_pair(src_port, dst_port)); + if (i != _connections->end()) { + SharedPtr<ConnectionModel> c = PtrCast<ConnectionModel>(i->second); + signal_removed_connection.emit(c); + _connections->erase(i); + } else { + warn << "[PatchModel::remove_connection] Failed to find connection " << + src_port->path() << " -> " << dst_port->path() << endl; } - - warn << "[PatchModel::remove_connection] Failed to find connection " << - src_port_path << " -> " << dst_port_path << endl; } diff --git a/src/client/PatchModel.hpp b/src/client/PatchModel.hpp index 1590aa10..e3baa3eb 100644 --- a/src/client/PatchModel.hpp +++ b/src/client/PatchModel.hpp @@ -27,6 +27,9 @@ #include "ConnectionModel.hpp" namespace Ingen { + +namespace Shared { class Port; } + namespace Client { class ClientStore; @@ -43,8 +46,8 @@ public: const Connections& connections() const { return *_connections.get(); } - SharedPtr<ConnectionModel> get_connection(const Raul::Path& src_port_path, - const Raul::Path& dst_port_path) const; + SharedPtr<ConnectionModel> get_connection(const Shared::Port* src_port, + const Shared::Port* dst_port); //uint32_t poly() const { return _poly; } bool enabled() const; @@ -85,7 +88,7 @@ private: bool remove_child(SharedPtr<ObjectModel> c); void add_connection(SharedPtr<ConnectionModel> cm); - void remove_connection(const Raul::Path& src_port_path, const Raul::Path& dst_port_path); + void remove_connection(const Shared::Port* src_port, const Shared::Port* dst_port); SharedPtr<Connections> _connections; bool _editable; |