From 76842d637f312cb2bafcb63204a0f8ba2f6c5889 Mon Sep 17 00:00:00 2001 From: Damian Jarek Date: Mon, 3 Jun 2019 01:09:06 +0200 Subject: [PATCH] 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 --- CHANGELOG.md | 6 ++++ include/boost/beast/http/impl/fields.hpp | 37 ++++++++++-------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29e47cbc..30b3a653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Version 259: + +* Reduce the number of instantiations of filter_token_list + +-------------------------------------------------------------------------------- + Version 258: * Fix separate compilation in CI diff --git a/include/boost/beast/http/impl/fields.hpp b/include/boost/beast/http/impl/fields.hpp index 9616af82..268f523d 100644 --- a/include/boost/beast/http/impl/fields.hpp +++ b/include/boost/beast/http/impl/fields.hpp @@ -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");