cmake: avoid getcwd in CollapseFullPath

`CollapseFullPath` calls getcwd, which is a rather expensive system
call. we can replace it with `GetHomeOutputDirectory()` to save us from
the calling overhead
This commit is contained in:
Tim Blechmann 2020-01-14 18:17:50 +08:00
parent 23e782ce05
commit 22f38c0d6b
5 changed files with 10 additions and 5 deletions

View File

@ -215,7 +215,8 @@ bool cmAddCustomCommandCommand(std::vector<std::string> const& args,
} }
if (cmSystemTools::FileIsFullPath(filename)) { if (cmSystemTools::FileIsFullPath(filename)) {
filename = cmSystemTools::CollapseFullPath(filename); filename = cmSystemTools::CollapseFullPath(
filename, status.GetMakefile().GetHomeOutputDirectory());
} }
switch (doing) { switch (doing) {
case doing_depfile: case doing_depfile:

View File

@ -53,7 +53,8 @@ bool cmAddSubDirectoryCommand(std::vector<std::string> const& args,
status.SetError(error); status.SetError(error);
return false; return false;
} }
srcPath = cmSystemTools::CollapseFullPath(srcPath); srcPath =
cmSystemTools::CollapseFullPath(srcPath, mf.GetHomeOutputDirectory());
// Compute the full path to the binary directory. // Compute the full path to the binary directory.
std::string binPath; std::string binPath;

View File

@ -34,7 +34,8 @@ void AppendPaths(const std::vector<std::string>& inputs,
it = cmStrCat(lg->GetMakefile()->GetCurrentBinaryDirectory(), '/', it); it = cmStrCat(lg->GetMakefile()->GetCurrentBinaryDirectory(), '/', it);
} }
if (cmSystemTools::FileIsFullPath(it)) { if (cmSystemTools::FileIsFullPath(it)) {
it = cmSystemTools::CollapseFullPath(it); it = cmSystemTools::CollapseFullPath(
it, lg->GetMakefile()->GetHomeOutputDirectory());
} }
} }
cm::append(output, result); cm::append(output, result);

View File

@ -3087,7 +3087,8 @@ std::vector<BT<std::string>> cmGeneratorTarget::GetIncludeDirectories(
cmLinkImplementationLibraries const* impl = cmLinkImplementationLibraries const* impl =
this->GetLinkImplementationLibraries(config); this->GetLinkImplementationLibraries(config);
for (cmLinkImplItem const& lib : impl->Libraries) { for (cmLinkImplItem const& lib : impl->Libraries) {
std::string libDir = cmSystemTools::CollapseFullPath(lib.AsStr()); std::string libDir = cmSystemTools::CollapseFullPath(
lib.AsStr(), this->Makefile->GetHomeOutputDirectory());
static cmsys::RegularExpression frameworkCheck( static cmsys::RegularExpression frameworkCheck(
"(.*\\.framework)(/Versions/[^/]+)?/[^/]+$"); "(.*\\.framework)(/Versions/[^/]+)?/[^/]+$");

View File

@ -31,7 +31,8 @@ cmSourceFileLocation::cmSourceFileLocation(cmMakefile const* mf,
this->AmbiguousExtension = true; this->AmbiguousExtension = true;
this->Directory = cmSystemTools::GetFilenamePath(name); this->Directory = cmSystemTools::GetFilenamePath(name);
if (cmSystemTools::FileIsFullPath(this->Directory)) { if (cmSystemTools::FileIsFullPath(this->Directory)) {
this->Directory = cmSystemTools::CollapseFullPath(this->Directory); this->Directory = cmSystemTools::CollapseFullPath(
this->Directory, mf->GetHomeOutputDirectory());
} }
this->Name = cmSystemTools::GetFilenameName(name); this->Name = cmSystemTools::GetFilenameName(name);
if (kind == cmSourceFileLocationKind::Known) { if (kind == cmSourceFileLocationKind::Known) {