Skip to content

Commit 6340d60

Browse files
committed
perf(gui): remove the mutex in the textview widget
1 parent 87aff87 commit 6340d60

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

src/gui/widget/textview.c

+2-15
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ typedef struct LCUI_TextViewRec_ {
6060
wchar_t *content;
6161
LCUI_BOOL trimming;
6262
LCUI_Widget widget;
63-
LCUI_Mutex mutex;
6463
LCUI_TextLayer layer;
6564
LCUI_CSSFontStyleRec style;
6665
LinkedListNode node;
@@ -79,7 +78,6 @@ typedef struct LCUI_TextViewRec_ {
7978
static struct LCUI_TextViewModule {
8079
int key_word_break;
8180
LinkedList list;
82-
LCUI_Mutex mutex;
8381
LCUI_WidgetPrototype prototype;
8482
} self;
8583

@@ -266,7 +264,6 @@ static void TextView_OnInit(LCUI_Widget w)
266264
TextLayer_SetUsingStyleTags(txt->layer, TRUE);
267265
Widget_BindEvent(w, "resize", TextView_OnResize, NULL, NULL);
268266
CSSFontStyle_Init(&txt->style);
269-
LCUIMutex_Init(&txt->mutex);
270267
txt->node.data = txt;
271268
txt->node.prev = txt->node.next = NULL;
272269
LinkedList_AppendNode(&self.list, &txt->node);
@@ -287,14 +284,12 @@ static void TextView_ClearTasks(LCUI_Widget w)
287284
static void TextView_OnDestroy(LCUI_Widget w)
288285
{
289286
LCUI_TextView txt = GetData(w);
287+
288+
LinkedList_Unlink(&self.list, &txt->node);
290289
CSSFontStyle_Destroy(&txt->style);
291290
TextLayer_Destroy(txt->layer);
292-
LCUIMutex_Unlock(&txt->mutex);
293291
TextView_ClearTasks(w);
294292
free(txt->content);
295-
LCUIMutex_Lock(&self.mutex);
296-
LinkedList_Unlink(&self.list, &txt->node);
297-
LCUIMutex_Unlock(&self.mutex);
298293
}
299294

300295
static void TextView_AutoSize(LCUI_Widget w, float *width, float *height)
@@ -357,14 +352,12 @@ static void TextView_OnTask(LCUI_Widget w)
357352
LinkedList_Init(&rects);
358353
i = TASK_SET_TEXT;
359354
if (txt->tasks[i].is_valid) {
360-
LCUIMutex_Lock(&txt->mutex);
361355
txt->tasks[i].is_valid = FALSE;
362356
TextLayer_SetTextW(txt->layer, txt->tasks[i].text, NULL);
363357
txt->tasks[TASK_UPDATE].is_valid = TRUE;
364358
txt->tasks[TASK_UPDATE_SIZE].is_valid = TRUE;
365359
free(txt->tasks[i].text);
366360
txt->tasks[i].text = NULL;
367-
LCUIMutex_Unlock(&txt->mutex);
368361
}
369362
i = TASK_SET_AUTOWRAP;
370363
if (txt->tasks[i].is_valid) {
@@ -483,15 +476,13 @@ int TextView_SetTextW(LCUI_Widget w, const wchar_t *text)
483476
}
484477
wcstrim(newtext, text, NULL);
485478
} while (0);
486-
LCUIMutex_Lock(&txt->mutex);
487479
if (txt->tasks[TASK_SET_TEXT].is_valid &&
488480
txt->tasks[TASK_SET_TEXT].text) {
489481
free(txt->tasks[TASK_SET_TEXT].text);
490482
}
491483
txt->tasks[TASK_SET_TEXT].is_valid = TRUE;
492484
txt->tasks[TASK_SET_TEXT].text = newtext;
493485
Widget_AddTask(w, LCUI_WTASK_USER);
494-
LCUIMutex_Unlock(&txt->mutex);
495486
return 0;
496487
}
497488

@@ -547,15 +538,13 @@ size_t LCUIWidget_RefreshTextView(void)
547538
LCUI_TextView txt;
548539
LinkedListNode *node;
549540

550-
LCUIMutex_Lock(&self.mutex);
551541
for (LinkedList_Each(node, &self.list)) {
552542
txt = node->data;
553543
if (txt->widget->state != LCUI_WSTATE_DELETED) {
554544
Widget_UpdateStyle(txt->widget, TRUE);
555545
}
556546
count += 1;
557547
}
558-
LCUIMutex_Unlock(&self.mutex);
559548
return count;
560549
}
561550

@@ -575,12 +564,10 @@ void LCUIWidget_AddTextView(void)
575564
self.prototype->setattr = TextView_OnParseAttr;
576565
self.prototype->runtask = TextView_OnTask;
577566
LCUI_AddCSSPropertyParser(&parser);
578-
LCUIMutex_Init(&self.mutex);
579567
LinkedList_Init(&self.list);
580568
}
581569

582570
void LCUIWidget_FreeTextView(void)
583571
{
584572
LinkedList_ClearData(&self.list, NULL);
585-
LCUIMutex_Destroy(&self.mutex);
586573
}

0 commit comments

Comments
 (0)