Skip to content

Commit 5f32dda

Browse files
Fixed the inefficient isTrue function
1 parent 6f54752 commit 5f32dda

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

cpr/util.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <curl/curl.h>
1212
#include <fstream>
1313
#include <ios>
14+
#include <iterator>
1415
#include <sstream>
1516
#include <string>
1617
#include <type_traits>
@@ -187,9 +188,10 @@ util::SecureString urlDecode(std::string_view s) {
187188
}
188189

189190
bool isTrue(const std::string& s) {
190-
std::string temp_string{s};
191-
std::transform(temp_string.begin(), temp_string.end(), temp_string.begin(), [](unsigned char c) { return static_cast<unsigned char>(std::tolower(c)); });
192-
return temp_string == "true";
191+
constexpr std::string_view tmp = "true";
192+
auto [s_it, tmp_it] = std::mismatch(s.begin(), s.end(), tmp.begin(), tmp.end(),
193+
[](auto s_c, auto t_c) { return std::tolower(s_c) == t_c; });
194+
return s_it == s.end() && tmp_it == tmp.end();
193195
}
194196

195197
time_t sTimestampToT(const std::string& st) {

0 commit comments

Comments
 (0)