Skip to content

Commit 5232cec

Browse files
authored
Apply modernize-use-starts-ends-with on llvm-project (#89140)
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.
1 parent d634b23 commit 5232cec

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

clang-tools-extra/clang-doc/Representation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx,
380380
this->SourceRoot = std::string(SourceRootDir);
381381
if (!RepositoryUrl.empty()) {
382382
this->RepositoryUrl = std::string(RepositoryUrl);
383-
if (!RepositoryUrl.empty() && RepositoryUrl.find("http://") != 0 &&
384-
RepositoryUrl.find("https://") != 0)
383+
if (!RepositoryUrl.empty() && !RepositoryUrl.starts_with("http://") &&
384+
!RepositoryUrl.starts_with("https://"))
385385
this->RepositoryUrl->insert(0, "https://");
386386
}
387387
}

lldb/unittests/Host/FileSystemTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class DummyFileSystem : public vfs::FileSystem {
9393
std::map<std::string, vfs::Status>::iterator I;
9494
std::string Path;
9595
bool isInPath(StringRef S) {
96-
if (Path.size() < S.size() && S.find(Path) == 0) {
96+
if (Path.size() < S.size() && S.starts_with(Path)) {
9797
auto LastSep = S.find_last_of('/');
9898
if (LastSep == Path.size() || LastSep == Path.size() - 1)
9999
return true;

llvm/unittests/Support/VirtualFileSystemTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class DummyFileSystem : public vfs::FileSystem {
101101
std::map<std::string, vfs::Status>::iterator I;
102102
std::string Path;
103103
bool isInPath(StringRef S) {
104-
if (Path.size() < S.size() && S.find(Path) == 0) {
104+
if (Path.size() < S.size() && S.starts_with(Path)) {
105105
auto LastSep = S.find_last_of('/');
106106
if (LastSep == Path.size() || LastSep == Path.size() - 1)
107107
return true;

0 commit comments

Comments
 (0)