From 31531b6cbaf11a7ff46e6665f990adc88e8d7696dbdd707e7bd01264bb60cca7 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sat, 9 Aug 2025 05:54:51 -0400 Subject: [PATCH] Remove a complex `instanceOf` usage. The condition chain here is rather baroque, so I'm making this its own commit for `git bisect` purposes. --- dw/oofawarewidget.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/dw/oofawarewidget.cc b/dw/oofawarewidget.cc index 33d548b..5e627d4 100644 --- a/dw/oofawarewidget.cc +++ b/dw/oofawarewidget.cc @@ -129,12 +129,16 @@ bool OOFAwareWidget::isOOFContainer (Widget *widget, int oofmIndex) // TODO The methods isPossibleContainer() and isPossibleContainerParent() // are only used in few cases. Does not matter currently, however. + // This was created to cleanup the `instanceOf` calls in the + // complex conditionals, below. It relies upon certain + // sequence point and ordering rules of short-circuit evaluation. + OOFAwareWidget *oaw; switch (oofmIndex) { case OOFM_FLOATS: - return widget->instanceOf () && + return (oaw= dynamic_cast< OOFAwareWidget *>( widget )) && (// For floats, only some OOF aware widgets are considered as // containers. - ((OOFAwareWidget*)widget)->isPossibleOOFContainer (OOFM_FLOATS) && + oaw->isPossibleOOFContainer (OOFM_FLOATS) && // The second condition: that this block is "out of flow", in a // wider sense. (// The toplevel widget is "out of flow", since there is no @@ -145,9 +149,8 @@ bool OOFAwareWidget::isOOFContainer (Widget *widget, int oofmIndex) // is also a text block, so possible float container) // within a table widget, which is not a suitable float // container parent). - !(widget->getParent()->instanceOf () && - ((OOFAwareWidget*)widget->getParent()) - ->isPossibleOOFContainerParent (OOFM_FLOATS)) || + !((oaw= dynamic_cast ( widget->getParent() )) && + oaw->isPossibleOOFContainerParent (OOFM_FLOATS)) || // Inline blocks are containing blocks, too. widget->getStyle()->display == DISPLAY_INLINE_BLOCK || // Same for blocks with 'overview' set to another value than @@ -163,7 +166,7 @@ bool OOFAwareWidget::isOOFContainer (Widget *widget, int oofmIndex) case OOFM_RELATIVE: case OOFM_ABSOLUTE: - return widget->instanceOf () && + return dynamic_cast< OOFAwareWidget * >( widget ) && (widget->getParent() == NULL || OOFAwareWidget::testWidgetPositioned (widget));