diff options
author | bakaoh <tatattai@gmail.com> | 2018-08-10 18:31:19 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2018-08-15 16:23:08 +0800 |
commit | 3fa8829845bf55df812f81356a3ec43149836bb5 (patch) | |
tree | 16bb5707241fffa03f93513fffcaada49c083274 /libsolidity/analysis/DeclarationContainer.cpp | |
parent | f82893450d36d1e2d136b0cbd4449ff955410fb5 (diff) | |
download | dexon-solidity-3fa8829845bf55df812f81356a3ec43149836bb5.tar.gz dexon-solidity-3fa8829845bf55df812f81356a3ec43149836bb5.tar.zst dexon-solidity-3fa8829845bf55df812f81356a3ec43149836bb5.zip |
Fixes #4718: High CPU usage when using large variable names
Diffstat (limited to 'libsolidity/analysis/DeclarationContainer.cpp')
-rw-r--r-- | libsolidity/analysis/DeclarationContainer.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libsolidity/analysis/DeclarationContainer.cpp b/libsolidity/analysis/DeclarationContainer.cpp index 347daaf8..5f980788 100644 --- a/libsolidity/analysis/DeclarationContainer.cpp +++ b/libsolidity/analysis/DeclarationContainer.cpp @@ -138,19 +138,22 @@ vector<Declaration const*> DeclarationContainer::resolveName(ASTString const& _n vector<ASTString> DeclarationContainer::similarNames(ASTString const& _name) const { static size_t const MAXIMUM_EDIT_DISTANCE = 2; + // because the function below has quadratic runtime - it will not magically improve once a better algorithm is discovered ;) + // since 80 is the suggested line length limit, we use 80^2 as length threshold + static size_t const MAXIMUM_LENGTH_THRESHOLD = 80 * 80; vector<ASTString> similar; for (auto const& declaration: m_declarations) { string const& declarationName = declaration.first; - if (stringWithinDistance(_name, declarationName, MAXIMUM_EDIT_DISTANCE)) + if (stringWithinDistance(_name, declarationName, MAXIMUM_EDIT_DISTANCE, MAXIMUM_LENGTH_THRESHOLD)) similar.push_back(declarationName); } for (auto const& declaration: m_invisibleDeclarations) { string const& declarationName = declaration.first; - if (stringWithinDistance(_name, declarationName, MAXIMUM_EDIT_DISTANCE)) + if (stringWithinDistance(_name, declarationName, MAXIMUM_EDIT_DISTANCE, MAXIMUM_LENGTH_THRESHOLD)) similar.push_back(declarationName); } |