py/objstr: Make bytes(bytes_obj) return bytes_obj.

Calling the bytes constructor on a bytes object returns the original bytes
object.  This saves allocating a new instance, and matches CPython.

Signed-off-by: Iyassou Shimels <s.iyassou@gmail.com>
This commit is contained in:
Iyassou Shimels 2020-09-23 22:45:22 +03:00 committed by Damien George
parent bada8c9231
commit ca017841d6
1 changed files with 4 additions and 0 deletions

View File

@ -205,6 +205,10 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
return mp_const_empty_bytes;
}
if (mp_obj_is_type(args[0], &mp_type_bytes)) {
return args[0];
}
if (mp_obj_is_str(args[0])) {
if (n_args < 2 || n_args > 3) {
goto wrong_args;