[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 <lionel_debroux@yahoo.fr>
This commit is contained in:
Lionel Debroux
2018-09-26 15:36:08 +02:00
committed by EmilieNumworks
parent 1a8c6b6ae9
commit ddebc06fa5
2 changed files with 17 additions and 27 deletions

View File

@@ -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);

View File

@@ -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() {
}