From bdef86faf2665929a5113e2575e8b30c26843757 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 27 Feb 2021 20:37:57 +0100 Subject: [PATCH] feat(style): add lv_style_get_prop_inlined and use it in the core main object style getter --- src/lv_core/lv_obj.c | 2 +- src/lv_misc/lv_style.c | 21 +-------------------- src/lv_misc/lv_style.h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index 97df1d4cf..4601d1602 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -979,7 +979,7 @@ static void lv_obj_set_state(lv_obj_t * obj, lv_state_t new_state) if(obj_style->is_trans) continue; lv_style_value_t v; - if(lv_style_get_prop(obj_style->style, LV_STYLE_TRANSITION, &v) == false) continue; + if(lv_style_get_prop_inlined(obj_style->style, LV_STYLE_TRANSITION, &v) == false) continue; const lv_style_transition_dsc_t * tr = v.ptr; /*Add the props t the set is not added yet or added but with smaller weight*/ diff --git a/src/lv_misc/lv_style.c b/src/lv_misc/lv_style.c index 9161578f2..827c7cc4c 100644 --- a/src/lv_misc/lv_style.c +++ b/src/lv_misc/lv_style.c @@ -184,26 +184,7 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) { - if(style->prop_cnt == 0) return false; - - if(style->allocated) { - uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t); - uint16_t * props = (uint16_t *) tmp; - uint32_t i; - for(i = 0; i < style->prop_cnt; i++) { - if(props[i] == prop) { - lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props; - *value = values[i]; - return true; - } - } - } else { - if(style->prop1 == prop) { - *value = style->v_p.value1; - return true; - } - } - return false; + return lv_style_get_prop_inlined(style, prop, value); } void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t * props, const lv_anim_path_t * path, uint32_t time, uint32_t delay) diff --git a/src/lv_misc/lv_style.h b/src/lv_misc/lv_style.h index e12e37da0..063464907 100644 --- a/src/lv_misc/lv_style.h +++ b/src/lv_misc/lv_style.h @@ -326,6 +326,42 @@ void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_ * @note For performance reasons there are no sanity check on `style` */ bool lv_style_get_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value); + + +/** + * Get the value of a property + * @param style: pointer to a style + * @param prop: the ID of a property + * @param value: pointer to a `lv_style_value_t` variable to store the value + * @return false: the property wsn't found in the style (`value` is unchanged) + * true: the property was fond, and `value` is set accordingly + * @note For performance reasons there are no sanity check on `style` + * @note This function is the same as ::lv_style_get_prop but inlined. Use it only on performance critical places + */ +static inline bool lv_style_get_prop_inlined(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value) +{ + if(style->prop_cnt == 0) return false; + + if(style->allocated) { + uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t); + uint16_t * props = (uint16_t *) tmp; + uint32_t i; + for(i = 0; i < style->prop_cnt; i++) { + if(props[i] == prop) { + lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props; + *value = values[i]; + return true; + } + } + } else { + if(style->prop1 == prop) { + *value = style->v_p.value1; + return true; + } + } + return false; +} + /** * Initialize a transition descriptor. * @param tr: pointer to a transition descriptor to initialize