pike.git / lib / modules / Mapping.pmod

version» Context lines:

pike.git/lib/modules/Mapping.pmod:12:   class ShadowedMapping(static mapping|ShadowedMapping parent)   {    static mapping shadow = ([]);       static mapping joined;    static int parent_generation = -1;       static int generation;    static int dirty = 1;    +  static int(0..1) modify_parent; +  +  //! @param mapping|ShadowedMapping parent +  //! Mapping to be shadowed. +  //! @param mapping|void shadow +  //! Initial shadow of @[parent]. +  //! @param int(0..1) 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 + ([]); +  this_program::modify_parent = modify_parent; +  } +     // Updates the cached joined mapping if needed.    static void update_joined()    {    if (!joined || (parent_generation != m_generation(parent))) {    joined = [mapping](parent + shadow);    parent_generation = m_generation(parent);    dirty = 1;    }    }   
pike.git/lib/modules/Mapping.pmod:33:    {    mixed res = shadow[ind];    if (!zero_type(res)) return res;    return parent[ind];    }       static void `[]=(mixed ind, mixed val)    {    joined = 0;    dirty = 1; +  if (modify_parent && zero_type(shadow[ind])) { +  parent[ind] = val; +  } else {    shadow[ind] = val;    } -  +  }       static mixed `->(string ind)    {    return `[](ind);    }       static void `->=(string ind, mixed val)    {    `[]=(ind, val);    }       static int _m_generation()    { -  if (dirty || (parent_generation != m_generation(parent))) { -  if (!dirty && (parent_generation != m_generation(parent))) +     update_joined(); -  +  if (dirty) {    generation++;    dirty = 0;    }    return generation;    }       static mixed _m_delete(mixed ind)    {    mixed res = m_delete(shadow, ind);    if (zero_type(res)) {    res = m_delete(parent, ind);    } -  +  if (!zero_type(res)) { +  joined = 0; +  dirty = 1; +  }    return res;    }       static array(mixed) _indices()    {    update_joined();    return indices(joined);    }       static array(mixed) _values()