summaryrefslogtreecommitdiff
path: root/src/mtrie.cpp
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2011-06-11 20:29:56 +0200
committerMartin Sustrik <sustrik@250bpm.com>2011-06-11 20:29:56 +0200
commitbd86def1c799a35d5cef0c0a9a1347a18fea227e (patch)
tree4d70d0053ef86b5a614bd19ad4c5f420017279c7 /src/mtrie.cpp
parent3935258b826adc31815be4f91b2f6eb02bb3c8ed (diff)
Actual message filtering happens in XPUB socket
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src/mtrie.cpp')
-rw-r--r--src/mtrie.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/mtrie.cpp b/src/mtrie.cpp
index 91f6852..fafac2d 100644
--- a/src/mtrie.cpp
+++ b/src/mtrie.cpp
@@ -206,10 +206,21 @@ bool zmq::mtrie_t::rm_helper (unsigned char *prefix_, size_t size_,
return next_node->rm_helper (prefix_ + 1, size_ - 1, pipe_);
}
-void zmq::mtrie_t::match (unsigned char *data_, size_t size_, pipes_t &pipes_)
+void zmq::mtrie_t::match (unsigned char *data_, size_t size_,
+ void (*func_) (pipe_t *pipe_, void *arg_), void *arg_)
{
- // Merge the subscriptions from this node to the resultset.
- pipes_.insert (pipes.begin (), pipes.end ());
+ match_helper (data_, size_, func_, arg_);
+}
+
+void zmq::mtrie_t::match_helper (unsigned char *data_, size_t size_,
+ void (*func_) (pipe_t *pipe_, void *arg_), void *arg_)
+{
+ // TODO: This function is on critical path. Rewrite it as iteration
+ // rather than recursion.
+
+ // Signal the pipes attached to this node.
+ for (pipes_t::iterator it = pipes.begin (); it != pipes.end (); ++it)
+ func_ (*it, arg_);
// If there are no subnodes in the trie, return.
if (count == 0)
@@ -217,14 +228,14 @@ void zmq::mtrie_t::match (unsigned char *data_, size_t size_, pipes_t &pipes_)
// If there's one subnode (optimisation).
if (count == 1) {
- next.node->match (data_ + 1, size_ - 1, pipes_);
+ next.node->match (data_ + 1, size_ - 1, func_, arg_);
return;
}
// If there are multiple subnodes.
for (unsigned char c = 0; c != count; c++) {
if (next.table [c])
- next.table [c]->match (data_ + 1, size_ - 1, pipes_);
+ next.table [c]->match (data_ + 1, size_ - 1, func_, arg_);
}
}