diff options
author | Max Kellermann <max@duempel.org> | 2014-08-07 15:05:27 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-08-07 16:08:02 +0200 |
commit | db6db517424e09bab9a12934e9df6807a7049926 (patch) | |
tree | 6525302356ec79acb6bebd179a13b760b8dcb279 /src | |
parent | 981be7956b86c4bcf449ff87082f422721a6e8c3 (diff) | |
download | mpd-db6db517424e09bab9a12934e9df6807a7049926.tar.gz mpd-db6db517424e09bab9a12934e9df6807a7049926.tar.xz mpd-db6db517424e09bab9a12934e9df6807a7049926.zip |
util/CharUtil: add IsWhitespaceFast()
Diffstat (limited to '')
-rw-r--r-- | src/LogBackend.cxx | 2 | ||||
-rw-r--r-- | src/client/ClientRead.cxx | 2 | ||||
-rw-r--r-- | src/input/TextInputStream.cxx | 2 | ||||
-rw-r--r-- | src/util/CharUtil.hxx | 13 | ||||
-rw-r--r-- | src/util/Tokenizer.cxx | 6 |
5 files changed, 19 insertions, 6 deletions
diff --git a/src/LogBackend.cxx b/src/LogBackend.cxx index 3cd907179..6f1794521 100644 --- a/src/LogBackend.cxx +++ b/src/LogBackend.cxx @@ -120,7 +120,7 @@ chomp_length(const char *p) { size_t length = strlen(p); - while (length > 0 && IsWhitespaceOrNull(p[length - 1])) + while (length > 0 && IsWhitespaceFast(p[length - 1])) --length; return (int)length; diff --git a/src/client/ClientRead.cxx b/src/client/ClientRead.cxx index 1ec6d29d5..ae8eda8bb 100644 --- a/src/client/ClientRead.cxx +++ b/src/client/ClientRead.cxx @@ -39,7 +39,7 @@ Client::OnSocketInput(void *data, size_t length) BufferedSocket::ConsumeInput(newline + 1 - p); /* skip whitespace at the end of the line */ - while (newline > p && IsWhitespaceOrNull(newline[-1])) + while (newline > p && IsWhitespaceFast(newline[-1])) --newline; /* terminate the string at the end of the line */ diff --git a/src/input/TextInputStream.cxx b/src/input/TextInputStream.cxx index b90eeacc0..36aa5f408 100644 --- a/src/input/TextInputStream.cxx +++ b/src/input/TextInputStream.cxx @@ -72,7 +72,7 @@ TextInputStream::ReadLine() buffer.Consume(p - src + 1); - while (p > src && IsWhitespaceOrNull(p[-1])) + while (p > src && IsWhitespaceFast(p[-1])) --p; *p = 0; return src; 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; |