From b7fe2a0bf92b25bc49c157e7f03f0dbce32bf5a5 Mon Sep 17 00:00:00 2001 From: Pisit Sawangvonganan Date: Wed, 6 Nov 2024 14:11:13 +0700 Subject: [PATCH] fb: cfb: avoid multiple `strlen` calls in `draw_text` Added `len` to store the result of `strlen(str)` to avoid multiple calls to `strlen` in the `for-loop`. Signed-off-by: Pisit Sawangvonganan --- subsys/fb/cfb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/subsys/fb/cfb.c b/subsys/fb/cfb.c index 7ba0882c90b..803d12d99a3 100644 --- a/subsys/fb/cfb.c +++ b/subsys/fb/cfb.c @@ -278,7 +278,9 @@ static int draw_text(const struct device *dev, const char *const str, int16_t x, } if ((fb->screen_info & SCREEN_INFO_MONO_VTILED)) { - for (size_t i = 0; i < strlen(str); i++) { + const size_t len = strlen(str); + + for (size_t i = 0; i < len; i++) { if ((x + fptr->width > fb->x_res) && wrap) { x = 0U; y += fptr->height;