aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore/StringUtils.cpp
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-08-15 16:49:39 +0800
committerGitHub <noreply@github.com>2018-08-15 16:49:39 +0800
commitb9752b236b474e384a297fe832cf0efb161e8deb (patch)
tree5c5d61fae37024a3ba2fea5bd7eaf0d455e6e043 /libdevcore/StringUtils.cpp
parent3c5226cefb9f883277530decedc08e2e48ed3050 (diff)
parent3fa8829845bf55df812f81356a3ec43149836bb5 (diff)
downloaddexon-solidity-b9752b236b474e384a297fe832cf0efb161e8deb.tar.gz
dexon-solidity-b9752b236b474e384a297fe832cf0efb161e8deb.tar.zst
dexon-solidity-b9752b236b474e384a297fe832cf0efb161e8deb.zip
Merge pull request #4797 from bakaoh/issue4718
Fixes #4718: High CPU usage when using large variable names
Diffstat (limited to 'libdevcore/StringUtils.cpp')
-rw-r--r--libdevcore/StringUtils.cpp5
1 files changed, 4 insertions, 1 deletions
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