Skip to content

Commit f611936

Browse files
committed
perf(gui): save classes and status with strlist
1 parent c60c26c commit f611936

15 files changed

Lines changed: 373 additions & 267 deletions

File tree

build/windows/LCUI/LCUI.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
<ClInclude Include="..\..\..\include\LCUI\util\rbtree.h" />
340340
<ClInclude Include="..\..\..\include\LCUI\util\rect.h" />
341341
<ClInclude Include="..\..\..\include\LCUI\util\string.h" />
342+
<ClInclude Include="..\..\..\include\LCUI\util\strlist.h" />
342343
<ClInclude Include="..\..\..\include\LCUI\util\strpool.h" />
343344
<ClInclude Include="..\..\..\include\LCUI\util\task.h" />
344345
<ClInclude Include="..\..\..\include\LCUI\util\time.h" />
@@ -408,6 +409,7 @@
408409
<ClCompile Include="..\..\..\src\platform\windows\windows_keyboard.c" />
409410
<ClCompile Include="..\..\..\src\platform\windows\windows_mouse.c" />
410411
<ClCompile Include="..\..\..\src\util\charset.c" />
412+
<ClCompile Include="..\..\..\src\util\strlist.c" />
411413
<ClCompile Include="..\..\..\src\util\strpool.c" />
412414
<ClCompile Include="..\..\..\src\util\task.c" />
413415
<ClCompile Include="..\..\..\src\util\uri.c" />

build/windows/LCUI/LCUI.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,9 @@
300300
<ClInclude Include="..\..\..\include\LCUI\util\strpool.h">
301301
<Filter>头文件\LCUI\util</Filter>
302302
</ClInclude>
303+
<ClInclude Include="..\..\..\include\LCUI\util\strlist.h">
304+
<Filter>头文件\LCUI\util</Filter>
305+
</ClInclude>
303306
</ItemGroup>
304307
<ItemGroup>
305308
<ClCompile Include="..\..\..\src\draw\border.c">
@@ -533,6 +536,9 @@
533536
<ClCompile Include="..\..\..\src\util\strpool.c">
534537
<Filter>源文件\util</Filter>
535538
</ClCompile>
539+
<ClCompile Include="..\..\..\src\util\strlist.c">
540+
<Filter>源文件\util</Filter>
541+
</ClCompile>
536542
</ItemGroup>
537543
<ItemGroup>
538544
<Text Include="..\..\..\LICENSE.TXT" />

include/LCUI/gui/widget_base.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#ifndef LCUI_WIDGET_BASE_H
3232
#define LCUI_WIDGET_BASE_H
3333

34+
#include <LCUI/util/strlist.h>
3435
#include <LCUI/gui/css_library.h>
3536

3637
LCUI_BEGIN_HEADER
@@ -178,8 +179,8 @@ typedef struct LCUI_WidgetRec_ {
178179
size_t index; /**< 部件索引位置 */
179180
char *id; /**< ID */
180181
char *type; /**< 类型 */
181-
char **classes; /**< 类列表 */
182-
char **status; /**< 状态列表 */
182+
strlist_t classes; /**< 类列表 */
183+
strlist_t status; /**< 状态列表 */
183184
wchar_t *title; /**< 标题 */
184185
LCUI_Rect2F padding; /**< 内边距框 */
185186
LCUI_Rect2F margin; /**< 外边距框 */

include/LCUI/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <LCUI/util/steptimer.h>
4141
#include <LCUI/util/string.h>
4242
#include <LCUI/util/strpool.h>
43+
#include <LCUI/util/strlist.h>
4344
#include <LCUI/util/parse.h>
4445
#include <LCUI/util/event.h>
4546
#include <LCUI/util/logger.h>

include/LCUI/util/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ AUTOMAKE_OPTIONS=foreign
33
# Headers to install
44
pkginclude_HEADERS = dict.h rbtree.h linkedlist.h string.h rect.h dirent.h \
55
time.h event.h steptimer.h parse.h logger.h math.h task.h uri.h charset.h \
6-
strpool.h
6+
strpool.h strlist.h
77
pkgincludedir=$(prefix)/include/LCUI/util

include/LCUI/util/string.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -87,39 +87,6 @@ LCUI_API int cmdsplit(const char *cmd, char ***outargv);
8787
*/
8888
LCUI_API int strsplit(const char *instr, const char *sep, char ***outstrs);
8989

90-
/**
91-
* 向字符串组添加字符串
92-
* @param[in][out] strlist 字符串组
93-
* @param[in] str 字符串
94-
*/
95-
LCUI_API int strsadd(char ***strlist, const char *str);
96-
97-
/**
98-
* 判断字符串组中是否包含指定字符串
99-
* @param[in][out] strlist 字符串组
100-
* @param[in] str 字符串
101-
* @returns 如果包含则返回 1, 否则返回 0
102-
*/
103-
LCUI_API int strshas(char **strlist, const char *str);
104-
105-
/**
106-
* 从字符串组中删除指定字符串
107-
* @param[in][out] strlist 字符串组
108-
* @param[in] str 字符串
109-
* @returns 如果删除成功则返回 1, 否则返回 0
110-
*/
111-
LCUI_API int strsdel(char ***strlist, const char *str);
112-
113-
/**
114-
* 向已排序的字符串组添加字符串
115-
* @param[in][out] strlist 字符串组
116-
* @param[in] str 字符串
117-
*/
118-
LCUI_API int sortedstrsadd(char ***strlist, const char *str);
119-
120-
/** 释放字符串组 */
121-
LCUI_API void freestrs(char **strs);
122-
12390
LCUI_END_HEADER
12491

12592
#endif

include/LCUI/util/strlist.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* strlist.h -- string list
3+
*
4+
* Copyright (c) 2019, Liu chao <lc-soft@live.cn> All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* * Neither the name of LCUI nor the names of its contributors may be used
15+
* to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#ifndef LCUI_UTIL_STRLIST_H
32+
#define LCUI_UTIL_STRLIST_H
33+
34+
typedef char** strlist_t;
35+
36+
LCUI_API int sortedstrlist_add(strlist_t *strlist, const char *str);
37+
38+
LCUI_API int strlist_add_one(strlist_t *strlist, const char *str);
39+
40+
LCUI_API int strlist_remove_one(strlist_t *strlist, const char *str);
41+
42+
/**
43+
* 向字符串组添加字符串
44+
* @param[in][out] strlist 字符串组
45+
* @param[in] str 字符串
46+
*/
47+
LCUI_API int strlist_add(strlist_t *strlist, const char *str);
48+
49+
/**
50+
* 判断字符串组中是否包含指定字符串
51+
* @param[in][out] strlist 字符串组
52+
* @param[in] str 字符串
53+
* @returns 如果包含则返回 1, 否则返回 0
54+
*/
55+
LCUI_API int strlist_has(strlist_t strlist, const char *str);
56+
57+
/**
58+
* 从字符串组中移除指定字符串
59+
* @param[in][out] strlist 字符串组
60+
* @param[in] str 字符串
61+
* @returns 如果删除成功则返回 1, 否则返回 0
62+
*/
63+
LCUI_API int strlist_remove(strlist_t *strlist, const char *str);
64+
65+
/**
66+
* 向已排序的字符串组添加字符串
67+
* @param[in][out] strlist 字符串组
68+
* @param[in] str 字符串
69+
*/
70+
LCUI_API int sortedstrlist_add(strlist_t *strlist, const char *str);
71+
72+
/** 释放字符串组 */
73+
LCUI_API void strlist_free(strlist_t strs);
74+
75+
#endif

src/gui/css_library.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* css_library.c -- CSS library operation module.
33
*
44
* Copyright (c) 2018, Liu chao <lc-soft@live.cn> All rights reserved.
@@ -367,12 +367,12 @@ static void SelectorNode_Copy(LCUI_SelectorNode dst, LCUI_SelectorNode src)
367367
dst->fullname = src->fullname ? strdup2(src->fullname) : NULL;
368368
if (src->classes) {
369369
for (i = 0; src->classes[i]; ++i) {
370-
sortedstrsadd(&dst->classes, src->classes[i]);
370+
sortedstrlist_add(&dst->classes, src->classes[i]);
371371
}
372372
}
373373
if (src->status) {
374374
for (i = 0; src->status[i]; ++i) {
375-
sortedstrsadd(&dst->status, src->status[i]);
375+
sortedstrlist_add(&dst->status, src->status[i]);
376376
}
377377
}
378378
}
@@ -388,11 +388,11 @@ void SelectorNode_Delete(LCUI_SelectorNode node)
388388
node->id = NULL;
389389
}
390390
if (node->classes) {
391-
freestrs(node->classes);
391+
strlist_free(node->classes);
392392
node->classes = NULL;
393393
}
394394
if (node->status) {
395-
freestrs(node->status);
395+
strlist_free(node->status);
396396
node->status = NULL;
397397
}
398398
if (node->fullname) {
@@ -740,12 +740,12 @@ static int SelectorNode_Save(LCUI_SelectorNode node, const char *name, int len,
740740
node->type = str;
741741
return TYPE_RANK;
742742
case ':':
743-
if (sortedstrsadd(&node->status, name) == 0) {
743+
if (sortedstrlist_add(&node->status, name) == 0) {
744744
return PCLASS_RANK;
745745
}
746746
break;
747747
case '.':
748-
if (sortedstrsadd(&node->classes, name) == 0) {
748+
if (sortedstrlist_add(&node->classes, name) == 0) {
749749
return CLASS_RANK;
750750
}
751751
break;

src/gui/widget_class.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636

3737
int Widget_AddClass(LCUI_Widget w, const char *class_name)
3838
{
39-
if (strshas(w->classes, class_name)) {
39+
if (strlist_has(w->classes, class_name)) {
4040
return 1;
4141
}
42-
if (strsadd(&w->classes, class_name) <= 0) {
42+
if (strlist_add(&w->classes, class_name) <= 0) {
4343
return 0;
4444
}
4545
Widget_HandleChildrenStyleChange(w, 0, class_name);
@@ -49,17 +49,17 @@ int Widget_AddClass(LCUI_Widget w, const char *class_name)
4949

5050
LCUI_BOOL Widget_HasClass(LCUI_Widget w, const char *class_name)
5151
{
52-
if (strshas(w->classes, class_name)) {
52+
if (strlist_has(w->classes, class_name)) {
5353
return TRUE;
5454
}
5555
return FALSE;
5656
}
5757

5858
int Widget_RemoveClass(LCUI_Widget w, const char *class_name)
5959
{
60-
if (strshas(w->classes, class_name)) {
60+
if (strlist_has(w->classes, class_name)) {
6161
Widget_HandleChildrenStyleChange(w, 0, class_name);
62-
strsdel(&w->classes, class_name);
62+
strlist_remove(&w->classes, class_name);
6363
Widget_UpdateStyle(w, TRUE);
6464
return 1;
6565
}
@@ -69,7 +69,7 @@ int Widget_RemoveClass(LCUI_Widget w, const char *class_name)
6969
void Widget_DestroyClasses(LCUI_Widget w)
7070
{
7171
if (w->classes) {
72-
freestrs(w->classes);
72+
strlist_free(w->classes);
7373
}
7474
w->classes = NULL;
7575
}

src/gui/widget_status.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737

3838
int Widget_AddStatus(LCUI_Widget w, const char *status_name)
3939
{
40-
if (strshas(w->status, status_name)) {
40+
if (strlist_has(w->status, status_name)) {
4141
return 0;
4242
}
43-
if (strsadd(&w->status, status_name) <= 0) {
43+
if (strlist_add(&w->status, status_name) <= 0) {
4444
return 0;
4545
}
4646
Widget_HandleChildrenStyleChange(w, 1, status_name);
@@ -50,17 +50,17 @@ int Widget_AddStatus(LCUI_Widget w, const char *status_name)
5050

5151
LCUI_BOOL Widget_HasStatus(LCUI_Widget w, const char *status_name)
5252
{
53-
if (strshas(w->status, status_name)) {
53+
if (strlist_has(w->status, status_name)) {
5454
return TRUE;
5555
}
5656
return FALSE;
5757
}
5858

5959
int Widget_RemoveStatus(LCUI_Widget w, const char *status_name)
6060
{
61-
if (strshas(w->status, status_name)) {
61+
if (strlist_has(w->status, status_name)) {
6262
Widget_HandleChildrenStyleChange(w, 1, status_name);
63-
strsdel(&w->status, status_name);
63+
strlist_remove(&w->status, status_name);
6464
Widget_UpdateStyle(w, TRUE);
6565
return 1;
6666
}
@@ -102,7 +102,7 @@ void Widget_SetDisabled(LCUI_Widget w, LCUI_BOOL disabled)
102102
void Widget_DestroyStatus(LCUI_Widget w)
103103
{
104104
if (w->status) {
105-
freestrs(w->status);
105+
strlist_free(w->status);
106106
}
107107
w->status = NULL;
108108
}

0 commit comments

Comments
 (0)