From 6fa79e945f36a39ee169edb70570b4c2fb20a104 Mon Sep 17 00:00:00 2001 From: Neo Xu Date: Wed, 24 Jan 2024 20:55:04 +0800 Subject: [PATCH] chore(array): use array_front and use it like an array (#5448) Signed-off-by: Xu Xingliang --- src/draw/lv_draw_vector.c | 9 +++++---- src/draw/sw/lv_draw_sw_vector.c | 9 +++++---- src/draw/vg_lite/lv_draw_vg_lite_vector.c | 7 ++++--- src/draw/vg_lite/lv_vg_lite_utils.c | 4 ++-- src/misc/lv_event.c | 5 +++-- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/draw/lv_draw_vector.c b/src/draw/lv_draw_vector.c index dfa3e88cb..400e09f4d 100644 --- a/src/draw/lv_draw_vector.c +++ b/src/draw/lv_draw_vector.c @@ -206,9 +206,10 @@ void lv_matrix_transform_point(const lv_matrix_t * matrix, lv_fpoint_t * point) void lv_matrix_transform_path(const lv_matrix_t * matrix, lv_vector_path_t * path) { - for(uint32_t i = 0; i < path->points.size; i++) { - lv_fpoint_t * pt = lv_array_at(&path->points, i); - lv_matrix_transform_point(matrix, pt); + lv_fpoint_t * pt = lv_array_front(&path->points); + uint32_t size = lv_array_size(&path->points); + for(uint32_t i = 0; i < size; i++) { + lv_matrix_transform_point(matrix, &pt[i]); } } @@ -315,7 +316,7 @@ void lv_vector_path_close(lv_vector_path_t * path) void lv_vector_path_get_bounding(const lv_vector_path_t * path, lv_area_t * area) { uint32_t len = lv_array_size(&path->points); - lv_fpoint_t * p = lv_array_at(&path->points, 0); + lv_fpoint_t * p = lv_array_front(&path->points); float x1 = p[0].x; float x2 = p[0].x; float y1 = p[0].y; diff --git a/src/draw/sw/lv_draw_sw_vector.c b/src/draw/sw/lv_draw_sw_vector.c index fc6f260d7..bfcca0910 100644 --- a/src/draw/sw/lv_draw_sw_vector.c +++ b/src/draw/sw/lv_draw_sw_vector.c @@ -86,9 +86,10 @@ static void _set_paint_matrix(Tvg_Paint * obj, const Tvg_Matrix * m) static void _set_paint_shape(Tvg_Paint * obj, const lv_vector_path_t * p) { uint32_t pidx = 0; - for(uint32_t i = 0; i < p->ops.size; i++) { - lv_vector_path_op_t * op = lv_array_at(&p->ops, i); - switch(*op) { + lv_vector_path_op_t * op = lv_array_front(&p->ops); + uint32_t size = lv_array_size(&p->ops); + for(uint32_t i = 0; i < size; i++) { + switch(op[i]) { case LV_VECTOR_PATH_OP_MOVE_TO: { lv_fpoint_t * pt = lv_array_at(&p->points, pidx); tvg_shape_move_to(obj, pt->x, pt->y); @@ -243,7 +244,7 @@ static void _set_paint_stroke(Tvg_Paint * obj, const lv_vector_stroke_dsc_t * ds tvg_shape_set_stroke_join(obj, _lv_stroke_join_to_tvg(dsc->join)); if(!lv_array_is_empty(&dsc->dash_pattern)) { - float * dash_array = lv_array_at(&dsc->dash_pattern, 0); + float * dash_array = lv_array_front(&dsc->dash_pattern); tvg_shape_set_stroke_dash(obj, dash_array, dsc->dash_pattern.size); } } diff --git a/src/draw/vg_lite/lv_draw_vg_lite_vector.c b/src/draw/vg_lite/lv_draw_vg_lite_vector.c index f8183a8a1..39dbd55a0 100644 --- a/src/draw/vg_lite/lv_draw_vg_lite_vector.c +++ b/src/draw/vg_lite/lv_draw_vg_lite_vector.c @@ -249,9 +249,10 @@ static void lv_path_to_vg(lv_vg_lite_path_t * dest, const lv_vector_path_t * src } while(0) uint32_t pidx = 0; - for(uint32_t i = 0; i < src->ops.size; i++) { - lv_vector_path_op_t * op = lv_array_at(&src->ops, i); - switch(*op) { + lv_vector_path_op_t * op = lv_array_front(&src->ops); + uint32_t size = lv_array_size(&src->ops); + for(uint32_t i = 0; i < size; i++) { + switch(op[i]) { case LV_VECTOR_PATH_OP_MOVE_TO: { const lv_fpoint_t * pt = lv_array_at(&src->points, pidx); CMP_BOUNDS(pt); diff --git a/src/draw/vg_lite/lv_vg_lite_utils.c b/src/draw/vg_lite/lv_vg_lite_utils.c index 802daf282..bf3ee9840 100644 --- a/src/draw/vg_lite/lv_vg_lite_utils.c +++ b/src/draw/vg_lite/lv_vg_lite_utils.c @@ -609,9 +609,9 @@ void lv_vg_lite_clear_image_decoder_dsc(lv_draw_unit_t * draw_unit) } /* Close all pending image decoder dsc */ + lv_image_decoder_dsc_t * img_dsc = lv_array_front(arr); for(uint32_t i = 0; i < size; i++) { - lv_image_decoder_dsc_t * img_dsc = lv_array_at(arr, i); - lv_image_decoder_close(img_dsc); + lv_image_decoder_close(&img_dsc[i]); } lv_array_clear(arr); } diff --git a/src/misc/lv_event.c b/src/misc/lv_event.c index 7fbd94510..af9f4906a 100644 --- a/src/misc/lv_event.c +++ b/src/misc/lv_event.c @@ -65,8 +65,9 @@ lv_result_t lv_event_send(lv_event_list_t * list, lv_event_t * e, bool preproces if(list == NULL) return LV_RESULT_OK; uint32_t i = 0; - lv_event_dsc_t * dsc = lv_array_at(list, 0); - for(i = 0; i < lv_array_size(list); i++) { + lv_event_dsc_t * dsc = lv_array_front(list); + uint32_t size = lv_array_size(list); + for(i = 0; i < size; i++) { if(dsc[i].cb == NULL) continue; bool is_preprocessed = (dsc[i].filter & LV_EVENT_PREPROCESS) != 0; if(is_preprocessed != preprocess) continue;