From 5486995a0082b8e50d9adb417457be90b31c2efb Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 10 Sep 2024 22:28:12 +0300 Subject: [PATCH] Path: use vec instead of set --- src/path/Path.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/path/Path.cpp b/src/path/Path.cpp index d306c88..1376bf7 100644 --- a/src/path/Path.cpp +++ b/src/path/Path.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include using namespace Hyprutils; @@ -11,6 +11,11 @@ namespace Hyprutils::Path { return basePath + "/hypr/" + programName + ".conf"; } + void push_if_new(std::vector vec, std::string str) { + if (std::find(vec.begin(), vec.end(), str) == vec.end()) + vec.push_back(str); + } + std::optional getHome() { static const auto homeDir = getenv("HOME"); @@ -49,23 +54,23 @@ namespace Hyprutils::Path { using T = std::optional; std::pair findConfig(std::string programName) { std::string configPath; - std::set paths; + std::vector 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);