Skip to content

Commit

Permalink
Path: use vec instead of set
Browse files Browse the repository at this point in the history
  • Loading branch information
fufexan committed Sep 10, 2024
1 parent 01f69fa commit 5486995
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/path/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <hyprutils/string/VarList.hpp>
#include <hyprutils/debug/Log.hpp>
#include <filesystem>
#include <set>
#include <vector>

using namespace Hyprutils;

Expand All @@ -11,6 +11,11 @@ namespace Hyprutils::Path {
return basePath + "/hypr/" + programName + ".conf";
}

void push_if_new(std::vector<std::string> vec, std::string str) {
if (std::find(vec.begin(), vec.end(), str) == vec.end())
vec.push_back(str);
}

std::optional<std::string> getHome() {
static const auto homeDir = getenv("HOME");

Expand Down Expand Up @@ -49,23 +54,23 @@ namespace Hyprutils::Path {
using T = std::optional<std::string>;
std::pair<T, T> findConfig(std::string programName) {
std::string configPath;
std::set<std::string> paths;
std::vector<std::string> paths;

static const auto xdgConfigHome = getXdgConfigHome();
if (xdgConfigHome.has_value())
paths.insert(xdgConfigHome.value());
push_if_new(paths, xdgConfigHome.value());

static const auto home = getHome();
if (home.has_value())
paths.insert(home.value());
push_if_new(paths, home.value());

static const auto xdgConfigDirs = getXdgConfigDirs();
if (xdgConfigDirs.has_value()) {
for (auto dir : xdgConfigDirs.value())
paths.insert(dir);
push_if_new(paths, dir);
}

paths.insert("/etc/xdg");
push_if_new(paths, "/etc/xdg");

for (auto path : paths) {
configPath = fullConfigPath(path, programName);
Expand Down

0 comments on commit 5486995

Please sign in to comment.