Skip to content
  • Damien George's avatar
    py/objstr: Make mp_obj_new_str_of_type check for existing interned qstr. · 1f1d5194
    Damien George authored
    The function mp_obj_new_str_of_type is a general str object constructor
    used in many places in the code to create either a str or bytes object.
    When creating a str it should first check if the string data already exists
    as an interned qstr, and if so then return the qstr object.  This patch
    makes the function have such behaviour, which helps to reduce heap usage by
    reusing existing interned data where possible.
    
    The old behaviour of mp_obj_new_str_of_type (which didn't check for
    existing interned data) is made available through the function
    mp_obj_new_str_copy, but should only be used in very special cases.
    
    One consequence of this patch is that the following expression is now True:
    
        'abc' is ' abc '.split()[0]
    1f1d5194