Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

constify the remaining for loops #7534

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hyprctl/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ void instancesRequest(bool json) {
std::vector<SInstanceData> inst = instances();

if (!json) {
for (auto& el : inst) {
for (auto const& el : inst) {
result += std::format("instance {}:\n\ttime: {}\n\tpid: {}\n\twl socket: {}\n\n", el.id, el.time, el.pid, el.wlSocket);
}
} else {
result += '[';
for (auto& el : inst) {
for (auto const& el : inst) {
result += std::format(R"#(
{{
"instance": "{}",
Expand Down
2 changes: 1 addition & 1 deletion hyprpm/src/core/DataState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void DataState::addNewPluginRepo(const SPluginRepository& repo) {
{"rev", repo.rev}
}}
};
for (auto& p : repo.plugins) {
for (auto const& p : repo.plugins) {
// copy .so to the good place
if (std::filesystem::exists(p.filename))
std::filesystem::copy_file(p.filename, PATH + "/" + p.name + ".so");
Expand Down
4 changes: 2 additions & 2 deletions hyprpm/src/core/Manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CManifest::CManifest(const eManifestType type, const std::string& path) {
auto manifest = toml::parse_file(path);

if (type == MANIFEST_HYPRLOAD) {
for (auto& [key, val] : manifest) {
for (auto const& [key, val] : manifest) {
if (key.str().ends_with(".build"))
continue;

Expand Down Expand Up @@ -63,7 +63,7 @@ CManifest::CManifest(const eManifestType type, const std::string& path) {
}
}

for (auto& [key, val] : manifest) {
for (auto const& [key, val] : manifest) {
if (key.str() == "repository")
continue;

Expand Down
38 changes: 19 additions & 19 deletions hyprpm/src/core/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string&

progress.m_iSteps = 2;
progress.printMessageAbove(std::string{Colors::GREEN} + "✔" + Colors::RESET + " parsed manifest, found " + std::to_string(pManifest->m_vPlugins.size()) + " plugins:");
for (auto& pl : pManifest->m_vPlugins) {
for (auto const& pl : pManifest->m_vPlugins) {
std::string message = std::string{Colors::RESET} + " → " + pl.name + " by ";
for (auto& a : pl.authors) {
for (auto const& a : pl.authors) {
message += a + ", ";
}
if (pl.authors.size() > 0) {
Expand All @@ -222,7 +222,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string&

progress.printMessageAbove(std::string{Colors::RESET} + " → Manifest has " + std::to_string(pManifest->m_sRepository.commitPins.size()) + " pins, checking");

for (auto& [hl, plugin] : pManifest->m_sRepository.commitPins) {
for (auto const& [hl, plugin] : pManifest->m_sRepository.commitPins) {
if (hl != HLVER.hash)
continue;

Expand Down Expand Up @@ -264,7 +264,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string&

progress.printMessageAbove(std::string{Colors::RESET} + " → Building " + p.name);

for (auto& bs : p.buildSteps) {
for (auto const& bs : p.buildSteps) {
std::string cmd = std::format("cd {} && PKG_CONFIG_PATH=\"{}/share/pkgconfig\" {}", m_szWorkingPluginDirectory, DataState::getHeadersPath(), bs);
out += " -> " + cmd + "\n" + execAndGet(cmd) + "\n";
}
Expand Down Expand Up @@ -299,7 +299,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string&
repo.url = url;
repo.rev = rev;
repo.hash = repohash;
for (auto& p : pManifest->m_vPlugins) {
for (auto const& p : pManifest->m_vPlugins) {
repo.plugins.push_back(SPlugin{p.name, m_szWorkingPluginDirectory + "/" + p.output, false, p.failed});
}
DataState::addNewPluginRepo(repo);
Expand Down Expand Up @@ -579,7 +579,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
const std::string USERNAME = getpwuid(getuid())->pw_name;
m_szWorkingPluginDirectory = "/tmp/hyprpm/" + USERNAME;

for (auto& repo : REPOS) {
for (auto const& repo : REPOS) {
bool update = forceUpdateAll;

progress.m_iSteps++;
Expand Down Expand Up @@ -658,7 +658,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {

progress.printMessageAbove(std::string{Colors::RESET} + " → Manifest has " + std::to_string(pManifest->m_sRepository.commitPins.size()) + " pins, checking");

for (auto& [hl, plugin] : pManifest->m_sRepository.commitPins) {
for (auto const& [hl, plugin] : pManifest->m_sRepository.commitPins) {
if (hl != HLVER.hash)
continue;

Expand All @@ -679,7 +679,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {

progress.printMessageAbove(std::string{Colors::RESET} + " → Building " + p.name);

for (auto& bs : p.buildSteps) {
for (auto const& bs : p.buildSteps) {
std::string cmd = std::format("cd {} && PKG_CONFIG_PATH=\"{}/share/pkgconfig\" {}", m_szWorkingPluginDirectory, DataState::getHeadersPath(), bs);
out += " -> " + cmd + "\n" + execAndGet(cmd) + "\n";
}
Expand Down Expand Up @@ -709,7 +709,7 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) {
if (repohash.length() > 0)
repohash.pop_back();
newrepo.hash = repohash;
for (auto& p : pManifest->m_vPlugins) {
for (auto const& p : pManifest->m_vPlugins) {
const auto OLDPLUGINIT = std::find_if(repo.plugins.begin(), repo.plugins.end(), [&](const auto& other) { return other.name == p.name; });
newrepo.plugins.push_back(SPlugin{p.name, m_szWorkingPluginDirectory + "/" + p.output, OLDPLUGINIT != repo.plugins.end() ? OLDPLUGINIT->enabled : false});
}
Expand Down Expand Up @@ -794,8 +794,8 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
const auto REPOS = DataState::getAllRepositories();

auto enabled = [REPOS](const std::string& plugin) -> bool {
for (auto& r : REPOS) {
for (auto& p : r.plugins) {
for (auto const& r : REPOS) {
for (auto const& p : r.plugins) {
if (p.name == plugin && p.enabled)
return true;
}
Expand All @@ -805,8 +805,8 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
};

auto repoForName = [REPOS](const std::string& name) -> std::string {
for (auto& r : REPOS) {
for (auto& p : r.plugins) {
for (auto const& r : REPOS) {
for (auto const& p : r.plugins) {
if (p.name == name)
return r.name;
}
Expand All @@ -816,7 +816,7 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
};

// unload disabled plugins
for (auto& p : loadedPlugins) {
for (auto const& p : loadedPlugins) {
if (!enabled(p)) {
// unload
loadUnloadPlugin(HYPRPMPATH + repoForName(p) + "/" + p + ".so", false);
Expand All @@ -825,8 +825,8 @@ ePluginLoadStateReturn CPluginManager::ensurePluginsLoadState() {
}

// load enabled plugins
for (auto& r : REPOS) {
for (auto& p : r.plugins) {
for (auto const& r : REPOS) {
for (auto const& p : r.plugins) {
if (!p.enabled)
continue;

Expand Down Expand Up @@ -855,10 +855,10 @@ bool CPluginManager::loadUnloadPlugin(const std::string& path, bool load) {
void CPluginManager::listAllPlugins() {
const auto REPOS = DataState::getAllRepositories();

for (auto& r : REPOS) {
for (auto const& r : REPOS) {
std::cout << std::string{Colors::RESET} + " → Repository " + r.name + ":\n";

for (auto& p : r.plugins) {
for (auto const& p : r.plugins) {

std::cout << std::string{Colors::RESET} + " │ Plugin " + p.name;

Expand Down Expand Up @@ -905,7 +905,7 @@ std::string CPluginManager::headerErrorShort(const eHeadersErrors err) {

bool CPluginManager::hasDeps() {
std::vector<std::string> deps = {"meson", "cpio", "cmake", "pkg-config"};
for (auto& d : deps) {
for (auto const& d : deps) {
if (!execAndGet("command -v " + d).contains("/"))
return false;
}
Expand Down
Loading
Loading