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

make most for loops use const references #7527

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
32 changes: 16 additions & 16 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void CCompositor::initServer(std::string socketName, int socketFd) {

initManagers(STAGE_LATE);

for (auto& o : pendingOutputs) {
for (auto const& o : pendingOutputs) {
onNewMonitor(o);
}
pendingOutputs.clear();
Expand Down Expand Up @@ -403,7 +403,7 @@ void CCompositor::initAllSignals() {

m_bSessionActive = false;

for (auto& m : m_vMonitors) {
for (auto const& m : m_vMonitors) {
m->noFrameSchedule = true;
m->framesToSkip = 1;
}
Expand Down Expand Up @@ -741,7 +741,7 @@ CMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
float bestDistance = 0.f;
SP<CMonitor> pBestMon;

for (auto& m : m_vMonitors) {
for (auto const& m : m_vMonitors) {
float dist = vecToRectDistanceSquared(point, m->vecPosition, m->vecPosition + m->vecSize);

if (dist < bestDistance || !pBestMon) {
Expand Down Expand Up @@ -1164,8 +1164,8 @@ void CCompositor::focusSurface(SP<CWLSurfaceResource> pSurface, PHLWINDOW pWindo
}

SP<CWLSurfaceResource> CCompositor::vectorToLayerPopupSurface(const Vector2D& pos, CMonitor* monitor, Vector2D* sCoords, PHLLS* ppLayerSurfaceFound) {
for (auto& lsl : monitor->m_aLayerSurfaceLayers | std::views::reverse) {
for (auto& ls : lsl | std::views::reverse) {
for (auto const& lsl : monitor->m_aLayerSurfaceLayers | std::views::reverse) {
for (auto const& ls : lsl | std::views::reverse) {
if (ls->fadingOut || !ls->layerSurface || (ls->layerSurface && !ls->layerSurface->mapped) || ls->alpha.value() == 0.f)
continue;

Expand All @@ -1183,7 +1183,7 @@ SP<CWLSurfaceResource> CCompositor::vectorToLayerPopupSurface(const Vector2D& po
}

SP<CWLSurfaceResource> CCompositor::vectorToLayerSurface(const Vector2D& pos, std::vector<PHLLSREF>* layerSurfaces, Vector2D* sCoords, PHLLS* ppLayerSurfaceFound) {
for (auto& ls : *layerSurfaces | std::views::reverse) {
for (auto const& ls : *layerSurfaces | std::views::reverse) {
if (ls->fadingOut || !ls->layerSurface || (ls->layerSurface && !ls->layerSurface->surface->mapped) || ls->alpha.value() == 0.f)
continue;

Expand Down Expand Up @@ -1458,7 +1458,7 @@ void CCompositor::cleanupFadingOut(const MONITORID& monid) {
g_pHyprOpenGL->markBlurDirtyForMonitor(getMonitorFromID(monid));

if (ls->fadingOut && ls->readyToDelete && ls->isFadedOut()) {
for (auto& m : m_vMonitors) {
for (auto const& m : m_vMonitors) {
for (auto& lsl : m->m_aLayerSurfaceLayers) {
if (!lsl.empty() && std::find_if(lsl.begin(), lsl.end(), [&](auto& other) { return other == ls; }) != lsl.end()) {
std::erase_if(lsl, [&](auto& other) { return other == ls || !other; });
Expand Down Expand Up @@ -1718,7 +1718,7 @@ PHLWINDOW CCompositor::getPrevWindowOnWorkspace(PHLWINDOW pWindow, bool focusabl

WORKSPACEID CCompositor::getNextAvailableNamedWorkspace() {
WORKSPACEID lowest = -1337 + 1;
for (auto& w : m_vWorkspaces) {
for (auto const& w : m_vWorkspaces) {
if (w->m_iID < -1 && w->m_iID < lowest)
lowest = w->m_iID;
}
Expand Down Expand Up @@ -1748,7 +1748,7 @@ PHLWORKSPACE CCompositor::getWorkspaceByString(const std::string& str) {
}

bool CCompositor::isPointOnAnyMonitor(const Vector2D& point) {
for (auto& m : m_vMonitors) {
for (auto const& m : m_vMonitors) {
if (VECINRECT(point, m->vecPosition.x, m->vecPosition.y, m->vecSize.x + m->vecPosition.x, m->vecSize.y + m->vecPosition.y))
return true;
}
Expand Down Expand Up @@ -1834,7 +1834,7 @@ CMonitor* CCompositor::getMonitorInDirection(CMonitor* pSourceMonitor, const cha
}

void CCompositor::updateAllWindowsAnimatedDecorationValues() {
for (auto& w : m_vWindows) {
for (auto const& w : m_vWindows) {
if (!w->m_bIsMapped)
continue;

Expand Down Expand Up @@ -2139,7 +2139,7 @@ void CCompositor::moveWorkspaceToMonitor(PHLWORKSPACE pWorkspace, CMonitor* pMon
if (!SWITCHINGISACTIVE)
nextWorkspaceOnMonitorID = pWorkspace->m_iID;
else {
for (auto& w : m_vWorkspaces) {
for (auto const& w : m_vWorkspaces) {
if (w->m_iMonitorID == POLDMON->ID && w->m_iID != pWorkspace->m_iID && !w->m_bIsSpecialWorkspace) {
nextWorkspaceOnMonitorID = w->m_iID;
break;
Expand Down Expand Up @@ -2237,7 +2237,7 @@ bool CCompositor::workspaceIDOutOfBounds(const WORKSPACEID& id) {
WORKSPACEID lowestID = INT64_MAX;
WORKSPACEID highestID = INT64_MIN;

for (auto& w : m_vWorkspaces) {
for (auto const& w : m_vWorkspaces) {
if (w->m_bIsSpecialWorkspace)
continue;

Expand Down Expand Up @@ -2271,7 +2271,7 @@ void CCompositor::updateFullscreenFadeOnWorkspace(PHLWORKSPACE pWorkspace) {
const auto PMONITOR = getMonitorFromID(pWorkspace->m_iMonitorID);

if (pWorkspace->m_iID == PMONITOR->activeWorkspaceID() || pWorkspace->m_iID == PMONITOR->activeSpecialWorkspaceID()) {
for (auto& ls : PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) {
for (auto const& ls : PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) {
if (!ls->fadingOut)
ls->alpha = FULLSCREEN && pWorkspace->m_efFullscreenMode == FSMODE_FULLSCREEN ? 0.f : 1.f;
}
Expand Down Expand Up @@ -2376,7 +2376,7 @@ PHLWINDOW CCompositor::getX11Parent(PHLWINDOW pWindow) {
if (!pWindow->m_bIsX11)
return nullptr;

for (auto& w : m_vWindows) {
for (auto const& w : m_vWindows) {
if (!w->m_bIsX11)
continue;

Expand Down Expand Up @@ -2543,7 +2543,7 @@ void CCompositor::closeWindow(PHLWINDOW pWindow) {
PHLLS CCompositor::getLayerSurfaceFromSurface(SP<CWLSurfaceResource> pSurface) {
std::pair<SP<CWLSurfaceResource>, bool> result = {pSurface, false};

for (auto& ls : m_vLayers) {
for (auto const& ls : m_vLayers) {
if (ls->layerSurface && ls->layerSurface->surface == pSurface)
return ls;

Expand Down Expand Up @@ -2679,7 +2679,7 @@ bool CCompositor::isWorkspaceSpecial(const WORKSPACEID& id) {

WORKSPACEID CCompositor::getNewSpecialID() {
WORKSPACEID highest = SPECIAL_WORKSPACE_START;
for (auto& ws : m_vWorkspaces) {
for (auto const& ws : m_vWorkspaces) {
if (ws->m_bIsSpecialWorkspace && ws->m_iID > highest) {
highest = ws->m_iID;
}
Expand Down
36 changes: 18 additions & 18 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,11 +813,11 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
static const auto PENABLEEXPLICIT = CConfigValue<Hyprlang::INT>("render:explicit_sync");
static int prevEnabledExplicit = *PENABLEEXPLICIT;

for (auto& w : g_pCompositor->m_vWindows) {
for (auto const& w : g_pCompositor->m_vWindows) {
w->uncacheWindowDecos();
}

for (auto& m : g_pCompositor->m_vMonitors)
for (auto const& m : g_pCompositor->m_vMonitors)
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);

// Update the keyboard layout to the cfg'd one if this is not the first launch
Expand Down Expand Up @@ -901,7 +901,7 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
m->forceFullFrames = 2;

// also force mirrors, as the aspect ratio could've changed
for (auto& mirror : m->mirrors)
for (auto const& mirror : m->mirrors)
mirror->forceFullFrames = 3;
}

Expand Down Expand Up @@ -940,7 +940,7 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std::

// invalidate layouts if they changed
if (COMMAND == "monitor" || COMMAND.contains("gaps_") || COMMAND.starts_with("dwindle:") || COMMAND.starts_with("master:")) {
for (auto& m : g_pCompositor->m_vMonitors)
for (auto const& m : g_pCompositor->m_vMonitors)
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
}

Expand Down Expand Up @@ -1034,15 +1034,15 @@ std::string CConfigManager::getDeviceString(const std::string& dev, const std::s
}

SMonitorRule CConfigManager::getMonitorRuleFor(const CMonitor& PMONITOR) {
for (auto& r : m_dMonitorRules | std::views::reverse) {
for (auto const& r : m_dMonitorRules | std::views::reverse) {
if (PMONITOR.matchesStaticSelector(r.name)) {
return r;
}
}

Debug::log(WARN, "No rule found for {}, trying to use the first.", PMONITOR.szName);

for (auto& r : m_dMonitorRules) {
for (auto const& r : m_dMonitorRules) {
if (r.name.empty()) {
return r;
}
Expand Down Expand Up @@ -1354,7 +1354,7 @@ void CConfigManager::dispatchExecOnce() {
firstExecDispatched = true;
isLaunchingExecOnce = true;

for (auto& c : firstExecRequests) {
for (auto const& c : firstExecRequests) {
handleRawExec("", c);
}

Expand Down Expand Up @@ -1438,7 +1438,7 @@ bool CConfigManager::deviceConfigExists(const std::string& dev) {
}

bool CConfigManager::shouldBlurLS(const std::string& ns) {
for (auto& bls : m_dBlurLSNamespaces) {
for (auto const& bls : m_dBlurLSNamespaces) {
if (bls == ns) {
return true;
}
Expand Down Expand Up @@ -1553,7 +1553,7 @@ CMonitor* CConfigManager::getBoundMonitorForWS(const std::string& wsname) {
}

std::string CConfigManager::getBoundMonitorStringForWS(const std::string& wsname) {
for (auto& wr : m_dWorkspaceRules) {
for (auto const& wr : m_dWorkspaceRules) {
const auto WSNAME = wr.workspaceName.starts_with("name:") ? wr.workspaceName.substr(5) : wr.workspaceName;

if (WSNAME == wsname)
Expand Down Expand Up @@ -1624,7 +1624,7 @@ void CConfigManager::addPluginKeyword(HANDLE handle, const std::string& name, Hy
}

void CConfigManager::removePluginConfig(HANDLE handle) {
for (auto& k : pluginKeywords) {
for (auto const& k : pluginKeywords) {
if (k.handle != handle)
continue;

Expand All @@ -1647,7 +1647,7 @@ std::string CConfigManager::getDefaultWorkspaceFor(const std::string& name) {
if (other->monitor == name)
return other->workspaceString;
if (other->monitor.substr(0, 5) == "desc:") {
auto monitor = g_pCompositor->getMonitorFromDesc(other->monitor.substr(5));
auto const monitor = g_pCompositor->getMonitorFromDesc(other->monitor.substr(5));
if (monitor && monitor->szName == name)
return other->workspaceString;
}
Expand Down Expand Up @@ -2044,7 +2044,7 @@ std::optional<std::string> CConfigManager::handleBind(const std::string& command
bool dontInhibit = false;
const auto BINDARGS = command.substr(4);

for (auto& arg : BINDARGS) {
for (auto const& arg : BINDARGS) {
if (arg == 'l') {
locked = true;
} else if (arg == 'r') {
Expand Down Expand Up @@ -2222,9 +2222,9 @@ std::optional<std::string> CConfigManager::handleLayerRule(const std::string& co

m_dLayerRules.push_back({VALUE, RULE});

for (auto& m : g_pCompositor->m_vMonitors)
for (auto& lsl : m->m_aLayerSurfaceLayers)
for (auto& ls : lsl)
for (auto const& m : g_pCompositor->m_vMonitors)
for (auto const& lsl : m->m_aLayerSurfaceLayers)
for (auto const& ls : lsl)
ls->applyRules();

return {};
Expand Down Expand Up @@ -2423,9 +2423,9 @@ void CConfigManager::updateBlurredLS(const std::string& name, const bool forceBl
matchName = matchName.substr(8);
}

for (auto& m : g_pCompositor->m_vMonitors) {
for (auto& lsl : m->m_aLayerSurfaceLayers) {
for (auto& ls : lsl) {
for (auto const& m : g_pCompositor->m_vMonitors) {
for (auto const& lsl : m->m_aLayerSurfaceLayers) {
for (auto const& ls : lsl) {
if (BYADDRESS) {
if (std::format("0x{:x}", (uintptr_t)ls.get()) == matchName)
ls->forceBlur = forceBlur;
Expand Down
26 changes: 13 additions & 13 deletions src/debug/HyprCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) {
if (format == eHyprCtlOutputFormat::FORMAT_JSON) {
result += "[";

for (auto& m : allMonitors ? g_pCompositor->m_vRealMonitors : g_pCompositor->m_vMonitors) {
for (auto const& m : allMonitors ? g_pCompositor->m_vRealMonitors : g_pCompositor->m_vMonitors) {
result += CHyprCtl::getMonitorData(m, format);
}

trimTrailingComma(result);

result += "]";
} else {
for (auto& m : allMonitors ? g_pCompositor->m_vRealMonitors : g_pCompositor->m_vMonitors) {
for (auto const& m : allMonitors ? g_pCompositor->m_vRealMonitors : g_pCompositor->m_vMonitors) {
if (!m->output || m->ID == -1)
continue;

Expand Down Expand Up @@ -272,7 +272,7 @@ std::string clientsRequest(eHyprCtlOutputFormat format, std::string request) {
if (format == eHyprCtlOutputFormat::FORMAT_JSON) {
result += "[";

for (auto& w : g_pCompositor->m_vWindows) {
for (auto const& w : g_pCompositor->m_vWindows) {
if (!w->m_bIsMapped && !g_pHyprCtl->m_sCurrentRequestParams.all)
continue;

Expand All @@ -283,7 +283,7 @@ std::string clientsRequest(eHyprCtlOutputFormat format, std::string request) {

result += "]";
} else {
for (auto& w : g_pCompositor->m_vWindows) {
for (auto const& w : g_pCompositor->m_vWindows) {
if (!w->m_bIsMapped && !g_pHyprCtl->m_sCurrentRequestParams.all)
continue;

Expand Down Expand Up @@ -381,15 +381,15 @@ std::string workspacesRequest(eHyprCtlOutputFormat format, std::string request)

if (format == eHyprCtlOutputFormat::FORMAT_JSON) {
result += "[";
for (auto& w : g_pCompositor->m_vWorkspaces) {
for (auto const& w : g_pCompositor->m_vWorkspaces) {
result += CHyprCtl::getWorkspaceData(w, format);
result += ",";
}

trimTrailingComma(result);
result += "]";
} else {
for (auto& w : g_pCompositor->m_vWorkspaces) {
for (auto const& w : g_pCompositor->m_vWorkspaces) {
result += CHyprCtl::getWorkspaceData(w, format);
}
}
Expand All @@ -401,15 +401,15 @@ std::string workspaceRulesRequest(eHyprCtlOutputFormat format, std::string reque
std::string result = "";
if (format == eHyprCtlOutputFormat::FORMAT_JSON) {
result += "[";
for (auto& r : g_pConfigManager->getAllWorkspaceRules()) {
for (auto const& r : g_pConfigManager->getAllWorkspaceRules()) {
result += getWorkspaceRuleData(r, format);
result += ",";
}

trimTrailingComma(result);
result += "]";
} else {
for (auto& r : g_pConfigManager->getAllWorkspaceRules()) {
for (auto const& r : g_pConfigManager->getAllWorkspaceRules()) {
result += getWorkspaceRuleData(r, format);
}
}
Expand Down Expand Up @@ -437,7 +437,7 @@ std::string layersRequest(eHyprCtlOutputFormat format, std::string request) {
if (format == eHyprCtlOutputFormat::FORMAT_JSON) {
result += "{\n";

for (auto& mon : g_pCompositor->m_vMonitors) {
for (auto const& mon : g_pCompositor->m_vMonitors) {
result += std::format(
R"#("{}": {{
"levels": {{
Expand Down Expand Up @@ -744,7 +744,7 @@ std::string animationsRequest(eHyprCtlOutputFormat format, std::string request)

ret += ",\n[";

for (auto& bz : g_pAnimationManager->getAllBeziers()) {
for (auto const& bz : g_pAnimationManager->getAllBeziers()) {
ret += std::format(R"#(
{{
"name": "{}"
Expand Down Expand Up @@ -782,7 +782,7 @@ std::string globalShortcutsRequest(eHyprCtlOutputFormat format, std::string requ
ret += std::format("{}:{} -> {}\n", sh.appid, sh.id, sh.description);
} else {
ret += "[";
for (auto& sh : SHORTCUTS) {
for (auto const& sh : SHORTCUTS) {
ret += std::format(R"#(
{{
"name": "{}",
Expand Down Expand Up @@ -1286,7 +1286,7 @@ std::string dispatchSetProp(eHyprCtlOutputFormat format, std::string request) {
g_pCompositor->focusWindow(PLASTWINDOW);
}

for (auto& m : g_pCompositor->m_vMonitors)
for (auto const& m : g_pCompositor->m_vMonitors)
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);

return "ok";
Expand Down Expand Up @@ -1386,7 +1386,7 @@ std::string dispatchOutput(eHyprCtlOutputFormat format, std::string request) {
bool added = false;

if (!vars[3].empty()) {
for (auto& m : g_pCompositor->m_vRealMonitors) {
for (auto const& m : g_pCompositor->m_vRealMonitors) {
if (m->szName == vars[3])
return "Name already taken";
}
Expand Down
Loading
Loading