llvm / llvm/llvm-project

[clang-tidy] New patterns for performance-inefficient-algorithm check

Open
#216,380 6 comments 0 reactions 1 assignee Claimed by @davidmenggx View on GitHub
clang-tidy enhancement
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

BEFORE:

```c++
auto search(std::set s, int i) {
return std::find_if(s.begin(), s.end(), [&](int val) {
return val > i;
});
}
```

AFTER:

```c++
auto search(std::set s, int i) {
return it->second.upper_bound(i);
}
```

Complexity drops from **O(n)** to **O(log n)**.
Also we can use `lower_bound` for `<=` in this check.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.