objexcept: Optimize using messages without formatting substitutions.
They are directly cast to str object, skipping allocation of formatting buffer.
This commit is contained in:
parent
3077fbff26
commit
29c4f92e13
|
@ -348,18 +348,22 @@ mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char
|
|||
if (fmt == NULL) {
|
||||
// no message
|
||||
assert(0);
|
||||
} else {
|
||||
if (strchr(fmt, '%') == NULL) {
|
||||
// no formatting substitutions, avoid allocating vstr.
|
||||
o->args->items[0] = mp_obj_new_str(fmt, strlen(fmt), false);
|
||||
} else {
|
||||
// render exception message and store as .args[0]
|
||||
// TODO: optimize bufferbloat
|
||||
va_list ap;
|
||||
vstr_t vstr;
|
||||
vstr_init(&vstr, 16);
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
vstr_vprintf(&vstr, fmt, ap);
|
||||
va_end(ap);
|
||||
o->args->items[0] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue