py/objstr: Remove "make_qstr_if_not_already" arg from mp_obj_new_str.

This patch simplifies the str creation API to favour the common case of
creating a str object that is not forced to be interned.  To force
interning of a new str the new mp_obj_new_str_via_qstr function is added,
and should only be used if warranted.

Apart from simplifying the mp_obj_new_str function (and making it have the
same signature as mp_obj_new_bytes), this patch also reduces code size by a
bit (-16 bytes for bare-arm and roughly -40 bytes on the bare-metal archs).
This commit is contained in:
Damien George
2017-11-16 13:17:51 +11:00
parent 6bc55b657b
commit 4601759bf5
24 changed files with 55 additions and 54 deletions

View File

@@ -159,12 +159,12 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) {
} else {
mp_raise_ValueError("chr() arg not in range(0x110000)");
}
return mp_obj_new_str(str, len, true);
return mp_obj_new_str_via_qstr(str, len);
#else
mp_int_t ord = mp_obj_get_int(o_in);
if (0 <= ord && ord <= 0xff) {
char str[1] = {ord};
return mp_obj_new_str(str, 1, true);
return mp_obj_new_str_via_qstr(str, 1);
} else {
mp_raise_ValueError("chr() arg not in range(256)");
}