From 967be8b95a64c7723d22db8bcbd1c4a3bee9fe0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 7 Sep 2012 09:40:44 +0200 Subject: [PATCH] Improve performance of Scene::Window Replace dynamic_casts to check the type for for Toplevel by isFoo() calls and use static_casts in such blocks. Furthermore method shape() returns now a constant reference instead of a copy of the QRegion. REVIEW: 106364 --- scene.cpp | 28 ++++++++++++++-------------- scene.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/scene.cpp b/scene.cpp index 0c5f6339a9..4444d05c47 100644 --- a/scene.cpp +++ b/scene.cpp @@ -490,7 +490,7 @@ void Scene::Window::discardShape() // Find out the shape of the window using the XShape extension // or if shape is not set then simply it's the window geometry. -QRegion Scene::Window::shape() const +const QRegion &Scene::Window::shape() const { if (!shape_valid) { Client* c = dynamic_cast< Client* >(toplevel); @@ -519,29 +519,28 @@ QRegion Scene::Window::shape() const QRegion Scene::Window::clientShape() const { - Client *c = dynamic_cast< Client* >(toplevel); - if (c && c->isShade()) - return QRegion(); + if (toplevel->isClient()) { + Client *c = static_cast< Client * > (toplevel); + if (c->isShade()) + return QRegion(); + } + // TODO: cache const QRegion r = shape() & QRect(toplevel->clientPos(), toplevel->clientSize()); return r.isEmpty() ? QRegion() : r; } bool Scene::Window::isVisible() const { - if (dynamic_cast< Deleted* >(toplevel) != NULL) + if (toplevel->isDeleted()) return false; if (!toplevel->isOnCurrentDesktop()) return false; if (!toplevel->isOnCurrentActivity()) return false; - if (Client* c = dynamic_cast< Client* >(toplevel)) - return c->isShown(true); + if (toplevel->isClient()) + return (static_cast< Client *>(toplevel))->isShown(true); return true; // Unmanaged is always visible - // TODO there may be transformations, so ignore this for now - return !toplevel->geometry() - .intersected(QRect(0, 0, displayWidth(), displayHeight())) - .isEmpty(); } bool Scene::Window::isOpaque() const @@ -557,13 +556,14 @@ bool Scene::Window::isPaintingEnabled() const void Scene::Window::resetPaintingEnabled() { disable_painting = 0; - if (dynamic_cast< Deleted* >(toplevel) != NULL) + if (toplevel->isDeleted()) disable_painting |= PAINT_DISABLED_BY_DELETE; if (!toplevel->isOnCurrentDesktop()) disable_painting |= PAINT_DISABLED_BY_DESKTOP; if (!toplevel->isOnCurrentActivity()) disable_painting |= PAINT_DISABLED_BY_ACTIVITY; - if (Client* c = dynamic_cast< Client* >(toplevel)) { + if (toplevel->isClient()) { + Client *c = static_cast(toplevel); if (c->isMinimized()) disable_painting |= PAINT_DISABLED_BY_MINIMIZE; if (c->tabGroup() && c != c->tabGroup()->current()) @@ -612,7 +612,7 @@ WindowQuadList Scene::Window::buildQuads(bool force) const if (m_shadow) { ret << m_shadow->shadowQuads(); } - effects->buildQuads(static_cast(toplevel)->effectWindow(), ret); + effects->buildQuads(toplevel->effectWindow(), ret); cached_quad_list = new WindowQuadList(ret); return ret; } diff --git a/scene.h b/scene.h index d6db74a575..a5159480ba 100644 --- a/scene.h +++ b/scene.h @@ -207,7 +207,7 @@ public: // is the window fully opaque bool isOpaque() const; // shape of the window - QRegion shape() const; + const QRegion &shape() const; QRegion clientShape() const; void discardShape(); void updateToplevel(Toplevel* c);