py: With obj repr "C", change raw str accessor from macro to function.
This saves around 1000 bytes (Thumb2 arch) because in repr "C" it is costly to check and extract a qstr. So making such check/extract a function instead of a macro saves lots of code space.
This commit is contained in:
parent
183edefddd
commit
04353cc85e
11
py/objstr.c
11
py/objstr.c
@ -2038,6 +2038,17 @@ const char *mp_obj_str_get_data(mp_obj_t self_in, mp_uint_t *len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
|
||||||
|
const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, mp_uint_t *len) {
|
||||||
|
if (MP_OBJ_IS_QSTR(self_in)) {
|
||||||
|
return qstr_data(MP_OBJ_QSTR_VALUE(self_in), len);
|
||||||
|
} else {
|
||||||
|
*len = ((mp_obj_str_t*)self_in)->len;
|
||||||
|
return ((mp_obj_str_t*)self_in)->data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/* str iterator */
|
/* str iterator */
|
||||||
|
|
||||||
|
@ -49,10 +49,16 @@ typedef struct _mp_obj_str_t {
|
|||||||
{ str_len = qstr_len(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_len = ((mp_obj_str_t*)str_obj_in)->len; }
|
{ str_len = qstr_len(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_len = ((mp_obj_str_t*)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
|
||||||
|
const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, mp_uint_t *len);
|
||||||
|
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \
|
||||||
|
mp_uint_t str_len; const byte *str_data = mp_obj_str_get_data_no_check(str_obj_in, &str_len);
|
||||||
|
#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; mp_uint_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
|
const byte *str_data; mp_uint_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
|
||||||
{ str_data = qstr_data(MP_OBJ_QSTR_VALUE(str_obj_in), &str_len); } \
|
{ str_data = qstr_data(MP_OBJ_QSTR_VALUE(str_obj_in), &str_len); } \
|
||||||
else { str_len = ((mp_obj_str_t*)str_obj_in)->len; str_data = ((mp_obj_str_t*)str_obj_in)->data; }
|
else { str_len = ((mp_obj_str_t*)str_obj_in)->len; str_data = ((mp_obj_str_t*)str_obj_in)->data; }
|
||||||
|
#endif
|
||||||
|
|
||||||
mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
mp_obj_t mp_obj_str_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
|
||||||
void mp_str_print_json(const mp_print_t *print, const byte *str_data, mp_uint_t str_len);
|
void mp_str_print_json(const mp_print_t *print, const byte *str_data, mp_uint_t str_len);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user