From 529f72249c2cf4cefc824a612aeddf2d5f858f54 Mon Sep 17 00:00:00 2001 From: Visal Vijay <150381094+B2krobbery@users.noreply.github.com> Date: Thu, 2 Apr 2026 03:50:56 +0530 Subject: layout: replace string comparison with ID-based matching in WorkspaceAlgoMatcher (#13943) * perf(layout): replace string comparison with ID-based matching in WorkspaceAlgoMatcher * perf(layout): replace string comparison with ID-based matching in WorkspaceAlgoMatcher --- src/layout/supplementary/WorkspaceAlgoMatcher.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/layout/supplementary/WorkspaceAlgoMatcher.cpp') diff --git a/src/layout/supplementary/WorkspaceAlgoMatcher.cpp b/src/layout/supplementary/WorkspaceAlgoMatcher.cpp index 98cdb773..0bf394a4 100644 --- a/src/layout/supplementary/WorkspaceAlgoMatcher.cpp +++ b/src/layout/supplementary/WorkspaceAlgoMatcher.cpp @@ -1,5 +1,6 @@ #include "WorkspaceAlgoMatcher.hpp" - +#include +#include #include "../../config/ConfigValue.hpp" #include "../../config/shared/workspace/WorkspaceRuleManager.hpp" @@ -14,6 +15,8 @@ #include "../../Compositor.hpp" +static const std::unordered_map layoutIDs = {{"dwindle", 1}, {"master", 2}, {"scrolling", 3}, {"monocle", 4}, {"default", 5}, {"floating", 6}}; + using namespace Layout; using namespace Layout::Supplementary; @@ -112,7 +115,7 @@ SP CWorkspaceAlgoMatcher::createAlgorithmForWorkspace(PHLWORKSPACE w } void CWorkspaceAlgoMatcher::updateWorkspaceLayouts() { - // TODO: make this ID-based, string comparison is slow + // TODO: fully migrate layout selection to ID-based system (comparison optimized) for (const auto& ws : g_pCompositor->getWorkspaces()) { if (!ws) continue; @@ -123,9 +126,18 @@ void CWorkspaceAlgoMatcher::updateWorkspaceLayouts() { continue; const auto LAYOUT_TO_USE = tiledAlgoForWorkspace(ws.lock()); + auto itLayout = layoutIDs.find(LAYOUT_TO_USE); + const int layoutID = (itLayout != layoutIDs.end()) ? itLayout->second : -1; - if (m_algoNames.contains(&typeid(*TILED_ALGO.get())) && m_algoNames.at(&typeid(*TILED_ALGO.get())) == LAYOUT_TO_USE) - continue; + if (m_algoNames.contains(&typeid(*TILED_ALGO.get()))) { + const auto& currentName = m_algoNames.at(&typeid(*TILED_ALGO.get())); + + auto itCurrent = layoutIDs.find(currentName); + const int currentID = (itCurrent != layoutIDs.end()) ? itCurrent->second : -1; + + if (currentID == layoutID) + continue; + } // needs a switchup ws->m_space->algorithm()->updateTiledAlgo(algoForNameTiled(LAYOUT_TO_USE)); -- cgit v1.2.3