Reduce the number of instantiations of filter_token_list

Not using lambdas in this case reduced the number of instantiations of
the algorithm by a factor of 4x at no (observable) runtime cost.

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
Damian Jarek
2019-06-03 01:09:06 +02:00
parent 6af4c01e56
commit 76842d637f
2 changed files with 21 additions and 22 deletions

View File

@@ -1,3 +1,9 @@
Version 259:
* Reduce the number of instantiations of filter_token_list
--------------------------------------------------------------------------------
Version 258:
* Fix separate compilation in CI

View File

@@ -824,16 +824,23 @@ keep_alive_impl(
String& s, string_view value,
unsigned version, bool keep_alive)
{
struct iequals_predicate
{
bool operator()(string_view s)
{
return beast::iequals(s, sv1) || beast::iequals(s, sv2);
}
string_view sv1;
string_view sv2;
};
if(version < 11)
{
if(keep_alive)
{
// remove close
filter_token_list(s, value,
[](string_view s)
{
return iequals(s, "close");
});
filter_token_list(s, value, iequals_predicate{"close"});
// add keep-alive
if(s.empty())
s.append("keep-alive");
@@ -844,12 +851,7 @@ keep_alive_impl(
{
// remove close and keep-alive
filter_token_list(s, value,
[](string_view s)
{
return
iequals(s, "close") ||
iequals(s, "keep-alive");
});
iequals_predicate{"close", "keep-alive"});
}
}
else
@@ -858,21 +860,12 @@ keep_alive_impl(
{
// remove close and keep-alive
filter_token_list(s, value,
[](string_view s)
{
return
iequals(s, "close") ||
iequals(s, "keep-alive");
});
iequals_predicate{"close", "keep-alive"});
}
else
{
// remove keep-alive
filter_token_list(s, value,
[](string_view s)
{
return iequals(s, "keep-alive");
});
filter_token_list(s, value, iequals_predicate{"keep-alive"});
// add close
if(s.empty())
s.append("close");