diff options
author | Sebastian Geerken <devnull@localhost> | 2014-12-08 14:50:43 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2014-12-08 14:50:43 +0100 |
commit | aa15346bc3f383b6104e4e89a5b76ca9f7b49e23 (patch) | |
tree | 12f7ead1826ecb54bc8315b35898b557126cc670 | |
parent | a7960cd35790d4e30edffd356f667e5fa08c44c5 (diff) |
Performance of floats collision testing.
-rw-r--r-- | dw/outofflowmgr.cc | 36 | ||||
-rw-r--r-- | dw/outofflowmgr.hh | 3 |
2 files changed, 31 insertions, 8 deletions
diff --git a/dw/outofflowmgr.cc b/dw/outofflowmgr.cc index 23e30d86..2e8eef4b 100644 --- a/dw/outofflowmgr.cc +++ b/dw/outofflowmgr.cc @@ -962,7 +962,7 @@ void OutOfFlowMgr::checkAllocatedFloatCollisions (Side side) if (vloat->generatingBlock != other->generatingBlock) { int yRealNewSame; - if (collidesV (vloat, other, CB, &yRealNewSame)) { + if (collidesV (vloat, other, CB, &yRealNewSame, true)) { DBG_OBJ_MSGF ("resize.oofm", 1, "=> collides, new yReal = %d (old: %d)", yRealNewSame, vloat->yReal); @@ -993,7 +993,7 @@ void OutOfFlowMgr::checkAllocatedFloatCollisions (Side side) for (bool foundColl = false; !foundColl && oppIndexTmp >= 0 && collidesV (vloat, oppList->get (oppIndexTmp), CB, - &yRealNewOpp); + &yRealNewOpp, true); oppIndexTmp--) { DBG_OBJ_MSGF ("resize.oofm", 1, "opposite side (after collision (v) test): " @@ -1542,7 +1542,7 @@ void OutOfFlowMgr::tellFloatPosition (Widget *widget, int yReq) int index = vloat->getIndex (listSame->type), yRealNew; if (index >= 1 && collidesV (vloat, listSame->get (index - 1), listSame->type, - &yRealNew)) { + &yRealNew, false)) { vloat->yReal = yRealNew; DBG_OBJ_SET_NUM_O (vloat->getWidget (), "<Float>.yReal", vloat->yReal); } @@ -1580,7 +1580,7 @@ void OutOfFlowMgr::tellFloatPosition (Widget *widget, int yReq) for (bool foundColl = false; !foundColl && oppFloatIndex >= 0 && collidesV (vloat, listOpp->get (oppFloatIndex), listSame->type, - &yRealNew); + &yRealNew, false); oppFloatIndex--) { // ... but stop the loop as soon as the horizontal dimensions // test is positive. @@ -1598,7 +1598,7 @@ void OutOfFlowMgr::tellFloatPosition (Widget *widget, int yReq) } bool OutOfFlowMgr::collidesV (Float *vloat, Float *other, SFVType type, - int *yReal) + int *yReal, bool useAllocation) { // Only checks vertical (possible) collisions, and only refers to // vloat->yReal; never to vloat->allocation->y, even when the GBs are @@ -1636,13 +1636,35 @@ bool OutOfFlowMgr::collidesV (Float *vloat, Float *other, SFVType type, assert (wasAllocated (vloat->generatingBlock)); Allocation *gba = getAllocation (vloat->generatingBlock), *flaOther = other->getWidget()->getAllocation (); + + // We distinguish two cases (by different values of useAllocation): + // (i) within tellPosition, GB allocation + yReal is used for the + // y position of the other float, while (ii) in checkAllocatedFloat- + // Collisions, the float allocation is used. The latter is necessary + // by the definition of this method, the former increases performance, + // as compared to using the float allocation, in some cases, as in + // this: + // + // When '<div><div style="float:left">[Some text]</div></div>' is + // repeated n times, the resize idle function (Layout::resizeIdle) + // would be repeated roughly n times, when also in case (i) the float + // allocation is used, since for the collision test of float n with + // float n - 1, the allocation of float n - 1 does not yet reflect the + // collision test between n - 1 and n - 2, but yReal does for n - 1. + // + // Cases where this is incorrect will hopefully be rare, and, in any + // case, corrected in sizeAllocateEnd, either because hasRelation- + // Changed returns true, or in checkAllocatedFloatCollisions. + + int otherFloatY = useAllocation ? flaOther->y : + getAllocation(other->generatingBlock)->y + other->yReal; int otherBottomGB = - flaOther->y + flaOther->ascent + flaOther->descent - gba->y; + otherFloatY + flaOther->ascent + flaOther->descent - gba->y; DBG_OBJ_MSGF ("resize.oofm", 1, "different generators: " "otherBottomGB = %d + (%d + %d) - %d = %d", - flaOther->y, flaOther->ascent, flaOther->descent, gba->y, + otherFloatY, flaOther->ascent, flaOther->descent, gba->y, otherBottomGB); if (vloat->yReal < otherBottomGB) { diff --git a/dw/outofflowmgr.hh b/dw/outofflowmgr.hh index 1c17ecdb..24607bad 100644 --- a/dw/outofflowmgr.hh +++ b/dw/outofflowmgr.hh @@ -283,7 +283,8 @@ private: core::Widget *getFloatWidgetAtPoint (SortedFloatsVector *list, int x, int y, int level); - bool collidesV (Float *vloat, Float *other, SFVType type, int *yReal); + bool collidesV (Float *vloat, Float *other, SFVType type, int *yReal, + bool useAllocation); bool collidesH (Float *vloat, Float *other, SFVType type); void getFloatsListsAndSide (Float *vloat, SortedFloatsVector **listSame, |