epee: speed up string matching a bit

This commit is contained in:
moneromooo-monero 2018-11-26 15:49:17 +00:00
parent 3a3858dc90
commit a13eb0a1a4
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3

View File

@ -91,11 +91,15 @@ namespace misc_utils
*/ */
inline void match_string2(std::string::const_iterator& star_end_string, std::string::const_iterator buf_end, std::string& val) inline void match_string2(std::string::const_iterator& star_end_string, std::string::const_iterator buf_end, std::string& val)
{ {
val.clear();
val.reserve(std::distance(star_end_string, buf_end));
bool escape_mode = false; bool escape_mode = false;
std::string::const_iterator it = star_end_string; std::string::const_iterator it = star_end_string;
++it; ++it;
std::string::const_iterator fi = it;
while (fi != buf_end && *fi != '\\' && *fi != '\"')
++fi;
val.assign(it, fi);
val.reserve(std::distance(star_end_string, buf_end));
it = fi;
for(;it != buf_end;it++) for(;it != buf_end;it++)
{ {
if(escape_mode/*prev_ch == '\\'*/) if(escape_mode/*prev_ch == '\\'*/)