Improved performance when getting windows list from the active workspace. no more call malloc() every time the list was needed.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11708 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca
2005-03-12 23:26:05 +00:00
parent 3a3b405008
commit c9df3905a8
4 changed files with 42 additions and 36 deletions
+27 -19
View File
@@ -66,7 +66,9 @@ RootLayer::RootLayer(const char *name, int32 workspaceCount,
{ {
fDesktop = desktop; fDesktop = desktop;
fWinBorderList = NULL; fWinBorderListLength = 64;
fWinBorderList2 = (WinBorder**)malloc(fWinBorderListLength * sizeof(WinBorder*));
fWinBorderList = (WinBorder**)malloc(fWinBorderListLength * sizeof(WinBorder*));
fWinBorderCount = 0; fWinBorderCount = 0;
fWinBorderIndex = 0; fWinBorderIndex = 0;
fWsCount = 0; fWsCount = 0;
@@ -321,15 +323,6 @@ void RootLayer::ResizeBy(float x, float y)
Layer* RootLayer::VirtualTopChild() const Layer* RootLayer::VirtualTopChild() const
{ {
if (fWinBorderList)
{
free(fWinBorderList);
fWinBorderList = NULL;
}
void **list;
ActiveWorkspace()->GetWinBorderList(list, &fWinBorderCount);
fWinBorderList = (WinBorder**)list;
fWinBorderIndex = fWinBorderCount-1; fWinBorderIndex = fWinBorderCount-1;
if (fWinBorderIndex < fWinBorderCount && fWinBorderIndex >= 0) if (fWinBorderIndex < fWinBorderCount && fWinBorderIndex >= 0)
@@ -356,15 +349,6 @@ Layer* RootLayer::VirtualUpperSibling() const
Layer* RootLayer::VirtualBottomChild() const Layer* RootLayer::VirtualBottomChild() const
{ {
if (fWinBorderList)
{
free(fWinBorderList);
fWinBorderList = NULL;
}
void **list;
ActiveWorkspace()->GetWinBorderList(list, &fWinBorderCount);
fWinBorderList = (WinBorder**)list;
fWinBorderIndex = 0; fWinBorderIndex = 0;
if (fWinBorderIndex < fWinBorderCount && fWinBorderIndex >= 0) if (fWinBorderIndex < fWinBorderCount && fWinBorderIndex >= 0)
@@ -906,6 +890,8 @@ void RootLayer::MouseEventHandler(int32 code, BPortLink& msg)
exFocus->fDecorator->SetFocus(false); exFocus->fDecorator->SetFocus(false);
if (focus && exFocus != focus && focus->fDecorator) if (focus && exFocus != focus && focus->fDecorator)
focus->fDecorator->SetFocus(true); focus->fDecorator->SetFocus(true);
get_workspace_windows();
BRegion reg(target->fFull); BRegion reg(target->fFull);
reg.Include(&target->fTopLayer->fFull); reg.Include(&target->fTopLayer->fFull);
@@ -1554,6 +1540,8 @@ void RootLayer::show_winBorder(WinBorder *winBorder)
invalidate = invalid; invalidate = invalid;
} }
get_workspace_windows();
if (invalidate) if (invalidate)
{ {
BRegion reg(winBorder->fFull); BRegion reg(winBorder->fFull);
@@ -1581,9 +1569,29 @@ void RootLayer::hide_winBorder(WinBorder *winBorder)
invalidate = invalid; invalidate = invalid;
} }
get_workspace_windows();
if (invalidate) if (invalidate)
{ {
invalidate_layer(this, winBorder->fFullVisible); invalidate_layer(this, winBorder->fFullVisible);
} }
} }
void RootLayer::get_workspace_windows()
{
int32 bufferSize = fWinBorderListLength;
memcpy(fWinBorderList2, fWinBorderList, fWinBorderCount);
if (!(ActiveWorkspace()->GetWinBorderList((void**)fWinBorderList, &bufferSize)))
{
fWinBorderList2 = (WinBorder**)realloc(fWinBorderList2, bufferSize);
fWinBorderList = (WinBorder**)realloc(fWinBorderList, bufferSize);
fWinBorderListLength = bufferSize;
ActiveWorkspace()->GetWinBorderList((void**)fWinBorderList, &bufferSize);
}
fWinBorderCount = bufferSize;
fWinBorderIndex = 0;
}
+4
View File
@@ -136,6 +136,8 @@ friend class Desktop;
void show_winBorder(WinBorder* winBorder); void show_winBorder(WinBorder* winBorder);
void hide_winBorder(WinBorder* winBorder); void hide_winBorder(WinBorder* winBorder);
void get_workspace_windows();
void invalidate_layer(Layer *layer, const BRegion &region); void invalidate_layer(Layer *layer, const BRegion &region);
void redraw_layer(Layer *layer, const BRegion &region); void redraw_layer(Layer *layer, const BRegion &region);
@@ -162,9 +164,11 @@ friend class Desktop;
int32 fActiveWksIndex; int32 fActiveWksIndex;
int32 fWsCount; int32 fWsCount;
Workspace* fWorkspace[32]; Workspace* fWorkspace[32];
mutable WinBorder** fWinBorderList2;
mutable WinBorder** fWinBorderList; mutable WinBorder** fWinBorderList;
mutable int32 fWinBorderCount; mutable int32 fWinBorderCount;
mutable int32 fWinBorderIndex; mutable int32 fWinBorderIndex;
int32 fWinBorderListLength;
int32 fScreenShotIndex; int32 fScreenShotIndex;
bool fQuiting; bool fQuiting;
+10 -16
View File
@@ -215,7 +215,7 @@ WinBorder *Workspace::Front() const
\param list The list of visible WinBorders found in this workspace. \param list The list of visible WinBorders found in this workspace.
\param itemCount Number of WinBorder pointers found in the list. \param itemCount Number of WinBorder pointers found in the list.
*/ */
void Workspace::GetWinBorderList(void **&list, int32 *itemCount ) const bool Workspace::GetWinBorderList(void **list, int32 *itemCount ) const
{ {
int32 count = 0; int32 count = 0;
ListData *cursor; ListData *cursor;
@@ -228,18 +228,15 @@ void Workspace::GetWinBorderList(void **&list, int32 *itemCount ) const
cursor = cursor->upperItem; cursor = cursor->upperItem;
} }
if (count == 0) if (*itemCount < count)
{ {
*itemCount = 0; // buffer not big enough. buffer must be count high
list = NULL; *itemCount = count;
return; return false;
} }
void **mylist; if (list)
mylist = (void**)malloc(sizeof(void*) * count);
if (mylist)
{ {
list = mylist;
*itemCount = count; *itemCount = count;
cursor = fBottomItem; cursor = fBottomItem;
@@ -247,17 +244,14 @@ void Workspace::GetWinBorderList(void **&list, int32 *itemCount ) const
{ {
if (!cursor->layerPtr->IsHidden()) if (!cursor->layerPtr->IsHidden())
{ {
*mylist = cursor->layerPtr; *list = cursor->layerPtr;
mylist++; list++;
} }
cursor = cursor->upperItem; cursor = cursor->upperItem;
} }
} }
else
{ return false;
list = NULL;
itemCount = 0;
}
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
+1 -1
View File
@@ -63,7 +63,7 @@ public:
WinBorder* Focus(void) const; WinBorder* Focus(void) const;
WinBorder* Front(void) const; WinBorder* Front(void) const;
void GetWinBorderList(void **&list, int32 *itemCount ) const; bool GetWinBorderList(void **list, int32 *itemCount ) const;
bool MoveToBack(WinBorder *newLast); bool MoveToBack(WinBorder *newLast);
bool MoveToFront(WinBorder *newFront, bool doNotDisturb = false); bool MoveToFront(WinBorder *newFront, bool doNotDisturb = false);