diff options
| author | Dan Engelbrecht <[email protected]> | 2026-02-27 16:39:04 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-02-27 16:39:04 +0100 |
| commit | 87aff23c1246abd2838d8b0e589fe61015effa9c (patch) | |
| tree | 4ee3bd840d76278d51b82d19f7017c5a4867c5c0 /src/zenhttp/clients/httpclientcommon.h | |
| parent | MeasureLatency now bails out quickly if it experiences a connection error (#789) (diff) | |
| download | zen-87aff23c1246abd2838d8b0e589fe61015effa9c.tar.xz zen-87aff23c1246abd2838d8b0e589fe61015effa9c.zip | |
optimize string matching (#791)
Diffstat (limited to 'src/zenhttp/clients/httpclientcommon.h')
| -rw-r--r-- | src/zenhttp/clients/httpclientcommon.h | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/zenhttp/clients/httpclientcommon.h b/src/zenhttp/clients/httpclientcommon.h index 8bb1e9268..5ed946541 100644 --- a/src/zenhttp/clients/httpclientcommon.h +++ b/src/zenhttp/clients/httpclientcommon.h @@ -158,11 +158,18 @@ namespace detail { IncrementalStringMatcher() {} - IncrementalStringMatcher(std::string&& InMatchString) : MatchString(std::move(InMatchString)) {} + IncrementalStringMatcher(std::string&& InMatchString) : MatchString(std::move(InMatchString)) + { + RawMatchString = MatchString.data(); + } - void Init(std::string&& InMatchString) { MatchString = std::move(InMatchString); } + void Init(std::string&& InMatchString) + { + MatchString = std::move(InMatchString); + RawMatchString = MatchString.data(); + } - void Reset() + inline void Reset() { MatchLength = 0; MatchStartOffset = 0; @@ -186,13 +193,13 @@ namespace detail { void Match(uint64_t Offset, char C) { - ZEN_ASSERT_SLOW(!MatchString.empty()); + ZEN_ASSERT_SLOW(RawMatchString != nullptr); if (MatchState == EMatchState::Complete) { Reset(); } - if (C == MatchString[MatchLength]) + if (C == RawMatchString[MatchLength]) { if (MatchLength == 0) { @@ -222,8 +229,9 @@ namespace detail { private: std::string MatchString; + const char* RawMatchString = nullptr; + uint64_t MatchLength = 0; - uint64_t MatchLength = 0; uint64_t MatchStartOffset = 0; }; @@ -233,8 +241,8 @@ namespace detail { std::vector<HttpClient::Response::MultipartBoundary> Boundaries; MultipartBoundaryParser(); - bool Init(const std::string_view ContentTypeHeaderValue); - inline void ParseInput(std::string_view data) { InternalParseInput(data); } + bool Init(const std::string_view ContentTypeHeaderValue); + void ParseInput(std::string_view data); private: IncrementalStringMatcher BoundaryBeginMatcher; @@ -243,8 +251,6 @@ namespace detail { ExtendableStringBuilder<64> BoundaryHeader; uint64_t PayloadOffset = 0; - - void InternalParseInput(std::string_view data); }; std::pair<std::string_view, std::string_view> GetHeaderKeyAndValue(std::string_view HeaderString); |