data: Fixed performance drop in file path search
This commit is contained in:
+3
-3
@@ -28,7 +28,7 @@ bool Project::loadProjectSettings(const FilePath& projectSettingsFile)
|
||||
{
|
||||
setProjectSettingsFilePath(projectSettingsFile);
|
||||
|
||||
//m_fileManager.reset();
|
||||
m_fileManager.reset();
|
||||
updateFileManager();
|
||||
}
|
||||
return success;
|
||||
@@ -58,7 +58,7 @@ void Project::clearProjectSettings()
|
||||
setProjectSettingsFilePath(FilePath());
|
||||
ProjectSettings::getInstance()->clear();
|
||||
|
||||
//m_fileManager.reset();
|
||||
m_fileManager.reset();
|
||||
}
|
||||
|
||||
void Project::reloadProjectSettings()
|
||||
@@ -161,7 +161,7 @@ Parser::Arguments Project::getParserArguments() const
|
||||
std::vector<FilePath> headerSearchSubPaths;
|
||||
for(FilePath p : projSettings->getHeaderSearchPaths())
|
||||
{
|
||||
std::vector<FilePath> tempPaths = FileSystem::getSubDirectoies(p);
|
||||
std::vector<FilePath> tempPaths = FileSystem::getSubDirectories(p);
|
||||
headerSearchSubPaths.insert( headerSearchSubPaths.end(), tempPaths.begin(), tempPaths.end() );
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,18 @@ void PreprocessorCallbacks::FileChanged(
|
||||
}
|
||||
|
||||
const clang::FileEntry *fileEntry = m_sourceManager.getFileEntryForID(m_sourceManager.getFileID(location));
|
||||
if (fileEntry && m_fileRegister->getFileManager()->hasFilePath(fileEntry->getName()))
|
||||
|
||||
if (!fileEntry)
|
||||
{
|
||||
m_client->onFileParsed(FileInfo(
|
||||
FilePath(fileEntry->getName()),
|
||||
boost::posix_time::from_time_t(fileEntry->getModificationTime())
|
||||
));
|
||||
m_fileRegister->markIncludeFileParsing(fileEntry->getName());
|
||||
return;
|
||||
}
|
||||
|
||||
FilePath filePath(fileEntry->getName());
|
||||
|
||||
if (m_fileRegister->getFileManager()->hasFilePath(filePath.str()))
|
||||
{
|
||||
m_client->onFileParsed(m_fileRegister->getFileManager()->getFileInfo(filePath));
|
||||
m_fileRegister->markIncludeFileParsing(filePath.str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,13 +50,14 @@ void PreprocessorCallbacks::InclusionDirective(
|
||||
std::string baseFilePath = baseFileEntry->getName();
|
||||
std::string includedFilePath = fileEntry->getName();
|
||||
|
||||
if (m_fileRegister->getFileManager()->hasFilePath(baseFilePath) && // check if file is in project
|
||||
m_fileRegister->getFileManager()->hasFilePath(includedFilePath))
|
||||
const FileManager* fileManager = m_fileRegister->getFileManager();
|
||||
if (fileManager->hasFilePath(baseFilePath) && fileManager->hasFilePath(includedFilePath))
|
||||
{
|
||||
FileInfo baseFileInfo(baseFilePath, boost::posix_time::from_time_t(baseFileEntry->getModificationTime()));
|
||||
FileInfo includedFileInfo(includedFilePath, boost::posix_time::from_time_t(fileEntry->getModificationTime()));
|
||||
|
||||
m_client->onFileIncludeParsed(getParseLocation(fileNameRange.getAsRange()), baseFileInfo, includedFileInfo);
|
||||
m_client->onFileIncludeParsed(
|
||||
getParseLocation(fileNameRange.getAsRange()),
|
||||
fileManager->getFileInfo(baseFilePath),
|
||||
fileManager->getFileInfo(includedFilePath)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ void TaskParseCxx::enter()
|
||||
{
|
||||
m_start = utility::durationStart();
|
||||
|
||||
m_client->prepareParsingFile();
|
||||
|
||||
m_parser.setupParsing(m_files, m_arguments);
|
||||
|
||||
for (const FilePath& path : m_parser.getFileRegister()->getUnparsedSourceFilePaths())
|
||||
@@ -69,8 +67,12 @@ Task::TaskState TaskParseCxx::update()
|
||||
|
||||
MessageStatus(ss.str(), false, true).dispatch();
|
||||
|
||||
m_client->prepareParsingFile();
|
||||
|
||||
m_parser.runTool(std::vector<std::string>(1, sourcePath));
|
||||
|
||||
m_client->finishParsingFile();
|
||||
|
||||
if (isSource)
|
||||
{
|
||||
fileRegister->markSourceFileParsed(sourcePath);
|
||||
@@ -83,8 +85,6 @@ void TaskParseCxx::exit()
|
||||
{
|
||||
FileRegister* fileRegister = m_parser.getFileRegister();
|
||||
|
||||
m_client->finishParsingFile();
|
||||
|
||||
MessageFinishedParsing(
|
||||
fileRegister->getParsedFilesCount(),
|
||||
fileRegister->getFilesCount(),
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <set>
|
||||
|
||||
#include "utility/file/FileSystem.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/utility.h"
|
||||
#include "data/access/StorageAccessProxy.h"
|
||||
|
||||
@@ -38,19 +39,26 @@ void FileManager::setPaths(
|
||||
m_includeExtensions = includeExtensions;
|
||||
}
|
||||
|
||||
void FileManager::reset()
|
||||
{
|
||||
m_files.clear();
|
||||
m_addedFiles.clear();
|
||||
m_updatedFiles.clear();
|
||||
m_removedFiles.clear();
|
||||
}
|
||||
|
||||
void FileManager::fetchFilePaths()
|
||||
{
|
||||
std::map<FilePath, FileInfo> files;
|
||||
for (FileInfo oldFileInfo: m_storageAccessProxy->getInfoOnAllFiles())
|
||||
{
|
||||
files[oldFileInfo.path] = oldFileInfo;
|
||||
m_files[oldFileInfo.path] = oldFileInfo;
|
||||
}
|
||||
|
||||
m_addedFiles.clear();
|
||||
m_updatedFiles.clear();
|
||||
m_removedFiles.clear();
|
||||
|
||||
for (std::map<FilePath, FileInfo>::iterator it = files.begin(); it != files.end(); it++)
|
||||
for (std::map<FilePath, FileInfo>::iterator it = m_files.begin(); it != m_files.end(); it++)
|
||||
{
|
||||
m_removedFiles.insert(it->first);
|
||||
}
|
||||
@@ -59,8 +67,8 @@ void FileManager::fetchFilePaths()
|
||||
for (FileInfo fileInfo: fileInfos)
|
||||
{
|
||||
const FilePath& filePath = fileInfo.path;
|
||||
std::map<FilePath, FileInfo>::iterator it = files.find(filePath);
|
||||
if (it != files.end())
|
||||
std::map<FilePath, FileInfo>::iterator it = m_files.find(filePath);
|
||||
if (it != m_files.end())
|
||||
{
|
||||
m_removedFiles.erase(filePath);
|
||||
if (fileInfo.lastWriteTime > it->second.lastWriteTime)
|
||||
@@ -71,10 +79,15 @@ void FileManager::fetchFilePaths()
|
||||
}
|
||||
else
|
||||
{
|
||||
files.insert(std::pair<FilePath, FileInfo>(filePath, fileInfo));
|
||||
m_files.insert(std::pair<FilePath, FileInfo>(filePath, fileInfo));
|
||||
m_addedFiles.insert(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
for (const FilePath& filePath : m_removedFiles)
|
||||
{
|
||||
m_files.erase(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
std::set<FilePath> FileManager::getAddedFilePaths() const
|
||||
@@ -94,16 +107,7 @@ std::set<FilePath> FileManager::getRemovedFilePaths() const
|
||||
|
||||
bool FileManager::hasFilePath(const FilePath& filePath) const
|
||||
{
|
||||
std::vector<FileInfo> fileInfos = getFileInfosInProject();
|
||||
for (size_t i = 0; i < fileInfos.size(); i++)
|
||||
{
|
||||
if (fileInfos[i].path == filePath)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return (m_files.find(filePath) != m_files.end());
|
||||
}
|
||||
|
||||
bool FileManager::hasSourceExtension(const FilePath& filePath) const
|
||||
@@ -116,6 +120,18 @@ bool FileManager::hasIncludeExtension(const FilePath& filePath) const
|
||||
return filePath.hasExtension(m_includeExtensions);
|
||||
}
|
||||
|
||||
const FileInfo& FileManager::getFileInfo(const FilePath& filePath) const
|
||||
{
|
||||
std::map<FilePath, FileInfo>::const_iterator it = m_files.find(filePath);
|
||||
|
||||
if (it == m_files.end())
|
||||
{
|
||||
LOG_ERROR("No FileInfo found for file: " + filePath.str());
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::vector<FileInfo> FileManager::getFileInfosInProject() const
|
||||
{
|
||||
std::vector<FileInfo> fileInfos;
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
std::vector<std::string> includeExtensions
|
||||
);
|
||||
|
||||
void reset();
|
||||
void fetchFilePaths();
|
||||
|
||||
std::set<FilePath> getAddedFilePaths() const;
|
||||
@@ -35,9 +36,13 @@ public:
|
||||
virtual bool hasSourceExtension(const FilePath& filePath) const;
|
||||
virtual bool hasIncludeExtension(const FilePath& filePath) const;
|
||||
|
||||
const FileInfo& getFileInfo(const FilePath& filePath) const;
|
||||
|
||||
private:
|
||||
std::vector<FileInfo> getFileInfosInProject() const;
|
||||
|
||||
std::map<FilePath, FileInfo> m_files;
|
||||
|
||||
std::vector<FilePath> m_sourcePaths;
|
||||
std::vector<FilePath> m_includePaths;
|
||||
std::vector<std::string> m_sourceExtensions;
|
||||
|
||||
@@ -148,12 +148,22 @@ bool FileSystem::equivalent(const std::string& pathA, const std::string& pathB)
|
||||
return boost::filesystem::path(pathA).compare(boost::filesystem::path(pathB)) == 0;
|
||||
}
|
||||
|
||||
std::vector<FilePath> FileSystem::getSubDirectoies(const FilePath &path) {
|
||||
std::vector<FilePath> FileSystem::getSubDirectories(const FilePath &path)
|
||||
{
|
||||
std::vector<FilePath> v;
|
||||
for ( boost::filesystem::recursive_directory_iterator end, dir(path.str());
|
||||
dir != end; ++dir ) {
|
||||
if(boost::filesystem::is_directory(dir->path()))
|
||||
v.push_back(FilePath(dir->path()));
|
||||
|
||||
if (!path.exists())
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
for (boost::filesystem::recursive_directory_iterator end, dir(path.str()); dir != end; dir++)
|
||||
{
|
||||
if (boost::filesystem::is_directory(dir->path()))
|
||||
{
|
||||
v.push_back(FilePath(dir->path()));
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
const std::vector<FilePath>& paths, const std::vector<std::string>& fileExtensions);
|
||||
|
||||
static std::string getTimeStringNow();
|
||||
static std::vector<FilePath> getSubDirectoies(const FilePath& path);
|
||||
static std::vector<FilePath> getSubDirectories(const FilePath& path);
|
||||
|
||||
static bool exists(const std::string& path);
|
||||
static std::string fileName(const std::string& path);
|
||||
|
||||
Reference in New Issue
Block a user