diff options
author | Jon Foster <jon@jon-foster.co.uk> | 2024-04-01 19:19:29 +0100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2024-07-04 15:52:47 +1000 |
commit | 289b2dd87960a4cdf019013cecd489f0d0cabc26 (patch) | |
tree | 647081dc2a33d0444c3b2f95f3d65ed3d531b99e /py/objstr.c | |
parent | f36a5654a87838e68fb313272098777f76a94865 (diff) |
py/objstr: Add new mp_obj_new_str_from_cstr() helper function.
There were lots of places where this pattern was duplicated, to convert a
standard C string to a MicroPython string:
x = mp_obj_new_str(s, strlen(s));
This commit provides a simpler method that removes this code duplication:
x = mp_obj_new_str_from_cstr(s);
This gives clearer, and probably smaller, code.
Signed-off-by: Jon Foster <jon@jon-foster.co.uk>
Diffstat (limited to 'py/objstr.c')
-rw-r--r-- | py/objstr.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index c7e4ebf53..346a6259f 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -2308,6 +2308,10 @@ mp_obj_t mp_obj_new_str(const char *data, size_t len) { } } +mp_obj_t mp_obj_new_str_from_cstr(const char *str) { + return mp_obj_new_str(str, strlen(str)); +} + mp_obj_t mp_obj_str_intern(mp_obj_t str) { GET_STR_DATA_LEN(str, data, len); return mp_obj_new_str_via_qstr((const char *)data, len); |