We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e9404e5 commit a3edeb9Copy full SHA for a3edeb9
py/objdict.c
@@ -250,15 +250,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_copy_obj, dict_copy);
250
// this is a classmethod
251
STATIC mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) {
252
mp_obj_t iter = mp_getiter(args[1]);
253
- mp_obj_t len = mp_obj_len_maybe(iter);
254
mp_obj_t value = mp_const_none;
255
mp_obj_t next = MP_OBJ_NULL;
256
- mp_obj_t self_out;
257
258
if (n_args > 2) {
259
value = args[2];
260
}
261
+ // optimisation to allocate result based on len of argument
+ mp_obj_t self_out;
262
+ mp_obj_t len = mp_obj_len_maybe(args[1]);
263
if (len == MP_OBJ_NULL) {
264
/* object's type doesn't have a __len__ slot */
265
self_out = mp_obj_new_dict(0);
0 commit comments