mirror of
https://github.com/micropython/micropython.git
synced 2026-01-06 20:20:14 +01:00
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:
@@ -885,7 +885,7 @@ STATIC mp_obj_t wlan_scan(mp_obj_t self_in) {
|
||||
}
|
||||
|
||||
mp_obj_t tuple[5];
|
||||
tuple[0] = mp_obj_new_str((const char *)wlanEntry.ssid, wlanEntry.ssid_len, false);
|
||||
tuple[0] = mp_obj_new_str((const char *)wlanEntry.ssid, wlanEntry.ssid_len);
|
||||
tuple[1] = mp_obj_new_bytes((const byte *)wlanEntry.bssid, SL_BSSID_LENGTH);
|
||||
// 'normalize' the security type
|
||||
if (wlanEntry.sec_type > 2) {
|
||||
@@ -1075,7 +1075,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mode_obj, 1, 2, wlan_mode);
|
||||
STATIC mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_str((const char *)self->ssid, strlen((const char *)self->ssid), false);
|
||||
return mp_obj_new_str((const char *)self->ssid, strlen((const char *)self->ssid));
|
||||
} else {
|
||||
size_t len;
|
||||
const char *ssid = mp_obj_str_get_data(args[1], &len);
|
||||
@@ -1095,7 +1095,7 @@ STATIC mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) {
|
||||
} else {
|
||||
mp_obj_t security[2];
|
||||
security[0] = mp_obj_new_int(self->auth);
|
||||
security[1] = mp_obj_new_str((const char *)self->key, strlen((const char *)self->key), false);
|
||||
security[1] = mp_obj_new_str((const char *)self->key, strlen((const char *)self->key));
|
||||
return mp_obj_new_tuple(2, security);
|
||||
}
|
||||
} else {
|
||||
@@ -1199,7 +1199,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
|
||||
// mp_obj_t connections = mp_obj_new_list(0, NULL);
|
||||
//
|
||||
// if (wlan_is_connected()) {
|
||||
// device[0] = mp_obj_new_str((const char *)wlan_obj.ssid_o, strlen((const char *)wlan_obj.ssid_o), false);
|
||||
// device[0] = mp_obj_new_str((const char *)wlan_obj.ssid_o, strlen((const char *)wlan_obj.ssid_o));
|
||||
// device[1] = mp_obj_new_bytes((const byte *)wlan_obj.bssid, SL_BSSID_LENGTH);
|
||||
// // add the device to the list
|
||||
// mp_obj_list_append(connections, mp_obj_new_tuple(MP_ARRAY_SIZE(device), device));
|
||||
@@ -1232,7 +1232,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
|
||||
// if (sl_NetAppGet(SL_NET_APP_DEVICE_CONFIG_ID, NETAPP_SET_GET_DEV_CONF_OPT_DEVICE_URN, &len, (uint8_t *)urn) < 0) {
|
||||
// mp_raise_OSError(MP_EIO);
|
||||
// }
|
||||
// return mp_obj_new_str(urn, (len - 1), false);
|
||||
// return mp_obj_new_str(urn, (len - 1));
|
||||
// }
|
||||
//
|
||||
// return mp_const_none;
|
||||
|
||||
Reference in New Issue
Block a user