py/objstr: Split mp_obj_str_from_vstr into bytes/str versions.

Previously the desired output type was specified.  Now make the type part
of the function name.  Because this function is used in a few places this
saves code size due to smaller call-site.

This makes `mp_obj_new_str_type_from_vstr` a private function of objstr.c
(which is almost the only place where the output type isn't a compile-time
constant).

This saves ~140 bytes on PYBV11.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared
2022-08-22 17:08:05 +10:00
committed by Damien George
parent 09879f99ca
commit 8a0ee5a5c0
37 changed files with 102 additions and 73 deletions

View File

@@ -372,7 +372,11 @@ STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) {
// Add post-match string
vstr_add_strn(&vstr_return, subj.begin, subj.end - subj.begin);
return mp_obj_new_str_from_vstr(mp_obj_get_type(where), &vstr_return);
if (mp_obj_get_type(where) == &mp_type_str) {
return mp_obj_new_str_from_vstr(&vstr_return);
} else {
return mp_obj_new_bytes_from_vstr(&vstr_return);
}
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_sub_obj, 3, 5, re_sub_helper);