From: Marcin Siodelski Date: Tue, 13 Nov 2018 13:25:34 +0000 (+0100) Subject: [#57,!122] First attempt to improve performance of JSONFeed. X-Git-Tag: 268-reservation-mode-is-not-global_base~28^2~10 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a325aaa7fc2df13c3d059c29812c0c5405e2d154;p=thirdparty%2Fkea.git [#57,!122] First attempt to improve performance of JSONFeed. --- diff --git a/src/lib/cc/json_feed.cc b/src/lib/cc/json_feed.cc index 27b311124b..75d2a117ef 100644 --- a/src/lib/cc/json_feed.cc +++ b/src/lib/cc/json_feed.cc @@ -33,8 +33,7 @@ const int JSONFeed::FEED_OK_EVT; const int JSONFeed::FEED_FAILED_EVT; JSONFeed::JSONFeed() - : StateModel(), buffer_(), error_message_(), open_scopes_(0), - output_() { + : StateModel(), error_message_(), open_scopes_(0), output_() { } void @@ -100,8 +99,9 @@ JSONFeed::postBuffer(const void* buf, const size_t buf_size) { if (getNextEvent() == NEED_MORE_DATA_EVT) { transition(getCurrState(), MORE_DATA_PROVIDED_EVT); } - buffer_.insert(buffer_.end(), static_cast(buf), + buffer_.assign(static_cast(buf), static_cast(buf) + buf_size); + data_ptr_ = 0; } } @@ -163,9 +163,8 @@ JSONFeed::onModelFailure(const std::string& explanation) { bool JSONFeed::popNextFromBuffer(char& next) { // If there are any characters in the buffer, pop next. - if (!buffer_.empty()) { - next = buffer_.front(); - buffer_.pop_front(); + if (!buffer_.empty() && (data_ptr_ < buffer_.size())) { + next = buffer_[data_ptr_++]; return (true); } return (false); @@ -295,7 +294,7 @@ JSONFeed::innerJSONHandler() { transition(JSON_END_ST, FEED_OK_EVT); } else { - transition(getCurrState(), DATA_READ_OK_EVT); + postNextEvent(DATA_READ_OK_EVT); } break; @@ -304,7 +303,7 @@ JSONFeed::innerJSONHandler() { break; default: - transition(getCurrState(), DATA_READ_OK_EVT); + postNextEvent(DATA_READ_OK_EVT); } } } diff --git a/src/lib/cc/json_feed.h b/src/lib/cc/json_feed.h index ce3d026f18..42e5e28fbd 100644 --- a/src/lib/cc/json_feed.h +++ b/src/lib/cc/json_feed.h @@ -11,9 +11,9 @@ #include #include #include -#include #include #include +#include namespace isc { namespace config { @@ -278,7 +278,10 @@ private: //@} /// @brief Internal buffer from which the feed reads data. - std::list buffer_; + std::vector buffer_; + + /// @brief Holds pointer to the next byte in the buffer to be read. + size_t data_ptr_; /// @brief Error message set by @ref onModelFailure. std::string error_message_;