mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-15 10:25:59 +01:00
internal: few more marginal optimisations from profiling (#8271)
* deco: reduce local temporars and function calls profiling shows this is a high used function, reduce the amount of function calls and local temporar copies and also check if we even need to add extents at all in the loop. * popup: optimize bfhelper in popups pass nodes as const reference and reserve the size of the children node vector help reduce the reallocations. * procotol: make compositor bfhelper use const ref use const ref for nodes and reserve second nodes vector size to reduce amount of reallocation needed.
This commit is contained in:
parent
d49a1334a8
commit
c7315617eb
5 changed files with 29 additions and 20 deletions
|
@ -288,12 +288,13 @@ bool CPopup::visible() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPopup::bfHelper(std::vector<CPopup*> nodes, std::function<void(CPopup*, void*)> fn, void* data) {
|
void CPopup::bfHelper(std::vector<CPopup*> const& nodes, std::function<void(CPopup*, void*)> fn, void* data) {
|
||||||
for (auto const& n : nodes) {
|
for (auto const& n : nodes) {
|
||||||
fn(n, data);
|
fn(n, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CPopup*> nodes2;
|
std::vector<CPopup*> nodes2;
|
||||||
|
nodes2.reserve(nodes.size() * 2);
|
||||||
|
|
||||||
for (auto const& n : nodes) {
|
for (auto const& n : nodes) {
|
||||||
for (auto const& c : n->m_vChildren) {
|
for (auto const& c : n->m_vChildren) {
|
||||||
|
|
|
@ -81,5 +81,5 @@ class CPopup {
|
||||||
|
|
||||||
Vector2D localToGlobal(const Vector2D& rel);
|
Vector2D localToGlobal(const Vector2D& rel);
|
||||||
Vector2D t1ParentCoords();
|
Vector2D t1ParentCoords();
|
||||||
static void bfHelper(std::vector<CPopup*> nodes, std::function<void(CPopup*, void*)> fn, void* data);
|
static void bfHelper(std::vector<CPopup*> const& nodes, std::function<void(CPopup*, void*)> fn, void* data);
|
||||||
};
|
};
|
||||||
|
|
|
@ -252,9 +252,10 @@ void CWLSurfaceResource::resetRole() {
|
||||||
role = makeShared<CDefaultSurfaceRole>();
|
role = makeShared<CDefaultSurfaceRole>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWLSurfaceResource::bfHelper(std::vector<SP<CWLSurfaceResource>> nodes, std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data) {
|
void CWLSurfaceResource::bfHelper(std::vector<SP<CWLSurfaceResource>> const& nodes, std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data) {
|
||||||
|
|
||||||
std::vector<SP<CWLSurfaceResource>> nodes2;
|
std::vector<SP<CWLSurfaceResource>> nodes2;
|
||||||
|
nodes2.reserve(nodes.size() * 2);
|
||||||
|
|
||||||
// first, gather all nodes below
|
// first, gather all nodes below
|
||||||
for (auto const& n : nodes) {
|
for (auto const& n : nodes) {
|
||||||
|
|
|
@ -147,7 +147,7 @@ class CWLSurfaceResource {
|
||||||
void dropPendingBuffer();
|
void dropPendingBuffer();
|
||||||
void dropCurrentBuffer();
|
void dropCurrentBuffer();
|
||||||
void commitPendingState();
|
void commitPendingState();
|
||||||
void bfHelper(std::vector<SP<CWLSurfaceResource>> nodes, std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
|
void bfHelper(std::vector<SP<CWLSurfaceResource>> const& nodes, std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
|
||||||
void updateCursorShm();
|
void updateCursorShm();
|
||||||
|
|
||||||
friend class CWLPointerResource;
|
friend class CWLPointerResource;
|
||||||
|
|
|
@ -294,13 +294,11 @@ SBoxExtents CDecorationPositioner::getWindowDecorationReserved(PHLWINDOW pWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
SBoxExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly) {
|
SBoxExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOW pWindow, bool inputOnly) {
|
||||||
CBox accum = pWindow->getWindowMainSurfaceBox();
|
CBox const mainSurfaceBox = pWindow->getWindowMainSurfaceBox();
|
||||||
|
CBox accum = mainSurfaceBox;
|
||||||
|
|
||||||
for (auto const& data : m_vWindowPositioningDatas) {
|
for (auto const& data : m_vWindowPositioningDatas) {
|
||||||
if (!data->pDecoration)
|
if (!data->pDecoration || (inputOnly && !(data->pDecoration->getDecorationFlags() & DECORATION_ALLOWS_MOUSE_INPUT)))
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!(data->pDecoration->getDecorationFlags() & DECORATION_ALLOWS_MOUSE_INPUT) && inputOnly)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto const window = data->pWindow.lock();
|
auto const window = data->pWindow.lock();
|
||||||
|
@ -308,31 +306,40 @@ SBoxExtents CDecorationPositioner::getWindowDecorationExtents(PHLWINDOW pWindow,
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
CBox decoBox;
|
CBox decoBox;
|
||||||
|
|
||||||
if (data->positioningInfo.policy == DECORATION_POSITION_ABSOLUTE) {
|
if (data->positioningInfo.policy == DECORATION_POSITION_ABSOLUTE) {
|
||||||
decoBox = data->pWindow->getWindowMainSurfaceBox();
|
decoBox = mainSurfaceBox;
|
||||||
decoBox.addExtents(data->positioningInfo.desiredExtents);
|
decoBox.addExtents(data->positioningInfo.desiredExtents);
|
||||||
} else {
|
} else {
|
||||||
decoBox = data->lastReply.assignedGeometry;
|
decoBox = data->lastReply.assignedGeometry;
|
||||||
const auto EDGEPOINT = getEdgeDefinedPoint(data->positioningInfo.edges, pWindow);
|
decoBox.translate(getEdgeDefinedPoint(data->positioningInfo.edges, pWindow));
|
||||||
decoBox.translate(EDGEPOINT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check bounds only if decoBox extends beyond accum
|
||||||
SBoxExtents extentsToAdd;
|
SBoxExtents extentsToAdd;
|
||||||
|
bool needUpdate = false;
|
||||||
|
|
||||||
if (decoBox.x < accum.x)
|
if (decoBox.x < accum.x) {
|
||||||
extentsToAdd.topLeft.x = accum.x - decoBox.x;
|
extentsToAdd.topLeft.x = accum.x - decoBox.x;
|
||||||
if (decoBox.y < accum.y)
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
if (decoBox.y < accum.y) {
|
||||||
extentsToAdd.topLeft.y = accum.y - decoBox.y;
|
extentsToAdd.topLeft.y = accum.y - decoBox.y;
|
||||||
if (decoBox.x + decoBox.w > accum.x + accum.w)
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
if (decoBox.x + decoBox.w > accum.x + accum.w) {
|
||||||
extentsToAdd.bottomRight.x = (decoBox.x + decoBox.w) - (accum.x + accum.w);
|
extentsToAdd.bottomRight.x = (decoBox.x + decoBox.w) - (accum.x + accum.w);
|
||||||
if (decoBox.y + decoBox.h > accum.y + accum.h)
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
if (decoBox.y + decoBox.h > accum.y + accum.h) {
|
||||||
extentsToAdd.bottomRight.y = (decoBox.y + decoBox.h) - (accum.y + accum.h);
|
extentsToAdd.bottomRight.y = (decoBox.y + decoBox.h) - (accum.y + accum.h);
|
||||||
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (needUpdate)
|
||||||
accum.addExtents(extentsToAdd);
|
accum.addExtents(extentsToAdd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return accum.extentsFrom(pWindow->getWindowMainSurfaceBox());
|
return accum.extentsFrom(mainSurfaceBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
CBox CDecorationPositioner::getBoxWithIncludedDecos(PHLWINDOW pWindow) {
|
CBox CDecorationPositioner::getBoxWithIncludedDecos(PHLWINDOW pWindow) {
|
||||||
|
|
Loading…
Reference in a new issue