diff --git a/source/common/http/codec_helper.h b/source/common/http/codec_helper.h index 3cc6d5bd6580d..5128891e41055 100644 --- a/source/common/http/codec_helper.h +++ b/source/common/http/codec_helper.h @@ -1,11 +1,11 @@ #pragma once -#include - #include "envoy/http/codec.h" #include "common/common/assert.h" +#include "absl/container/inlined_vector.h" + namespace Envoy { namespace Http { @@ -54,12 +54,7 @@ class StreamCallbackHelper { bool local_end_stream_{}; protected: - StreamCallbackHelper() { - // Set space for 8 callbacks (64 bytes). - callbacks_.reserve(8); - } - - void addCallbacks_(StreamCallbacks& callbacks) { + void addCallbacksHelper(StreamCallbacks& callbacks) { ASSERT(!reset_callbacks_started_ && !local_end_stream_); callbacks_.push_back(&callbacks); for (uint32_t i = 0; i < high_watermark_callbacks_; ++i) { @@ -67,12 +62,12 @@ class StreamCallbackHelper { } } - void removeCallbacks_(StreamCallbacks& callbacks) { + void removeCallbacksHelper(StreamCallbacks& callbacks) { // For performance reasons we just clear the callback and do not resize the vector. // Reset callbacks scale with the number of filters per request and do not get added and // removed multiple times. // The vector may not be safely resized without making sure the run.*Callbacks() helper - // functions above still handle removeCallbacks_() calls mid-loop. + // functions above still handle removeCallbacksHelper() calls mid-loop. for (auto& callback : callbacks_) { if (callback == &callbacks) { callback = nullptr; @@ -82,7 +77,7 @@ class StreamCallbackHelper { } private: - std::vector callbacks_; + absl::InlinedVector callbacks_; bool reset_callbacks_started_{}; uint32_t high_watermark_callbacks_{}; }; diff --git a/source/common/http/conn_manager_impl.cc b/source/common/http/conn_manager_impl.cc index b4dddcb478ff1..b8709f79b9fa5 100644 --- a/source/common/http/conn_manager_impl.cc +++ b/source/common/http/conn_manager_impl.cc @@ -272,7 +272,7 @@ RequestDecoder& ConnectionManagerImpl::newStream(ResponseEncoder& response_encod new_stream->response_encoder_->getStream().addCallbacks(*new_stream); new_stream->buffer_limit_ = new_stream->response_encoder_->getStream().bufferLimit(); // If the network connection is backed up, the stream should be made aware of it on creation. - // Both HTTP/1.x and HTTP/2 codecs handle this in StreamCallbackHelper::addCallbacks_. + // Both HTTP/1.x and HTTP/2 codecs handle this in StreamCallbackHelper::addCallbacksHelper. ASSERT(read_callbacks_->connection().aboveHighWatermark() == false || new_stream->high_watermark_count_ > 0); new_stream->moveIntoList(std::move(new_stream), streams_); diff --git a/source/common/http/http1/codec_impl.h b/source/common/http/http1/codec_impl.h index 12901e447e9a6..f41824755b571 100644 --- a/source/common/http/http1/codec_impl.h +++ b/source/common/http/http1/codec_impl.h @@ -61,8 +61,8 @@ class StreamEncoderImpl : public virtual StreamEncoder, void disableChunkEncoding() override { disable_chunk_encoding_ = true; } // Http::Stream - void addCallbacks(StreamCallbacks& callbacks) override { addCallbacks_(callbacks); } - void removeCallbacks(StreamCallbacks& callbacks) override { removeCallbacks_(callbacks); } + void addCallbacks(StreamCallbacks& callbacks) override { addCallbacksHelper(callbacks); } + void removeCallbacks(StreamCallbacks& callbacks) override { removeCallbacksHelper(callbacks); } // After this is called, for the HTTP/1 codec, the connection should be closed, i.e. no further // progress may be made with the codec. void resetStream(StreamResetReason reason) override; diff --git a/source/common/http/http2/codec_impl.h b/source/common/http/http2/codec_impl.h index ed579f6ff7fff..23c670debca7f 100644 --- a/source/common/http/http2/codec_impl.h +++ b/source/common/http/http2/codec_impl.h @@ -208,8 +208,8 @@ class ConnectionImpl : public virtual Connection, protected Logger::LoggablelocalAddress();