Skip to content

Commit 6974757

Browse files
author
don-dron
committed
cc core: vectorize CheckHeaderName like CheckHeaderValue
commit_hash:50b2c3567f3801bce8f54c441fa60618a62a00e4
1 parent 3734f53 commit 6974757

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

core/src/server/http/http_response.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,23 @@ void CheckHeaderName(std::string_view name) {
5050
};
5151
static constexpr auto bad_chars = init();
5252

53+
bool check_failed = false;
54+
55+
// this gets autovectorized, and we optimize for happy path here
5356
for (const char c : name) {
54-
auto code = static_cast<uint8_t>(c);
55-
if (bad_chars[code]) {
56-
throw std::runtime_error(
57-
fmt::format("invalid character in header name: '{}' (#{}), full header name: {}", c, code, name)
58-
);
57+
const auto code = static_cast<uint8_t>(c);
58+
check_failed |= bad_chars[code];
59+
}
60+
61+
if (check_failed) {
62+
// in a presumably rare scenarios of the check failing we do a second loop
63+
for (const char c : name) {
64+
const auto code = static_cast<uint8_t>(c);
65+
if (bad_chars[code]) {
66+
throw std::runtime_error(
67+
fmt::format("invalid character in header name: '{}' (#{}), full header name: {}", c, code, name)
68+
);
69+
}
5970
}
6071
}
6172
}

0 commit comments

Comments
 (0)