Commit ba2382d6 authored by Dominik Charousset's avatar Dominik Charousset

Avoid repeated map lookups

parent 41dc4ac4
...@@ -94,34 +94,30 @@ void incoming_stream_multiplexer::operator()(stream_msg::ack_batch&) { ...@@ -94,34 +94,30 @@ void incoming_stream_multiplexer::operator()(stream_msg::ack_batch&) {
void incoming_stream_multiplexer::operator()(stream_msg::close&) { void incoming_stream_multiplexer::operator()(stream_msg::close&) {
CAF_ASSERT(current_stream_msg_ != nullptr); CAF_ASSERT(current_stream_msg_ != nullptr);
CAF_ASSERT(current_stream_state_ != streams_.end()); CAF_ASSERT(current_stream_state_ != streams_.end());
auto i = streams_.find(current_stream_msg_->sid);
if (i != streams_.end()) {
forward_to_downstream(); forward_to_downstream();
streams_.erase(i); streams_.erase(current_stream_state_);
}
} }
void incoming_stream_multiplexer::operator()(stream_msg::abort& x) { void incoming_stream_multiplexer::operator()(stream_msg::abort& x) {
CAF_ASSERT(current_stream_msg_ != nullptr); CAF_ASSERT(current_stream_msg_ != nullptr);
CAF_ASSERT(current_stream_state_ != streams_.end()); CAF_ASSERT(current_stream_state_ != streams_.end());
auto i = streams_.find(current_stream_msg_->sid); if (current_stream_state_->second.prev_stage == self_->current_sender())
if (i != streams_.end()) { fail(x.reason, nullptr, current_stream_state_->second.next_stage);
if (i->second.prev_stage == self_->current_sender())
fail(x.reason, nullptr, i->second.next_stage);
else else
fail(x.reason, i->second.prev_stage); fail(x.reason, current_stream_state_->second.prev_stage);
streams_.erase(i); streams_.erase(current_stream_state_);
}
} }
void incoming_stream_multiplexer::operator()(stream_msg::downstream_failed&) { void incoming_stream_multiplexer::operator()(stream_msg::downstream_failed&) {
CAF_ASSERT(current_stream_msg_ != nullptr); CAF_ASSERT(current_stream_msg_ != nullptr);
CAF_ASSERT(current_stream_state_ != streams_.end()); CAF_ASSERT(current_stream_state_ != streams_.end());
// TODO: implement me
} }
void incoming_stream_multiplexer::operator()(stream_msg::upstream_failed&) { void incoming_stream_multiplexer::operator()(stream_msg::upstream_failed&) {
CAF_ASSERT(current_stream_msg_ != nullptr); CAF_ASSERT(current_stream_msg_ != nullptr);
CAF_ASSERT(current_stream_state_ != streams_.end()); CAF_ASSERT(current_stream_state_ != streams_.end());
// TODO: implement me
} }
void incoming_stream_multiplexer::forward_to_upstream() { void incoming_stream_multiplexer::forward_to_upstream() {
......
...@@ -97,31 +97,31 @@ void outgoing_stream_multiplexer::operator()(stream_msg::ack_batch&) { ...@@ -97,31 +97,31 @@ void outgoing_stream_multiplexer::operator()(stream_msg::ack_batch&) {
void outgoing_stream_multiplexer::operator()(stream_msg::close&) { void outgoing_stream_multiplexer::operator()(stream_msg::close&) {
CAF_ASSERT(current_stream_msg_ != nullptr); CAF_ASSERT(current_stream_msg_ != nullptr);
auto i = streams_.find(current_stream_msg_->sid); CAF_ASSERT(current_stream_state_ != streams_.end());
if (i != streams_.end()) {
forward_to_downstream(); forward_to_downstream();
streams_.erase(i); streams_.erase(current_stream_state_);
}
} }
void outgoing_stream_multiplexer::operator()(stream_msg::abort& x) { void outgoing_stream_multiplexer::operator()(stream_msg::abort& x) {
CAF_ASSERT(current_stream_msg_ != nullptr); CAF_ASSERT(current_stream_msg_ != nullptr);
auto i = streams_.find(current_stream_msg_->sid); CAF_ASSERT(current_stream_state_ != streams_.end());
if (i != streams_.end()) { if (current_stream_state_->second.prev_stage == self_->current_sender())
if (i->second.prev_stage == self_->current_sender()) fail(x.reason, nullptr, current_stream_state_->second.next_stage);
fail(x.reason, nullptr, i->second.next_stage);
else else
fail(x.reason, i->second.prev_stage); fail(x.reason, current_stream_state_->second.prev_stage);
streams_.erase(i); streams_.erase(current_stream_state_);
}
} }
void outgoing_stream_multiplexer::operator()(stream_msg::downstream_failed&) { void outgoing_stream_multiplexer::operator()(stream_msg::downstream_failed&) {
CAF_ASSERT(current_stream_msg_ != nullptr); CAF_ASSERT(current_stream_msg_ != nullptr);
CAF_ASSERT(current_stream_state_ != streams_.end());
// TODO: implement me
} }
void outgoing_stream_multiplexer::operator()(stream_msg::upstream_failed&) { void outgoing_stream_multiplexer::operator()(stream_msg::upstream_failed&) {
CAF_ASSERT(current_stream_msg_ != nullptr); CAF_ASSERT(current_stream_msg_ != nullptr);
CAF_ASSERT(current_stream_state_ != streams_.end());
// TODO: implement me
} }
void outgoing_stream_multiplexer::forward_to_upstream() { void outgoing_stream_multiplexer::forward_to_upstream() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment