diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-30 03:11:44 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-30 03:15:17 +0300 |
commit | 8827682b35f6fefb4604f28447b77e8443cbf1cb (patch) | |
tree | 6dc258faa2d577dc893f231fc19ff53ac6b2127e /py | |
parent | bcdffe53c641ad5832f06cd544f29e3cdd522829 (diff) | |
download | micropython-8827682b35f6fefb4604f28447b77e8443cbf1cb.tar.gz micropython-8827682b35f6fefb4604f28447b77e8443cbf1cb.zip |
objstr: *strip(): If nothing is stripped, don't create dup string.
Diffstat (limited to 'py')
-rw-r--r-- | py/objstr.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/py/objstr.c b/py/objstr.c index 42a246429c..d095c8b471 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -691,6 +691,12 @@ STATIC mp_obj_t str_uni_strip(int type, uint n_args, const mp_obj_t *args) { assert(last_good_char_pos >= first_good_char_pos); //+1 to accomodate the last character machine_uint_t stripped_len = last_good_char_pos - first_good_char_pos + 1; + if (stripped_len == orig_str_len) { + // If nothing was stripped, don't bother to dup original string + // TODO: watch out for this case when we'll get to bytearray.strip() + assert(first_good_char_pos == 0); + return args[0]; + } return mp_obj_new_str_of_type(self_type, orig_str + first_good_char_pos, stripped_len); } |