diff options
author | Iyassou Shimels <s.iyassou@gmail.com> | 2020-09-23 22:45:22 +0300 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-09-24 11:04:58 +1000 |
commit | ca017841d65b5f9da5eb4e6e3ca66b009bc54fc4 (patch) | |
tree | 835c229fc89db716449a19b2f3537e077a37d97d | |
parent | bada8c923195622aee80faf7acf003bc7852459d (diff) | |
download | micropython-ca017841d65b5f9da5eb4e6e3ca66b009bc54fc4.tar.gz micropython-ca017841d65b5f9da5eb4e6e3ca66b009bc54fc4.zip |
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>
-rw-r--r-- | py/objstr.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index a276a255e5..84728e6f2d 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -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; |