From 1053b35682b7ede790d0a9a76d9e2760dca4f4b7 Mon Sep 17 00:00:00 2001 From: Patrick Parker Date: Tue, 11 Sep 2007 02:12:37 +0000 Subject: [PATCH] tighten the loop in wildcard_string_match, eliminate a string copy operation --- src/serialization/string_utils.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/serialization/string_utils.cpp b/src/serialization/string_utils.cpp index 84a2fb532ae..d564e7e2949 100644 --- a/src/serialization/string_utils.cpp +++ b/src/serialization/string_utils.cpp @@ -758,24 +758,19 @@ bool wildcard_string_match(const std::string& str, const std::string& match) do { matches = true; //now try to place the str into the solid space - std::string test_str = str.substr(current); - for(std::string::size_type i=0; i < solid_len; ++i) { - if(i > test_str.length()) { - matches = false; - break; - } + const std::string::size_type test_len = str.length() - current; + for(std::string::size_type i=0; i < solid_len && matches; ++i) { char solid_c = match[solid_begin + i]; - if(solid_c != '?' && solid_c != test_str[i]) { + if(i > test_len || !(solid_c == '?' || solid_c == str[current+i])) { matches = false; - break; } } if(matches) { //the solid space matched, now consume it and attempt to find more - std::string consumed_match = (solid_begin+solid_len < match.length()) + const std::string consumed_match = (solid_begin+solid_len < match.length()) ? match.substr(solid_end) : ""; - std::string consumed_str = (solid_len < test_str.length()) - ? test_str.substr(solid_len) : ""; + const std::string consumed_str = (solid_len < test_len) + ? str.substr(current+solid_len) : ""; matches = wildcard_string_match(consumed_str, consumed_match); } } while(wild_matching && !matches && ++current < str.length());