Skip to content

Commit

Permalink
py/objstr: Don't use inline GET_STR_DATA_LEN for object-repr D.
Browse files Browse the repository at this point in the history
Changing to use the helper function mp_obj_str_get_data_no_check() reduces
code size of nan-boxing builds by about 1000 bytes.
  • Loading branch information
dpgeorge committed Dec 27, 2019
1 parent e83ab73 commit 4c0176d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions py/objstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2153,13 +2153,13 @@ const char *mp_obj_str_get_data(mp_obj_t self_in, size_t *len) {
}
}

#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
#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) {
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;
*len = ((mp_obj_str_t*)MP_OBJ_TO_PTR(self_in))->len;
return ((mp_obj_str_t*)MP_OBJ_TO_PTR(self_in))->data;
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion py/objstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ typedef struct _mp_obj_str_t {
{ 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
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
#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);
#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);
Expand Down

0 comments on commit 4c0176d

Please sign in to comment.