py/objstr: Reformat str access macros to make them readable.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
7d91a9bf5b
commit
b5986784e4
30
py/objstr.h
30
py/objstr.h
@ -41,24 +41,38 @@ typedef struct _mp_obj_str_t {
|
|||||||
// use this macro to extract the string hash
|
// use this macro to extract the string hash
|
||||||
// warning: the hash can be 0, meaning invalid, and must then be explicitly computed from the data
|
// warning: the hash can be 0, meaning invalid, and must then be explicitly computed from the data
|
||||||
#define GET_STR_HASH(str_obj_in, str_hash) \
|
#define GET_STR_HASH(str_obj_in, str_hash) \
|
||||||
mp_uint_t str_hash; if (mp_obj_is_qstr(str_obj_in)) \
|
mp_uint_t str_hash; \
|
||||||
{ str_hash = qstr_hash(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_hash = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->hash; }
|
if (mp_obj_is_qstr(str_obj_in)) { \
|
||||||
|
str_hash = qstr_hash(MP_OBJ_QSTR_VALUE(str_obj_in)); \
|
||||||
|
} else { \
|
||||||
|
str_hash = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->hash; \
|
||||||
|
}
|
||||||
|
|
||||||
// use this macro to extract the string length
|
// use this macro to extract the string length
|
||||||
#define GET_STR_LEN(str_obj_in, str_len) \
|
#define GET_STR_LEN(str_obj_in, str_len) \
|
||||||
size_t str_len; if (mp_obj_is_qstr(str_obj_in)) \
|
size_t str_len; \
|
||||||
{ str_len = qstr_len(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_len = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->len; }
|
if (mp_obj_is_qstr(str_obj_in)) { \
|
||||||
|
str_len = qstr_len(MP_OBJ_QSTR_VALUE(str_obj_in)); \
|
||||||
|
} else { \
|
||||||
|
str_len = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->len; \
|
||||||
|
}
|
||||||
|
|
||||||
// use this macro to extract the string data and length
|
// use this macro to extract the string data and length
|
||||||
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
|
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
|
||||||
const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len);
|
const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len);
|
||||||
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \
|
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \
|
||||||
size_t str_len; const byte *str_data = mp_obj_str_get_data_no_check(str_obj_in, &str_len);
|
size_t str_len; \
|
||||||
|
const byte *str_data = mp_obj_str_get_data_no_check(str_obj_in, &str_len);
|
||||||
#else
|
#else
|
||||||
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \
|
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \
|
||||||
const byte *str_data; size_t str_len; if (mp_obj_is_qstr(str_obj_in)) \
|
const byte *str_data; \
|
||||||
{ str_data = qstr_data(MP_OBJ_QSTR_VALUE(str_obj_in), &str_len); } \
|
size_t str_len; \
|
||||||
else { str_len = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->len; str_data = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->data; }
|
if (mp_obj_is_qstr(str_obj_in)) { \
|
||||||
|
str_data = qstr_data(MP_OBJ_QSTR_VALUE(str_obj_in), &str_len); \
|
||||||
|
} else { \
|
||||||
|
str_len = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->len; \
|
||||||
|
str_data = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->data; \
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||||
|
Loading…
Reference in New Issue
Block a user