Skip to content

Commit

Permalink
vkconfig: Avoid duplicated paths
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe-lunarg committed Sep 27, 2024
1 parent 74bbd88 commit b2b3234
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
10 changes: 6 additions & 4 deletions vkconfig_core/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ bool Environment::Load() {
// assemble a list of paths that take precidence for layer discovery.
const QString VK_LAYER_PATH(qgetenv("VK_LAYER_PATH"));
if (!VK_LAYER_PATH.isEmpty()) {
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_SET] =
ConvertString(QString(qgetenv("VK_LAYER_PATH")).split(SEPARATOR));
std::vector<std::string> paths = ConvertString(QString(qgetenv("VK_LAYER_PATH")).split(SEPARATOR));
paths = UniqueStrings(paths);
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_SET] = paths;
} else {
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_SET].clear();
}
Expand All @@ -258,8 +259,9 @@ bool Environment::Load() {
// assemble a list of paths that take precidence for layer discovery.
const QString VK_ADD_LAYER_PATH(qgetenv("VK_ADD_LAYER_PATH"));
if (!VK_ADD_LAYER_PATH.isEmpty()) {
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_ADD] =
ConvertString(QString(qgetenv("VK_ADD_LAYER_PATH")).split(SEPARATOR));
std::vector<std::string> paths = ConvertString(QString(qgetenv("VK_ADD_LAYER_PATH")).split(SEPARATOR));
paths = UniqueStrings(paths);
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_ADD] = paths;
} else {
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_ADD].clear();
}
Expand Down
7 changes: 7 additions & 0 deletions vkconfig_core/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <cctype>
#include <regex>
#include <set>

std::string format(const char* message, ...) {
std::size_t const STRING_BUFFER(4096);
Expand Down Expand Up @@ -311,6 +312,12 @@ QStringList ConvertString(const std::vector<std::string>& strings) {
return string_list;
}

std::vector<std::string> UniqueStrings(const std::vector<std::string>& strings) {
std::set<std::string> uniques(strings.begin(), strings.end());
std::vector<std::string> results(uniques.begin(), uniques.end());
return results;
}

std::string ToLowerCase(const std::string& value) {
std::string result = value;

Expand Down
2 changes: 2 additions & 0 deletions vkconfig_core/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ std::vector<std::string> ConvertString(const QStringList& string_list);

QStringList ConvertString(const std::vector<std::string>& strings);

std::vector<std::string> UniqueStrings(const std::vector<std::string>& strings);

std::string ToLowerCase(const std::string& value);

std::string ToUpperCase(const std::string& value);
Expand Down

0 comments on commit b2b3234

Please sign in to comment.