Branch: Tag:

2008-06-27

2008-06-27 11:28:02 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Mapping.ShadowedMapping no longer uses m_generation(), but instead uses a deferred copy of the parent mapping.
This gives a risk of performance loss if the copy is realized and the mappings are of the same size with substantially the same content.
Fixed AutoDoc mk II markup.

Rev: lib/modules/Mapping.pmod:1.9

14:    static mapping shadow = ([]);       static mapping joined; -  static int parent_generation = -1; +  static mapping parent_copy;    -  static int generation; -  static int dirty = 1; -  +     static int(0..1) modify_parent;    -  //! @param mapping|ShadowedMapping parent +  //! @decl void create(mapping|ShadowedMapping parent, @ +  //! mapping|void shadow, int(0..1)|void modify_parent) +  //! +  //! @param parent    //! Mapping to be shadowed. -  //! @param mapping|void shadow +  //! @param shadow    //! Initial shadow of @[parent]. -  //! @param int(0..1) modify_parent +  //! @param modify_parent    //! Modifications should be done to @[parent] rather than    //! to @[shadow]. If this is set, only entries that are    //! already present in @[shadow] can be modified by later    //! operations. -  +     static void create(mapping|void shadow, int(0..1)|void modify_parent)    {    if (shadow) this_program::shadow = shadow + ([]);
39:    // Updates the cached joined mapping if needed.    static void update_joined()    { -  if (!joined || (parent_generation != m_generation(parent))) { +  if (!joined || !equal(parent, parent_copy)) {    joined = [mapping](parent + shadow); -  parent_generation = m_generation(parent); -  dirty = 1; +  parent_copy = [mapping](parent + ([]));    }    }   
56:    static void `[]=(mixed ind, mixed val)    {    joined = 0; -  dirty = 1; +     if (modify_parent && zero_type(shadow[ind])) {    parent[ind] = val;    } else {
74:    `[]=(ind, val);    }    -  static int _m_generation() +  static int(0..1) _equal(mixed other)    {    update_joined(); -  if (dirty) { -  generation++; -  dirty = 0; +  return equal(other, joined);    } -  return generation; -  } +        static mixed _m_delete(mixed ind)    {
92:    }    if (!zero_type(res)) {    joined = 0; -  dirty = 1; +     }    return res;    }