diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-14 23:54:00 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-06-19 15:47:02 +0200 |
commit | 2cb4ec5e00c18f5087b898c6232f63e8926d40cd (patch) | |
tree | 2022d4ad74b4d9095400d28a7c26df53255fa7e0 /messagebus | |
parent | 3da1452bbec099d76705e9b3b2f7a6cfe83903bb (diff) |
pre-size by reserve and inline small methods.
Diffstat (limited to 'messagebus')
-rw-r--r-- | messagebus/src/vespa/messagebus/callstack.cpp | 17 | ||||
-rw-r--r-- | messagebus/src/vespa/messagebus/callstack.h | 13 | ||||
-rw-r--r-- | messagebus/src/vespa/messagebus/message.cpp | 6 |
3 files changed, 13 insertions, 23 deletions
diff --git a/messagebus/src/vespa/messagebus/callstack.cpp b/messagebus/src/vespa/messagebus/callstack.cpp index 6faa9c5adc2..0ab8658d53f 100644 --- a/messagebus/src/vespa/messagebus/callstack.cpp +++ b/messagebus/src/vespa/messagebus/callstack.cpp @@ -20,24 +20,7 @@ CallStack::discard() } } -CallStack::CallStack() : _stack() { } CallStack::~CallStack() { } -void -CallStack::swap(CallStack &dst) -{ - _stack.swap(dst._stack); -} - -void -CallStack::push(IReplyHandler &replyHandler, Context ctx, - IDiscardHandler *discardHandler) -{ - Frame frame; - frame.replyHandler = &replyHandler; - frame.discardHandler = discardHandler; - frame.ctx = ctx; - _stack.push_back(frame); -} IReplyHandler & CallStack::pop(Reply &reply) diff --git a/messagebus/src/vespa/messagebus/callstack.h b/messagebus/src/vespa/messagebus/callstack.h index 43019738524..68da598e796 100644 --- a/messagebus/src/vespa/messagebus/callstack.h +++ b/messagebus/src/vespa/messagebus/callstack.h @@ -24,6 +24,7 @@ class CallStack { private: struct Frame { + Frame(IReplyHandler *r, IDiscardHandler * d, Context c) : replyHandler(r), discardHandler(d), ctx(c) {} IReplyHandler *replyHandler; IDiscardHandler *discardHandler; Context ctx; @@ -39,7 +40,7 @@ public: /** * Create a new empty CallStack. **/ - CallStack(); + CallStack() { } ~CallStack(); /** @@ -47,7 +48,7 @@ public: * * @param dst The stack to swap content with. **/ - void swap(CallStack &dst); + void swap(CallStack &dst) { _stack.swap(dst._stack); } /** * Discard this CallStack. This method should only be used when you are @@ -71,8 +72,9 @@ public: * @param ctx The context to store. * @param discardHandler The handler for discarded messages. **/ - void push(IReplyHandler &replyHandler, Context ctx, - IDiscardHandler *discardHandler = NULL); + void push(IReplyHandler &replyHandler, Context ctx, IDiscardHandler *discardHandler = NULL) { + _stack.emplace_back(&replyHandler, discardHandler, ctx); + } /** * Pop a frame from this stack. The handler part of the frame will @@ -84,6 +86,9 @@ public: * @param reply Reply that will receive the next context **/ IReplyHandler &pop(Reply &reply); + + /** Reserve space to avoid reallocation. */ + void reserve(size_t sz) { _stack.reserve(sz); } }; } // namespace mbus diff --git a/messagebus/src/vespa/messagebus/message.cpp b/messagebus/src/vespa/messagebus/message.cpp index cad9dc1bc40..c6d1bcce36f 100644 --- a/messagebus/src/vespa/messagebus/message.cpp +++ b/messagebus/src/vespa/messagebus/message.cpp @@ -4,7 +4,6 @@ #include "reply.h" #include "ireplyhandler.h" #include "emptyreply.h" -#include "error.h" #include "errorcode.h" #include <vespa/vespalib/util/backtrace.h> @@ -19,7 +18,10 @@ Message::Message() : _timeRemaining(0), _retryEnabled(true), _retry(0) -{ } +{ + // By observation there are normally 2 handlers pushed. + getCallStack().reserve(2); +} Message::~Message() { |