Skip to content

Commit

Permalink
perf(gui): improve widget destruction performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Mar 4, 2019
1 parent ac3ac06 commit 87aff87
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/gui/widget_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ void LCUI_InitWidgetEvent(LCUI_WidgetEvent e, const char *name)
static void Widget_AddEventRecord(LCUI_Widget widget, LCUI_WidgetEventPack pack)
{
WidgetEventRecord record;

LCUIMutex_Lock(&self.mutex);
record = RBTree_CustomGetData(&self.event_records, widget);
if (!record) {
Expand All @@ -215,6 +216,7 @@ static int Widget_DeleteEventRecord(LCUI_Widget widget,
int ret = 0;
WidgetEventRecord record;
LinkedListNode *node, *prev;

LCUIMutex_Lock(&self.mutex);
record = RBTree_CustomGetData(&self.event_records, widget);
if (!record) {
Expand All @@ -238,6 +240,7 @@ static void WidgetEventTranslator(LCUI_Event e, LCUI_WidgetEventPack pack)
{
WidgetEventHandler handler = e->data;
LCUI_Widget w = pack->widget;

if (!w) {
return;
}
Expand Down Expand Up @@ -641,6 +644,10 @@ int Widget_StopEventPropagation(LCUI_Widget widget)
LinkedListNode *node;
WidgetEventRecord record;
LCUI_WidgetEventPack pack;

if (self.event_records.total_node <= 1) {
return 0;
}
LCUIMutex_Lock(&self.mutex);
record = RBTree_CustomGetData(&self.event_records, widget);
if (!record) {
Expand Down Expand Up @@ -828,6 +835,9 @@ void LCUIWidget_ClearEventTarget(LCUI_Widget widget)
WidgetEventRecord record;
LCUI_WidgetEventPack pack;

if (self.event_records.total_node <= 1) {
return;
}
LCUIMutex_Lock(&self.mutex);
record = RBTree_CustomGetData(&self.event_records, widget);
if (record) {
Expand Down Expand Up @@ -1198,6 +1208,10 @@ int Widget_SetTouchCapture(LCUI_Widget w, int point_id)
int Widget_ReleaseTouchCapture(LCUI_Widget w, int point_id)
{
int ret;

if (self.touch_capturers.length <= 1) {
return 0;
}
LCUIMutex_Lock(&self.mutex);
ret = TouchCapturers_Delete(&self.touch_capturers, w, point_id);
LCUIMutex_Unlock(&self.mutex);
Expand Down

0 comments on commit 87aff87

Please sign in to comment.