Skip to content

Commit

Permalink
perf(gui): improve Widget_Empty() performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Mar 4, 2019
1 parent 1df08b6 commit 1654963
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
31 changes: 20 additions & 11 deletions src/gui/widget_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,32 @@ void Widget_Destroy(LCUI_Widget w)
void Widget_Empty(LCUI_Widget w)
{
LCUI_Widget root = w;
LCUI_Widget child;
LinkedListNode *node;
LCUI_WidgetEventRec ev;

while (root->parent) {
root = root->parent;
}
if (root == LCUIWidget.root) {
LinkedListNode *next, *node;
node = w->children.head.next;
while (node) {
next = node->next;
Widget_AddToTrash(node->data);
node = next;
}
Widget_InvalidateArea(w, NULL, SV_GRAPH_BOX);
Widget_AddTask(w, LCUI_WTASK_LAYOUT);
} else {
if (root != LCUIWidget.root) {
Widget_DestroyChildren(w);
return;
}
LCUI_InitWidgetEvent(&ev, "unlink");
for (LinkedList_Each(node, &w->children)) {
child = node->data;
Widget_TriggerEvent(child, &ev, NULL);
if (child->parent == root) {
Widget_PostSurfaceEvent(child, LCUI_WEVENT_UNLINK,
TRUE);
}
child->state = LCUI_WSTATE_DELETED;
child->parent = NULL;
}
LinkedList_ClearData(&w->children_show, NULL);
LinkedList_Concat(&LCUIWidget.trash, &w->children);
Widget_InvalidateArea(w, NULL, SV_GRAPH_BOX);
Widget_AddTask(w, LCUI_WTASK_LAYOUT);
}

void Widget_GetOffset(LCUI_Widget w, LCUI_Widget parent, float *offset_x,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widget_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int Widget_HandleClassesChange(LCUI_Widget w, const char *name)
}
/* If widget is not ready, indicate that the style of the children has
* been marked needs to be refreshed */
if (w->state < LCUI_WSTATE_READY) {
if (w->state < LCUI_WSTATE_READY || w->state == LCUI_WSTATE_DELETED) {
return 1;
}
if (Widget_GetChildrenStyleChanges(w, 0, name) > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widget_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void Widget_MarkChildrenRefreshByStatus(LCUI_Widget w)
static int Widget_HandleStatusChange(LCUI_Widget w, const char *name)
{
Widget_UpdateStyle(w, TRUE);
if (w->state < LCUI_WSTATE_READY) {
if (w->state < LCUI_WSTATE_READY || w->state == LCUI_WSTATE_DELETED) {
return 1;
}
if (w->rules && w->rules->ignore_status_change) {
Expand Down
1 change: 1 addition & 0 deletions src/gui/widget_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ int Widget_Unlink(LCUI_Widget widget)
LCUI_Widget child;
LCUI_WidgetEventRec ev = { 0 };
LinkedListNode *node, *snode;

if (!widget->parent) {
return -1;
}
Expand Down

0 comments on commit 1654963

Please sign in to comment.