Skip to content

Commit

Permalink
jcc:
Browse files Browse the repository at this point in the history
  optimize RebuildTree(): only call PlaceAll() once
  broadcast from UI thread
  • Loading branch information
jafl committed Jun 9, 2024
1 parent c530050 commit 0614a80
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
6 changes: 3 additions & 3 deletions code_crusader/code/Class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,9 @@ Class::FindParent

// check for any exact match

return okToSearchGhosts &&
itsTree->FindClass(*pInfo->name, &pInfo->parent) &&
pInfo->parent != this;
return (okToSearchGhosts &&
itsTree->FindClass(*pInfo->name, &pInfo->parent) &&
pInfo->parent != this);
}

/******************************************************************************
Expand Down
41 changes: 23 additions & 18 deletions code_crusader/code/Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,17 +749,17 @@ Tree::AddClass
3) All classes inheriting from (2)
4) ...
*** This runs in the update thread.
******************************************************************************/

void
Tree::RebuildTree()
{
JIndex i;

// delete ghost classes and clear all parent-child connections

JSize classCount = itsClassesByFull->GetItemCount();
for (i=classCount; i>=1; i--)
for (JIndex i=classCount; i>=1; i--)
{
Class* theClass = itsClassesByFull->GetItem(i);
if (theClass->IsGhost())
Expand All @@ -782,7 +782,7 @@ JIndex i;
do
{
progress = false;
for (i=1; i<=classCount; i++)
for (JIndex i=1; i<=classCount; i++)
{
progress = itsClassesByFull->GetItem(i)->FindParents(false) || progress;
}
Expand All @@ -792,7 +792,7 @@ JIndex i;
// Now that no more progress is being made, allow ghosts to be created.
// (Inserting ghosts does not cause classes to be skipped.)

for (i=1; i<=classCount; i++)
for (JIndex i=1; i<=classCount; i++)
{
itsClassesByFull->GetItem(i)->FindParents(true);
classCount = GetItemCount();
Expand All @@ -812,6 +812,8 @@ JIndex i;
If necessary or requested, it rebuilds the list of visible classes
and adjusts their placement in the tree.
*** This may run in the update thread.
******************************************************************************/

void
Expand Down Expand Up @@ -867,10 +869,11 @@ Tree::RecalcVisible
}
}

// Now that we know which classes are visible, we can optimize the arrangement
// to minimize the lengths of multiple inheritance links.
// Now that we know which classes are visible, we can place them in the
// shape of a tree and optimize the arrangement to minimize the lengths
// of multiple inheritance links.

if (rebuildVisible || itsVisibleByGeom->IsEmpty())
if (rebuildVisible || itsVisibleByGeom->IsEmpty() || forcePlaceAll)
{
itsVisibleByGeom->CopyPointers(*itsVisibleByName,
itsVisibleByGeom->GetCleanUpAction(), false);
Expand All @@ -891,17 +894,10 @@ Tree::RecalcVisible
}
}

// optimize further
// optimize further; calls PlaceAll()

MinimizeMILinks();
}

// place classes in the shape of a tree

if (rebuildVisible || forcePlaceAll)
{
PlaceAll();
}
}

/******************************************************************************
Expand All @@ -914,6 +910,8 @@ Tree::RecalcVisible
It contains information about root classes that have children
and is sorted by Class*.
*** This may run in the update thread.
******************************************************************************/

void
Expand Down Expand Up @@ -949,7 +947,12 @@ Tree::PlaceAll
itsWidth += itsMarginWidth;
itsHeight += itsMarginWidth;

Broadcast(BoundsChanged());
auto* task = jnew JXUrgentFunctionTask(this, [this]()
{
Broadcast(BoundsChanged());
},
"Tree::PlaceAll::BoundsChanged");
task->Go();
}

/******************************************************************************
Expand All @@ -958,6 +961,8 @@ Tree::PlaceAll
Build the class tree whose root is the given class.
Updates y to include the height of the new subtree.
*** This may run in the update thread.
******************************************************************************/

void
Expand Down Expand Up @@ -991,7 +996,7 @@ Tree::PlaceClass
// By quantizing the y-coordinate, we simplify pagination.

JCoordinate newY = (*y+origY - h)/2;
newY -= (newY - origY) % h;
newY -= (newY - origY) % h;
theClass->SetCoords(x, newY);
}
else
Expand Down
2 changes: 1 addition & 1 deletion code_crusader/jcc.jcc
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ T "./" "echo ====" "" FFFTTFF "" "" "" F
F
# build settings
1
T
F
"jcc"
"${LIB_DEPS}"
"make -k all"
Expand Down

0 comments on commit 0614a80

Please sign in to comment.