<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112970>112970</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
slow static analyzer performance with if-else chains
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:static analyzer,
performance
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
firewave
</td>
</tr>
</table>
<pre>
```cpp
#include <string>
std::string replaceEscapeSequences(const std::string &source)
{
std::string result;
for (std::size_t i = 0; i < source.size(); ++i) {
if (source[i] != '\\' || i + 1 >= source.size()) {
result += source[i];
}
else {
++i;
if (source[i] == 't') {
result += '\t';
} else if (source[i] == 'x')
{
std::string value = "0";
if (i + 1 < source.size() && std::isxdigit(source[i+1])) {
value += source[i++ + 1];
}
if (i + 1 < source.size() && std::isxdigit(source[i+1])) {
value += source[i++ + 1];
}
result += static_cast<char>(std::stoi(value, nullptr, 16));
}
}
}
return result;
}
```
```
$ time clang-tidy-20 -checks='-*,clang-analyzer-*' utils.cpp
1 warning generated.
Suppressed 1 warnings (1 with check filters).
real 0m4.272s
user 0m3.984s
sys 0m0.266s
```
This has been reduced from https://github.com/danmar/cppcheck/blob/main/lib/utils.cpp. The total time of the whole file is about 10 seconds and the code above accounts for about half of that.
Any further reduction cuts the analysis time by a third or in half.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vs2SozgMfhrlogoFIglw4NBJJi8wc58yRgTvOpi1Tfdknn7LOJO_yfRt10V1gy3r-z5JliOcU8eBuYb1Ftb7hZh8b2zdKcsf4p0XjWnPNWzS-MhxhHQP6RtQrgapp5YR8p3zVg1HyL9cFue_zreQv0H-FlfR8qiF5C9OipG_8j8TD5IdUCnN4Dw-mwNtnJmsZKDq4rbYxhdE_M3cspu0h_zOpDMWgcqbpfrJ3z0qhHyPKeTb-XWHESYJy0BlgMu3CLQF2iqgCh9ww1Dd7DeyW28VrPcIl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