mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 05:26:58 +08:00
find_package: Fix performance regression in 4.0.0 release
In commit e90f60f864
(find_package: Don't glob certain macOS paths,
2024-10-23, v4.0.0-rc1~579^2~1) we changed the name matching logic of
`find_package` to check if a possible match is a directory before
checking whether the name is a match. In some situations, this results
in unnecessarily calling `stat` for a very large number of files, which
can be extremely slow on some systems (especially Windows). Fix this by
making the check the last thing we do before accepting a possible match.
Fixes: #26817
This commit is contained in:

committed by
Brad King

parent
9c8fe5d0b4
commit
bb3a348def
@@ -240,12 +240,14 @@ public:
|
|||||||
for (auto i = 0ul; i < directoryLister.GetNumberOfFiles(); ++i) {
|
for (auto i = 0ul; i < directoryLister.GetNumberOfFiles(); ++i) {
|
||||||
char const* const fname = directoryLister.GetFile(i);
|
char const* const fname = directoryLister.GetFile(i);
|
||||||
// Skip entries to ignore or that aren't directories.
|
// Skip entries to ignore or that aren't directories.
|
||||||
if (isDirentryToIgnore(fname) || !directoryLister.FileIsDirectory(i)) {
|
if (isDirentryToIgnore(fname)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this->Names) {
|
if (!this->Names) {
|
||||||
this->Matches.emplace_back(fname);
|
if (directoryLister.FileIsDirectory(i)) {
|
||||||
|
this->Matches.emplace_back(fname);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (auto const& n : *this->Names) {
|
for (auto const& n : *this->Names) {
|
||||||
// NOTE Customization point for
|
// NOTE Customization point for
|
||||||
@@ -258,7 +260,9 @@ public:
|
|||||||
: cmsysString_strncasecmp(fname, name.c_str(),
|
: cmsysString_strncasecmp(fname, name.c_str(),
|
||||||
name.length())) == 0);
|
name.length())) == 0);
|
||||||
if (equal) {
|
if (equal) {
|
||||||
this->Matches.emplace_back(fname);
|
if (directoryLister.FileIsDirectory(i)) {
|
||||||
|
this->Matches.emplace_back(fname);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user