Skip to content

Commit

Permalink
Apply modernize-use-starts-ends-with on llvm-project (#89140)
Browse files Browse the repository at this point in the history
Run `modernize-use-starts-ends-with` on llvm-project. Two instances are
flagged, minor readability improvements, extremely minor performance
improvements.

```
python3 clang-tools-extra/clang-tidy/tool/run-clang-tidy.py \
    -clang-tidy-binary="build/bin/clang-tidy" \
    -clang-apply-replacements-binary="build/bin/clang-apply-replacements" \
    -checks="-*,modernize-use-starts-ends-with" \
    -header-filter=".*" \
    -fix -format
```

I am working on some additions to this check, but they don't seem to
flag any additional cases anyway.
  • Loading branch information
nicovank committed Apr 19, 2024
1 parent d634b23 commit 5232cec
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions clang-tools-extra/clang-doc/Representation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,8 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
this->SourceRoot = std::string(SourceRootDir);
if (!RepositoryUrl.empty()) {
this->RepositoryUrl = std::string(RepositoryUrl);
if (!RepositoryUrl.empty() && RepositoryUrl.find("http://") != 0 &&
RepositoryUrl.find("https://") != 0)
if (!RepositoryUrl.empty() && !RepositoryUrl.starts_with("http://") &&
!RepositoryUrl.starts_with("https://"))
this->RepositoryUrl->insert(0, "https://");
}
}
Expand Down
2 changes: 1 addition & 1 deletion lldb/unittests/Host/FileSystemTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DummyFileSystem : public vfs::FileSystem {
std::map<std::string, vfs::Status>::iterator I;
std::string Path;
bool isInPath(StringRef S) {
if (Path.size() < S.size() && S.find(Path) == 0) {
if (Path.size() < S.size() && S.starts_with(Path)) {
auto LastSep = S.find_last_of('/');
if (LastSep == Path.size() || LastSep == Path.size() - 1)
return true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/Support/VirtualFileSystemTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class DummyFileSystem : public vfs::FileSystem {
std::map<std::string, vfs::Status>::iterator I;
std::string Path;
bool isInPath(StringRef S) {
if (Path.size() < S.size() && S.find(Path) == 0) {
if (Path.size() < S.size() && S.starts_with(Path)) {
auto LastSep = S.find_last_of('/');
if (LastSep == Path.size() || LastSep == Path.size() - 1)
return true;
Expand Down

0 comments on commit 5232cec

Please sign in to comment.