Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(draw): optimize lv_draw_label() with text_length for text_local #7673

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

niklasf
Copy link
Contributor

@niklasf niklasf commented Jan 28, 2025

Introduce lv_strnlen() and lv_strndup(), mirroring the standard C library.

When using lv_draw_label() with text_length and text_local to draw a slice of a larger string, copy only the required part.

Depending on the size of the larger string, this can be anywhere from insignificant to a major improvement.

I think the additional standard library functions are useful, but it would also be possible to manually malloc and copy diretcly in the draw function.

@niklasf niklasf force-pushed the perf/draw-label-slice branch 3 times, most recently from 351cecd to b9da0c9 Compare January 28, 2025 18:44
Copy link
Member

@uLipe uLipe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

I just have a couple of nits.

src/stdlib/builtin/lv_string_builtin.c Show resolved Hide resolved
src/stdlib/builtin/lv_string_builtin.c Show resolved Hide resolved
src/stdlib/clib/lv_string_clib.c Show resolved Hide resolved
liamHowatt
liamHowatt previously approved these changes Jan 31, 2025
Introduce lv_strnlen() and lv_strndup(), mirroring the standard C
library.

When using lv_draw_label() with text_length and text_local to draw a
slice of a larger string, copy only the required part.
@liamHowatt
Copy link
Member

@uLipe I think we should try to make any functions that mimic C library functions as compliant as possible. i.e., the caller handles failures instead of crashing in str(n)dup, and invalid input is UB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants