Skip to content

Commit 4177083

Browse files
authored
fixed #14547 - store absolute path in FileWithDetails (fixes slow lead up to analysis with a lot of input files) (danmar#8282)
1 parent 25fe1de commit 4177083

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

cli/cmdlineparser.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
206206
assert(!(!pathnamesRef.empty() && !fileSettingsRef.empty()));
207207

208208
if (!fileSettingsRef.empty()) {
209-
// TODO: de-duplicate
210-
211209
std::list<FileSettings> fileSettings;
212210
if (!mSettings.fileFilters.empty()) {
213211
// filter only for the selected filenames from all project files
@@ -225,6 +223,8 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
225223
fileSettings = fileSettingsRef;
226224
}
227225

226+
// TODO: de-duplicate
227+
228228
mFileSettings.clear();
229229

230230
frontend::applyLang(fileSettings, mSettings, mEnforcedLang);
@@ -265,19 +265,6 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
265265
return false;
266266
}
267267

268-
// de-duplicate files
269-
{
270-
auto it = filesResolved.begin();
271-
while (it != filesResolved.end()) {
272-
const std::string& absname = Path::getAbsoluteFilePath(it->spath());
273-
// TODO: log if duplicated files were dropped
274-
filesResolved.erase(std::remove_if(std::next(it), filesResolved.end(), [&](const FileWithDetails& entry) {
275-
return Path::getAbsoluteFilePath(entry.spath()) == absname;
276-
}), filesResolved.end());
277-
++it;
278-
}
279-
}
280-
281268
std::list<FileWithDetails> files;
282269
if (!mSettings.fileFilters.empty()) {
283270
files = filterFiles(mSettings.fileFilters, filesResolved);
@@ -291,6 +278,19 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
291278
files = std::move(filesResolved);
292279
}
293280

281+
// de-duplicate files
282+
{
283+
auto it = files.begin();
284+
while (it != files.end()) {
285+
const std::string& absname = it->abspath();
286+
// TODO: log if duplicated files were dropped
287+
files.erase(std::remove_if(std::next(it), files.end(), [&](const FileWithDetails& entry) {
288+
return entry.abspath() == absname;
289+
}), files.end());
290+
++it;
291+
}
292+
}
293+
294294
frontend::applyLang(files, mSettings, mEnforcedLang);
295295

296296
// sort the markup last

lib/filesettings.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class FileWithDetails
5050
{
5151
mPath = std::move(path);
5252
mPathSimplified = Path::simplifyPath(mPath);
53+
mPathAbsolute.clear();
5354
}
5455

5556
const std::string& path() const
@@ -62,6 +63,14 @@ class FileWithDetails
6263
return mPathSimplified;
6364
}
6465

66+
const std::string& abspath() const
67+
{
68+
// use delayed resolution as it will fail for files which do not exist
69+
if (mPathAbsolute.empty())
70+
mPathAbsolute = Path::getAbsoluteFilePath(mPath);
71+
return mPathAbsolute;
72+
}
73+
6574
std::size_t size() const
6675
{
6776
return mSize;
@@ -89,6 +98,7 @@ class FileWithDetails
8998
private:
9099
std::string mPath;
91100
std::string mPathSimplified;
101+
mutable std::string mPathAbsolute;
92102
Standards::Language mLang = Standards::Language::None;
93103
std::size_t mSize;
94104
std::size_t mFsFileId{0};

0 commit comments

Comments
 (0)