summaryrefslogtreecommitdiffstats
path: root/src/PortID.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-15 20:10:41 +0000
committerDavid Robillard <d@drobilla.net>2010-12-15 20:10:41 +0000
commitf4f74f3316b474096f164aa33c9d2e8965a545c3 (patch)
tree49ed4402f138d17592d7a33a35fde7232f799bff /src/PortID.hpp
parentaea13cac2a4106bbca28fc062d60e18ca4990c6c (diff)
downloadpatchage-f4f74f3316b474096f164aa33c9d2e8965a545c3.tar.gz
patchage-f4f74f3316b474096f164aa33c9d2e8965a545c3.tar.bz2
patchage-f4f74f3316b474096f164aa33c9d2e8965a545c3.zip
Improve performance for setups with many apps or ports.
(Eliminate all linear searches for items, except one case for Jack ports which is unavoidable due to the Jack API, but is memoized, so each port will only be searched for once between refreshes). git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@2712 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/PortID.hpp')
-rw-r--r--src/PortID.hpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/PortID.hpp b/src/PortID.hpp
index b3c2eb6..b1f8444 100644
--- a/src/PortID.hpp
+++ b/src/PortID.hpp
@@ -34,6 +34,9 @@
struct PortID {
PortID() : type(NULL_PORT_ID) { memset(&id, 0, sizeof(id)); }
+ PortID(const PortID& copy) : type(copy.type) {
+ memcpy(&id, &copy.id, sizeof(id));
+ }
enum { NULL_PORT_ID, JACK_ID, ALSA_ADDR } type;
@@ -73,7 +76,40 @@ operator<<(std::ostream& os, const PortID& id)
break;
case PortID::ALSA_ADDR:
#ifdef HAVE_ALSA
- return os << "alsa:" << (int)id.id.alsa_addr.client << ":" << (int)id.id.alsa_addr.port;
+ return os << "alsa:" << (int)id.id.alsa_addr.client << ":" << (int)id.id.alsa_addr.port
+ << ":" << (id.id.is_input ? "in" : "out");
+#endif
+ break;
+ }
+ assert(false);
+}
+
+static inline bool
+operator<(const PortID& a, const PortID& b)
+{
+ if (a.type != b.type)
+ return a.type < b.type;
+
+ switch (a.type) {
+ case PortID::NULL_PORT_ID:
+ return true;
+ case PortID::JACK_ID:
+#ifdef USE_LIBJACK
+ return a.id.jack_id < b.id.jack_id;
+#endif
+ break;
+ case PortID::ALSA_ADDR:
+#ifdef HAVE_ALSA
+ if ((a.id.alsa_addr.client < b.id.alsa_addr.client)
+ || ((a.id.alsa_addr.client == b.id.alsa_addr.client)
+ && a.id.alsa_addr.port < b.id.alsa_addr.port)) {
+ return true;
+ } else if (a.id.alsa_addr.client == b.id.alsa_addr.client
+ && a.id.alsa_addr.port == b.id.alsa_addr.port) {
+ return (a.id.is_input < b.id.is_input);
+ } else {
+ return false;
+ }
#endif
break;
}