Skip to content

Commit 0143320

Browse files
authored
perf(theme): optimize the order of function calls (lvgl#5971)
1 parent 1f37da2 commit 0143320

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

src/themes/default/lv_theme_default.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,9 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
727727
LV_UNUSED(th);
728728

729729
my_theme_t * theme = theme_def;
730+
lv_obj_t * parent = lv_obj_get_parent(obj);
730731

731-
if(lv_obj_get_parent(obj) == NULL) {
732+
if(parent == NULL) {
732733
lv_obj_add_style(obj, &theme->styles.scr, 0);
733734
lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR);
734735
lv_obj_add_style(obj, &theme->styles.scrollbar_scrolled, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
@@ -737,20 +738,19 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
737738

738739
if(lv_obj_check_type(obj, &lv_obj_class)) {
739740
#if LV_USE_TABVIEW
740-
lv_obj_t * parent = lv_obj_get_parent(obj);
741741
/*Tabview content area*/
742-
if(parent && lv_obj_check_type(parent, &lv_tabview_class) && lv_obj_get_index(obj) == 1) {
742+
if(lv_obj_check_type(parent, &lv_tabview_class) && lv_obj_get_child(parent, 1) == obj) {
743743
return;
744744
}
745745
/*Tabview button container*/
746-
else if(lv_obj_check_type(parent, &lv_tabview_class) && lv_obj_get_index(obj) == 0) {
746+
else if(lv_obj_check_type(parent, &lv_tabview_class) && lv_obj_get_child(parent, 0) == obj) {
747747
lv_obj_add_style(obj, &theme->styles.bg_color_white, 0);
748748
lv_obj_add_style(obj, &theme->styles.outline_primary, LV_STATE_FOCUS_KEY);
749749
lv_obj_add_style(obj, &theme->styles.tab_bg_focus, LV_STATE_FOCUS_KEY);
750750
return;
751751
}
752752
/*Tabview pages*/
753-
else if(parent && lv_obj_check_type(lv_obj_get_parent(parent), &lv_tabview_class)) {
753+
else if(lv_obj_check_type(lv_obj_get_parent(parent), &lv_tabview_class)) {
754754
lv_obj_add_style(obj, &theme->styles.pad_normal, 0);
755755
lv_obj_add_style(obj, &theme->styles.rotary_scroll, 0);
756756
lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR);
@@ -761,13 +761,13 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
761761

762762
#if LV_USE_WIN
763763
/*Header*/
764-
if(lv_obj_get_index(obj) == 0 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) {
764+
if(lv_obj_check_type(parent, &lv_win_class) && lv_obj_get_child(parent, 0) == obj) {
765765
lv_obj_add_style(obj, &theme->styles.bg_color_grey, 0);
766766
lv_obj_add_style(obj, &theme->styles.pad_tiny, 0);
767767
return;
768768
}
769769
/*Content*/
770-
else if(lv_obj_get_index(obj) == 1 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) {
770+
else if(lv_obj_check_type(parent, &lv_win_class) && lv_obj_get_child(parent, 1) == obj) {
771771
lv_obj_add_style(obj, &theme->styles.scr, 0);
772772
lv_obj_add_style(obj, &theme->styles.pad_normal, 0);
773773
lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR);
@@ -777,7 +777,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
777777
#endif
778778

779779
#if LV_USE_CALENDAR
780-
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_calendar_class)) {
780+
if(lv_obj_check_type(parent, &lv_calendar_class)) {
781781
/*No style*/
782782
return;
783783
}
@@ -791,9 +791,9 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
791791
else if(lv_obj_check_type(obj, &lv_button_class)) {
792792

793793
#if LV_USE_TABVIEW
794-
lv_obj_t * parent = lv_obj_get_parent(obj);
795-
if(parent && lv_obj_get_index(parent) == 0) { /*Tabview header*/
796-
if(lv_obj_check_type(lv_obj_get_parent(parent), &lv_tabview_class)) {
794+
lv_obj_t * tv = lv_obj_get_parent(parent); /*parent is the tabview header*/
795+
if(tv && lv_obj_get_child(tv, 0) == parent) { /*The button is on the tab view header*/
796+
if(lv_obj_check_type(tv, &lv_tabview_class)) {
797797
lv_obj_add_style(obj, &theme->styles.pressed, LV_STATE_PRESSED);
798798
lv_obj_add_style(obj, &theme->styles.bg_color_primary_muted, LV_STATE_CHECKED);
799799
lv_obj_add_style(obj, &theme->styles.tab_btn, LV_STATE_CHECKED);
@@ -818,8 +818,8 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
818818
lv_obj_add_style(obj, &theme->styles.disabled, LV_STATE_DISABLED);
819819

820820
#if LV_USE_MENU
821-
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_menu_sidebar_header_cont_class) ||
822-
lv_obj_check_type(lv_obj_get_parent(obj), &lv_menu_main_header_cont_class)) {
821+
if(lv_obj_check_type(parent, &lv_menu_sidebar_header_cont_class) ||
822+
lv_obj_check_type(parent, &lv_menu_main_header_cont_class)) {
823823
lv_obj_add_style(obj, &theme->styles.menu_header_btn, 0);
824824
lv_obj_add_style(obj, &theme->styles.menu_pressed, LV_STATE_PRESSED);
825825
}
@@ -837,7 +837,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
837837
else if(lv_obj_check_type(obj, &lv_buttonmatrix_class)) {
838838

839839
#if LV_USE_CALENDAR
840-
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_calendar_class)) {
840+
if(lv_obj_check_type(parent, &lv_calendar_class)) {
841841
lv_obj_add_style(obj, &theme->styles.calendar_btnm_bg, 0);
842842
lv_obj_add_style(obj, &theme->styles.outline_primary, LV_STATE_FOCUS_KEY);
843843
lv_obj_add_style(obj, &theme->styles.outline_secondary, LV_STATE_EDITED);
@@ -1152,7 +1152,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
11521152
return;
11531153
}
11541154

1155-
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_msgbox_class)) {
1155+
if(lv_obj_check_type(parent, &lv_msgbox_class)) {
11561156
lv_obj_add_style(obj, &theme->styles.pad_tiny, 0);
11571157
return;
11581158
}

src/themes/mono/lv_theme_mono.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,16 +233,16 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
233233
LV_UNUSED(th);
234234

235235
my_theme_t * theme = theme_def;
236+
lv_obj_t * parent = lv_obj_get_parent(obj);
236237

237-
if(lv_obj_get_parent(obj) == NULL) {
238+
if(parent == NULL) {
238239
lv_obj_add_style(obj, &theme->styles.scr, 0);
239240
lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR);
240241
return;
241242
}
242243

243244
if(lv_obj_check_type(obj, &lv_obj_class)) {
244245
#if LV_USE_TABVIEW
245-
lv_obj_t * parent = lv_obj_get_parent(obj);
246246
/*Tabview content area*/
247247
if(lv_obj_check_type(parent, &lv_tabview_class)) {
248248
return;
@@ -258,13 +258,13 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
258258

259259
#if LV_USE_WIN
260260
/*Header*/
261-
if(lv_obj_get_index(obj) == 0 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) {
261+
if(lv_obj_check_type(parent, &lv_win_class) && lv_obj_get_child(parent, 0) == 0) {
262262
lv_obj_add_style(obj, &theme->styles.card, 0);
263263
lv_obj_add_style(obj, &theme->styles.no_radius, 0);
264264
return;
265265
}
266266
/*Content*/
267-
else if(lv_obj_get_index(obj) == 1 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) {
267+
else if(lv_obj_check_type(parent, &lv_win_class) && lv_obj_get_child(parent, 1) == obj) {
268268
lv_obj_add_style(obj, &theme->styles.card, 0);
269269
lv_obj_add_style(obj, &theme->styles.no_radius, 0);
270270
lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR);
@@ -288,7 +288,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
288288
#if LV_USE_BUTTONMATRIX
289289
else if(lv_obj_check_type(obj, &lv_buttonmatrix_class)) {
290290
#if LV_USE_MSGBOX
291-
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_msgbox_class)) {
291+
if(lv_obj_check_type(parent, &lv_msgbox_class)) {
292292
lv_obj_add_style(obj, &theme->styles.pad_gap, 0);
293293
lv_obj_add_style(obj, &theme->styles.card, LV_PART_ITEMS);
294294
lv_obj_add_style(obj, &theme->styles.pr, LV_PART_ITEMS | LV_STATE_PRESSED);
@@ -299,7 +299,7 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
299299
}
300300
#endif
301301
#if LV_USE_TABVIEW
302-
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_tabview_class)) {
302+
if(lv_obj_check_type(parent, &lv_tabview_class)) {
303303
lv_obj_add_style(obj, &theme->styles.pad_gap, 0);
304304
lv_obj_add_style(obj, &theme->styles.card, LV_PART_ITEMS);
305305
lv_obj_add_style(obj, &theme->styles.pr, LV_PART_ITEMS | LV_STATE_PRESSED);

src/themes/simple/lv_theme_simple.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,16 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
206206
LV_UNUSED(th);
207207

208208
my_theme_t * theme = theme_def;
209+
lv_obj_t * parent = lv_obj_get_parent(obj);
209210

210-
if(lv_obj_get_parent(obj) == NULL) {
211+
if(parent == NULL) {
211212
lv_obj_add_style(obj, &theme->styles.scr, 0);
212213
lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR);
213214
return;
214215
}
215216

216217
if(lv_obj_check_type(obj, &lv_obj_class)) {
217218
#if LV_USE_TABVIEW
218-
lv_obj_t * parent = lv_obj_get_parent(obj);
219219
/*Tabview content area*/
220220
if(lv_obj_check_type(parent, &lv_tabview_class)) {
221221
lv_obj_add_style(obj, &theme->styles.scr, 0);
@@ -231,12 +231,12 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
231231

232232
#if LV_USE_WIN
233233
/*Header*/
234-
if(lv_obj_get_index(obj) == 0 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) {
234+
if(lv_obj_check_type(parent, &lv_win_class) && lv_obj_get_child(parent, 0) == obj) {
235235
lv_obj_add_style(obj, &theme->styles.light, 0);
236236
return;
237237
}
238238
/*Content*/
239-
else if(lv_obj_get_index(obj) == 1 && lv_obj_check_type(lv_obj_get_parent(obj), &lv_win_class)) {
239+
else if(lv_obj_check_type(parent, &lv_win_class) && lv_obj_get_child(parent, 1) == obj) {
240240
lv_obj_add_style(obj, &theme->styles.light, 0);
241241
lv_obj_add_style(obj, &theme->styles.scrollbar, LV_PART_SCROLLBAR);
242242
return;
@@ -254,13 +254,13 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj)
254254
#if LV_USE_BUTTONMATRIX
255255
else if(lv_obj_check_type(obj, &lv_buttonmatrix_class)) {
256256
#if LV_USE_MSGBOX
257-
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_msgbox_class)) {
257+
if(lv_obj_check_type(parent, &lv_msgbox_class)) {
258258
lv_obj_add_style(obj, &theme->styles.light, LV_PART_ITEMS);
259259
return;
260260
}
261261
#endif
262262
#if LV_USE_TABVIEW
263-
if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_tabview_class)) {
263+
if(lv_obj_check_type(parent, &lv_tabview_class)) {
264264
lv_obj_add_style(obj, &theme->styles.light, LV_PART_ITEMS);
265265
return;
266266
}

0 commit comments

Comments
 (0)