Improve FileUtils::addSearchPath(#872)

Avoid duplicate search path
This commit is contained in:
tkzcfc 2022-09-29 23:10:30 +08:00 committed by GitHub
parent c01af9d338
commit 1263d05b76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -928,6 +928,18 @@ void FileUtils::addSearchPath(std::string_view searchpath, const bool front)
path += "/"; path += "/";
} }
auto it = std::find(_searchPathArray.begin(), _searchPathArray.end(), path);
if (it != _searchPathArray.end())
{
_searchPathArray.erase(it);
auto itOrigin = std::find(_originalSearchPaths.begin(), _originalSearchPaths.end(), std::string{searchpath});
if (itOrigin != _originalSearchPaths.end())
{
_originalSearchPaths.erase(itOrigin);
}
}
if (front) if (front)
{ {
_originalSearchPaths.insert(_originalSearchPaths.begin(), std::string{searchpath}); _originalSearchPaths.insert(_originalSearchPaths.begin(), std::string{searchpath});