From db6db517424e09bab9a12934e9df6807a7049926 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 7 Aug 2014 15:05:27 +0200 Subject: util/CharUtil: add IsWhitespaceFast() --- src/util/CharUtil.hxx | 13 +++++++++++++ src/util/Tokenizer.cxx | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src/util') diff --git a/src/util/CharUtil.hxx b/src/util/CharUtil.hxx index 3c1959b22..9cb852524 100644 --- a/src/util/CharUtil.hxx +++ b/src/util/CharUtil.hxx @@ -58,6 +58,19 @@ IsWhitespaceNotNull(const char ch) return ch > 0 && ch <= 0x20; } +/** + * Is the given character whitespace? This calls the faster one of + * IsWhitespaceOrNull() or IsWhitespaceNotNull(). Use this if you + * want the fastest implementation, and you don't care if a null byte + * matches. + */ +constexpr +static inline bool +IsWhitespaceFast(const char ch) +{ + return IsWhitespaceOrNull(ch); +} + constexpr static inline bool IsPrintableASCII(char ch) diff --git a/src/util/Tokenizer.cxx b/src/util/Tokenizer.cxx index d839b6ce6..306a90074 100644 --- a/src/util/Tokenizer.cxx +++ b/src/util/Tokenizer.cxx @@ -67,7 +67,7 @@ Tokenizer::NextWord(Error &error) whitespace or end-of-string */ while (*++input != 0) { - if (IsWhitespaceOrNull(*input)) { + if (IsWhitespaceFast(*input)) { /* a whitespace: the word ends here */ *input = 0; /* skip all following spaces, too */ @@ -112,7 +112,7 @@ Tokenizer::NextUnquoted(Error &error) whitespace or end-of-string */ while (*++input != 0) { - if (IsWhitespaceOrNull(*input)) { + if (IsWhitespaceFast(*input)) { /* a whitespace: the word ends here */ *input = 0; /* skip all following spaces, too */ @@ -176,7 +176,7 @@ Tokenizer::NextString(Error &error) line) */ ++input; - if (!IsWhitespaceOrNull(*input)) { + if (!IsWhitespaceFast(*input)) { error.Set(tokenizer_domain, "Space expected after closing '\"'"); return nullptr; -- cgit v1.2.3