From 3fa8829845bf55df812f81356a3ec43149836bb5 Mon Sep 17 00:00:00 2001 From: bakaoh Date: Fri, 10 Aug 2018 17:31:19 +0700 Subject: Fixes #4718: High CPU usage when using large variable names --- libdevcore/StringUtils.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libdevcore/StringUtils.cpp') diff --git a/libdevcore/StringUtils.cpp b/libdevcore/StringUtils.cpp index 01bdc675..50bf7cce 100644 --- a/libdevcore/StringUtils.cpp +++ b/libdevcore/StringUtils.cpp @@ -29,13 +29,16 @@ using namespace std; using namespace dev; -bool dev::stringWithinDistance(string const& _str1, string const& _str2, size_t _maxDistance) +bool dev::stringWithinDistance(string const& _str1, string const& _str2, size_t _maxDistance, size_t _lenThreshold) { if (_str1 == _str2) return true; size_t n1 = _str1.size(); size_t n2 = _str2.size(); + if (_lenThreshold > 0 && n1 * n2 > _lenThreshold) + return false; + size_t distance = stringDistance(_str1, _str2); // if distance is not greater than _maxDistance, and distance is strictly less than length of both names, they can be considered similar -- cgit v1.2.3