From ddebc06fa58bdaa841030d0e8ab3a46d48d10714 Mon Sep 17 00:00:00 2001 From: Lionel Debroux Date: Wed, 26 Sep 2018 15:36:08 +0200 Subject: [PATCH] [escher] Move View's destructor, and several other methods, to the header, so that the compiler can leverage its prior knowledge of the fact that the destructor is trivial (noticed by disassembling the code) to greatly optimize derived classes' destructors. Signed-off-by: Lionel Debroux --- escher/include/escher/view.h | 21 +++++++++++++++++---- escher/src/view.cpp | 23 ----------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/escher/include/escher/view.h b/escher/include/escher/view.h index f674a47b8..32bfe796d 100644 --- a/escher/include/escher/view.h +++ b/escher/include/escher/view.h @@ -26,12 +26,21 @@ class View { friend class TransparentView; public: View(); - virtual ~View(); + virtual ~View() { + for (int i = 0; i < numberOfSubviews(); i++) { + View * subview = subviewAtIndex(i); + if (subview != nullptr) { + subview->m_superview = nullptr; + } + } + } View(View&& other) = default; View(const View& other) = delete; View& operator=(const View& other) = delete; View& operator=(View&& other) = delete; - void resetSuperview(); + void resetSuperview() { + m_superview = nullptr; + } /* The drawRect method should be implemented by each View subclass. In a * typical drawRect implementation, a subclass will make drawing calls to the * Kandinsky library using the provided context. */ @@ -66,8 +75,12 @@ protected: #endif KDRect m_frame; private: - virtual int numberOfSubviews() const; - virtual View * subviewAtIndex(int index); + virtual int numberOfSubviews() const { + return 0; + } + virtual View * subviewAtIndex(int index) { + return nullptr; + } virtual void layoutSubviews(); virtual const Window * window() const; KDRect redraw(KDRect rect, KDRect forceRedrawRect = KDRectZero); diff --git a/escher/src/view.cpp b/escher/src/view.cpp index 64cfcc62d..6ba058589 100644 --- a/escher/src/view.cpp +++ b/escher/src/view.cpp @@ -10,19 +10,6 @@ View::View() : { } -View::~View() { - for (int i = 0; i < numberOfSubviews(); i++) { - View * subview = subviewAtIndex(i); - if (subview != nullptr) { - subview->m_superview = nullptr; - } - } -} - -void View::resetSuperview() { - m_superview = nullptr; -} - void View::drawRect(KDContext * ctx, KDRect rect) const { // By default, a view doesn't do anything // It's transparent! @@ -121,7 +108,6 @@ void View::setSize(KDSize size) { setFrame(KDRect(m_frame.origin(), size)); } - void View::setFrame(KDRect frame) { if (frame == m_frame) { return; @@ -183,15 +169,6 @@ KDSize View::minimalSizeForOptimalDisplay() const { return KDSizeZero; } -int View::numberOfSubviews() const { - return 0; -} - -View * View::subviewAtIndex(int index) { - assert(false); - return nullptr; -} - void View::layoutSubviews() { }