diff options
author | Sebastian Geerken <devnull@localhost> | 2016-02-27 13:59:00 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2016-02-27 13:59:00 +0100 |
commit | ec1fc5e6aec8d4020eef89df8cf22235059ef11e (patch) | |
tree | fd9604030fe5b9bfad41a66845c187be04a8bb33 | |
parent | 382392aad21b6ade257e813aa836457d94af1b8f (diff) |
Optimzie OOFFloatsMgr::markSizeChange.
-rw-r--r-- | dw/ooffloatsmgr.cc | 36 | ||||
-rw-r--r-- | dw/ooffloatsmgr.hh | 12 |
2 files changed, 47 insertions, 1 deletions
diff --git a/dw/ooffloatsmgr.cc b/dw/ooffloatsmgr.cc index 06bab82b..5ea648b6 100644 --- a/dw/ooffloatsmgr.cc +++ b/dw/ooffloatsmgr.cc @@ -291,6 +291,16 @@ void OOFFloatsMgr::SortedFloatsVector::put (Float *vloat) vloat->index = size() - 1; } +int OOFFloatsMgr::TBInfo::ComparePosition::compare (Object *o1, Object *o2) +{ + TBInfo *tbInfo1 = (TBInfo*)o1, *tbInfo2 = (TBInfo*)o2; + int y1 = tbInfo1->getOOFAwareWidget () == NULL ? tbInfo1->y : + tbInfo1->getOOFAwareWidget()->getGeneratorY (oofmIndex); + int y2 = tbInfo2->getOOFAwareWidget () == NULL ? tbInfo2->y : + tbInfo2->getOOFAwareWidget()->getGeneratorY (oofmIndex); + return y1 - y2; +} + OOFFloatsMgr::TBInfo::TBInfo (OOFFloatsMgr *oofm, OOFAwareWidget *textblock, TBInfo *parent, int parentExtIndex) : WidgetInfo (oofm, textblock) @@ -637,7 +647,11 @@ void OOFFloatsMgr::markSizeChange (int ref) vloat->dirty = true; DBG_OBJ_SET_BOOL_O (vloat->getWidget (), "<Float>.dirty", vloat->dirty); - for (int i = 0; i < tbInfos->size (); i++) + int first = findTBInfo (vloat->yReal); + // The determination of the last element could perhaps be optimized, but we + // do not yet know the *new* height of the float. + int last = tbInfos->size () - 1; + for (int i = first; i <= last; i++) tbInfos->get(i)->getOOFAwareWidget()->borderChanged (oofmIndex, vloat->yReal, vloat->getWidget ()); @@ -645,6 +659,26 @@ void OOFFloatsMgr::markSizeChange (int ref) DBG_OBJ_LEAVE (); } +/** + * `y` is given relative to the container. + */ +int OOFFloatsMgr::findTBInfo (int y) +{ + DBG_OBJ_ENTER_O ("findTBInfo", 0, oofm, "findTBInfo", "%d", y); + + TBInfo key (this, NULL, NULL, 0); + key.y = y; + TBInfo::ComparePosition comparator (oofmIndex); + int index = tbInfos->bsearch (&key, false, &comparator); + + // "bsearch" returns next greater, but we are interrested in the last which + // is less or equal. + int result = index > 0 ? index - 1 : index; + + DBG_OBJ_LEAVE_VAL_O (oofm, "%d", result); + return result; +} + void OOFFloatsMgr::markExtremesChange (int ref) { diff --git a/dw/ooffloatsmgr.hh b/dw/ooffloatsmgr.hh index 27d296a9..87cdc866 100644 --- a/dw/ooffloatsmgr.hh +++ b/dw/ooffloatsmgr.hh @@ -126,7 +126,18 @@ private: class TBInfo: public WidgetInfo { public: + class ComparePosition: public lout::object::Comparator + { + private: + int oofmIndex; + + public: + inline ComparePosition (int oofmIndex) { this->oofmIndex = oofmIndex; } + int compare (Object *o1, Object *o2); + }; + int index; // position within "tbInfos" + int y; // used for sorting TBInfo *parent; int parentExtIndex; @@ -157,6 +168,7 @@ private: void moveExternalIndices (lout::container::typed::Vector<Float> *list, int oldStartIndex, int diff); Float *findFloatByWidget (core::Widget *widget); + int findTBInfo (int y); void sizeAllocateFloats (Side side); int getGBWidthForAllocation (Float *vloat); |