diff --git a/CHANGELOG.md b/CHANGELOG.md index 20885534..0c7fbe2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 146: * Fix some typos +* Faster ascii_tolower -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/string.hpp b/include/boost/beast/core/string.hpp index f262b565..cd8411b6 100644 --- a/include/boost/beast/core/string.hpp +++ b/include/boost/beast/core/string.hpp @@ -55,9 +55,8 @@ inline char ascii_tolower(char c) { - if(c >= 'A' && c <= 'Z') - c += 'a' - 'A'; - return c; + return ((static_cast(c) - 65U) < 26) ? + c + 'a' - 'A' : c; } template @@ -77,17 +76,18 @@ iequals( a = *p1++; b = *p2++; if(a != b) - goto slow; - } - return true; - - while(n--) - { - slow: - if(ascii_tolower(a) != ascii_tolower(b)) - return false; - a = *p1++; - b = *p2++; + { + // slow loop + do + { + if(ascii_tolower(a) != ascii_tolower(b)) + return false; + a = *p1++; + b = *p2++; + } + while(n--); + return true; + } } return true; }