Skip to content

Commit

Permalink
perf(gui): remove the mutex in the textview widget
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Mar 4, 2019
1 parent 87aff87 commit 6340d60
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/gui/widget/textview.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ typedef struct LCUI_TextViewRec_ {
wchar_t *content;
LCUI_BOOL trimming;
LCUI_Widget widget;
LCUI_Mutex mutex;
LCUI_TextLayer layer;
LCUI_CSSFontStyleRec style;
LinkedListNode node;
Expand All @@ -79,7 +78,6 @@ typedef struct LCUI_TextViewRec_ {
static struct LCUI_TextViewModule {
int key_word_break;
LinkedList list;
LCUI_Mutex mutex;
LCUI_WidgetPrototype prototype;
} self;

Expand Down Expand Up @@ -266,7 +264,6 @@ static void TextView_OnInit(LCUI_Widget w)
TextLayer_SetUsingStyleTags(txt->layer, TRUE);
Widget_BindEvent(w, "resize", TextView_OnResize, NULL, NULL);
CSSFontStyle_Init(&txt->style);
LCUIMutex_Init(&txt->mutex);
txt->node.data = txt;
txt->node.prev = txt->node.next = NULL;
LinkedList_AppendNode(&self.list, &txt->node);
Expand All @@ -287,14 +284,12 @@ static void TextView_ClearTasks(LCUI_Widget w)
static void TextView_OnDestroy(LCUI_Widget w)
{
LCUI_TextView txt = GetData(w);

LinkedList_Unlink(&self.list, &txt->node);
CSSFontStyle_Destroy(&txt->style);
TextLayer_Destroy(txt->layer);
LCUIMutex_Unlock(&txt->mutex);
TextView_ClearTasks(w);
free(txt->content);
LCUIMutex_Lock(&self.mutex);
LinkedList_Unlink(&self.list, &txt->node);
LCUIMutex_Unlock(&self.mutex);
}

static void TextView_AutoSize(LCUI_Widget w, float *width, float *height)
Expand Down Expand Up @@ -357,14 +352,12 @@ static void TextView_OnTask(LCUI_Widget w)
LinkedList_Init(&rects);
i = TASK_SET_TEXT;
if (txt->tasks[i].is_valid) {
LCUIMutex_Lock(&txt->mutex);
txt->tasks[i].is_valid = FALSE;
TextLayer_SetTextW(txt->layer, txt->tasks[i].text, NULL);
txt->tasks[TASK_UPDATE].is_valid = TRUE;
txt->tasks[TASK_UPDATE_SIZE].is_valid = TRUE;
free(txt->tasks[i].text);
txt->tasks[i].text = NULL;
LCUIMutex_Unlock(&txt->mutex);
}
i = TASK_SET_AUTOWRAP;
if (txt->tasks[i].is_valid) {
Expand Down Expand Up @@ -483,15 +476,13 @@ int TextView_SetTextW(LCUI_Widget w, const wchar_t *text)
}
wcstrim(newtext, text, NULL);
} while (0);
LCUIMutex_Lock(&txt->mutex);
if (txt->tasks[TASK_SET_TEXT].is_valid &&
txt->tasks[TASK_SET_TEXT].text) {
free(txt->tasks[TASK_SET_TEXT].text);
}
txt->tasks[TASK_SET_TEXT].is_valid = TRUE;
txt->tasks[TASK_SET_TEXT].text = newtext;
Widget_AddTask(w, LCUI_WTASK_USER);
LCUIMutex_Unlock(&txt->mutex);
return 0;
}

Expand Down Expand Up @@ -547,15 +538,13 @@ size_t LCUIWidget_RefreshTextView(void)
LCUI_TextView txt;
LinkedListNode *node;

LCUIMutex_Lock(&self.mutex);
for (LinkedList_Each(node, &self.list)) {
txt = node->data;
if (txt->widget->state != LCUI_WSTATE_DELETED) {
Widget_UpdateStyle(txt->widget, TRUE);
}
count += 1;
}
LCUIMutex_Unlock(&self.mutex);
return count;
}

Expand All @@ -575,12 +564,10 @@ void LCUIWidget_AddTextView(void)
self.prototype->setattr = TextView_OnParseAttr;
self.prototype->runtask = TextView_OnTask;
LCUI_AddCSSPropertyParser(&parser);
LCUIMutex_Init(&self.mutex);
LinkedList_Init(&self.list);
}

void LCUIWidget_FreeTextView(void)
{
LinkedList_ClearData(&self.list, NULL);
LCUIMutex_Destroy(&self.mutex);
}

0 comments on commit 6340d60

Please sign in to comment.