mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 04:00:28 +01:00
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>
This commit is contained in:
committed by
Damien George
parent
f36a5654a8
commit
289b2dd879
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user