From e6f55bdbcb1dd88caa1d0a383895b76c470d516b Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Tue, 27 Mar 2012 00:49:24 +0000 Subject: [PATCH] Use a binary search in IsWhitespace rather than linear Originally committed to SVN as r6613. --- aegisub/src/utils.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/aegisub/src/utils.cpp b/aegisub/src/utils.cpp index 1ae31b165..06a8a69c9 100644 --- a/aegisub/src/utils.cpp +++ b/aegisub/src/utils.cpp @@ -227,12 +227,7 @@ void GetWordBoundaries(const wxString text, IntPairVector &results, int start, i } } - - /// @brief Determine whether wchar 'c' is a whitespace character -/// @param c -/// @return -/// bool IsWhitespace(wchar_t c) { const wchar_t whitespaces[] = { @@ -243,20 +238,10 @@ bool IsWhitespace(wchar_t c) 0x025F, 0x3000, 0xFEFF }; const size_t num_chars = sizeof(whitespaces) / sizeof(whitespaces[0]); - - for (size_t i = 0; i < num_chars; ++i) - if (whitespaces[i] == c) - return true; - - return false; + return std::binary_search(whitespaces, whitespaces + num_chars, c); } - - /// @brief Returns true if str is empty of consists of only whitespace -/// @param str -/// @return -/// bool StringEmptyOrWhitespace(const wxString &str) { for (size_t i = 0; i < str.size(); ++i)