]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#57,!122] First attempt to improve performance of JSONFeed.
authorMarcin Siodelski <marcin@isc.org>
Tue, 13 Nov 2018 13:25:34 +0000 (14:25 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 15 Nov 2018 12:20:43 +0000 (07:20 -0500)
src/lib/cc/json_feed.cc
src/lib/cc/json_feed.h

index 27b311124b7c3a0d102c11f72c25b7a565e01961..75d2a117efd35d4bc6d35f1fe627355707979e8b 100644 (file)
@@ -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<const char*>(buf),
+        buffer_.assign(static_cast<const char*>(buf),
                        static_cast<const char*>(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);
         }
     }
 }
index ce3d026f18fbc9fef170279e3acc2911bfa3cadb..42e5e28fbdc9c2d62d5d75a10ba8ce88764f8a25 100644 (file)
@@ -11,9 +11,9 @@
 #include <exceptions/exceptions.h>
 #include <util/state_model.h>
 #include <boost/shared_ptr.hpp>
-#include <list>
 #include <stdint.h>
 #include <string>
+#include <vector>
 
 namespace isc {
 namespace config {
@@ -278,7 +278,10 @@ private:
     //@}
 
     /// @brief Internal buffer from which the feed reads data.
-    std::list<char> buffer_;
+    std::vector<char> 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_;