/*public non-poly*/
morkArray::morkArray(morkEnv* ev, const morkUsage& inUsage,
    nsIMdbHeap* ioHeap, mork_size inSize, nsIMdbHeap* ioSlotHeap)
: morkNode(ev, inUsage, ioHeap)
, mArray_Slots( 0 )
, mArray_Heap( 0 )
, mArray_Fill( 0 )
, mArray_Size( 0 )
, mArray_Seed( (mork_u4)NS_PTR_TO_INT32(this) ) // "random" integer assignment
{
  if ( ev->Good() )
  {
    if ( ioSlotHeap )
    {
      nsIMdbHeap_SlotStrongHeap(ioSlotHeap, ev, &mArray_Heap);
      if ( ev->Good() )
      {
        if ( inSize < 3 )
          inSize = 3;
        mdb_size byteSize = inSize * sizeof(void*);
        void** block = 0;
        ioSlotHeap->Alloc(ev->AsMdbEnv(), byteSize, (void**) &block);
        if ( block && ev->Good() )
        {
          mArray_Slots = block;
          mArray_Size = inSize;
          MORK_MEMSET(mArray_Slots, 0, byteSize);
          if ( ev->Good() )
            mNode_Derived = morkDerived_kArray;
        }
      }
    }
    else
      ev->NilPointerError();
  }
}
示例#2
0
void morkMap::InitMap(morkEnv* ev, mork_size inSlots)
{
  if ( ev->Good() )
  {
    morkHashArrays old;
    // MORK_MEMCPY(&mMap_Form, &inForm, sizeof(morkMapForm));
    if ( inSlots < 3 ) /* requested capacity absurdly small? */
      inSlots = 3; /* bump it up to a minimum practical level */
    else if ( inSlots > (128 * 1024) ) /* requested slots absurdly big? */
      inSlots = (128 * 1024); /* decrease it to a maximum practical level */
      
    if ( this->new_arrays(ev, &old, inSlots) )
      mMap_Tag = morkMap_kTag;

    MORK_MEMSET(&old, 0, sizeof(morkHashArrays)); // do NOT finalize
  }
}
// alloc and free individual instances of rows:
morkRow* morkPool::NewRow(morkEnv* ev,
                          morkZone* ioZone)  // allocate a new row instance
{
  morkRow* newRow = 0;

#ifdef morkZone_CONFIG_ARENA
  // a zone 'chip' remembers no size, and so cannot be deallocated:
  newRow = (morkRow*)ioZone->ZoneNewChip(ev, sizeof(morkRow));
#else  /*morkZone_CONFIG_ARENA*/
  MORK_USED_1(ioZone);
  mPool_Heap->Alloc(ev->AsMdbEnv(), sizeof(morkRow), (void**)&newRow);
#endif /*morkZone_CONFIG_ARENA*/

  if (newRow) MORK_MEMSET(newRow, 0, sizeof(morkRow));

  return newRow;
}
示例#4
0
void*
morkMap::clear_alloc(morkEnv* ev, mork_size inSize)
{
  void* p = 0;
  nsIMdbHeap* heap = mMap_Heap;
  if ( heap )
  {
    if ( heap->Alloc(ev->AsMdbEnv(), inSize, (void**) &p) == 0 && p )
    {
      MORK_MEMSET(p, 0, inSize);
      return p;
    }
  }
  else
    ev->NilPointerError();
    
  return (void*) 0;
}
// alloc and free entire vectors of cells (not just one cell at a time)
morkCell* morkPool::NewCells(morkEnv* ev, mork_size inSize, morkZone* ioZone) {
  morkCell* newCells = 0;

  mork_size size = inSize * sizeof(morkCell);
  if (size) {
#ifdef morkZone_CONFIG_ARENA
    // a zone 'run' knows its size, and can indeed be deallocated:
    newCells = (morkCell*)ioZone->ZoneNewRun(ev, size);
#else  /*morkZone_CONFIG_ARENA*/
    MORK_USED_1(ioZone);
    mPool_Heap->Alloc(ev->AsMdbEnv(), size, (void**)&newCells);
#endif /*morkZone_CONFIG_ARENA*/
  }

  // note morkAtom depends on having nil stored in all new mCell_Atom slots:
  if (newCells) MORK_MEMSET(newCells, 0, size);
  return newCells;
}
void
morkArray::CutAllSlots(morkEnv* ev)
{
  if ( mArray_Slots )
  {
    if ( mArray_Fill <= mArray_Size )
    {
      mdb_size oldByteSize = mArray_Fill * sizeof(void*);
      MORK_MEMSET(mArray_Slots, 0, oldByteSize);
    }
    else
      this->FillBeyondSizeError(ev);
  }
  else
    this->NilSlotsAddressError(ev);

  ++mArray_Seed;
  mArray_Fill = 0;
}
示例#7
0
/*public non-poly*/ void
morkMap::CloseMap(morkEnv* ev) // called by CloseMorkNode();
{
  if ( this )
  {
    if ( this->IsNode() )
    {
      nsIMdbHeap* heap = mMap_Heap;
      if ( heap ) /* need to free the arrays? */
      {
        nsIMdbEnv* menv = ev->AsMdbEnv();
        
        if ( mMap_Keys )
          heap->Free(menv, mMap_Keys);
          
        if ( mMap_Vals )
          heap->Free(menv, mMap_Vals);
          
        if ( mMap_Assocs )
          heap->Free(menv, mMap_Assocs);
          
        if ( mMap_Buckets )
          heap->Free(menv, mMap_Buckets);
          
        if ( mMap_Changes )
          heap->Free(menv, mMap_Changes);
      }
      mMap_Keys = 0;
      mMap_Vals = 0;
      mMap_Buckets = 0;
      mMap_Assocs = 0;
      mMap_Changes = 0;
      mMap_FreeList = 0;
      MORK_MEMSET(&mMap_Form, 0, sizeof(morkMapForm));
      this->MarkShut();
    }
    else
      this->NonNodeError(ev);
  }
  else
    ev->NilPointerError();
}
示例#8
0
void
morkMap::clear_map(morkEnv* ev, nsIMdbHeap* ioSlotHeap)
{
  mMap_Tag = 0;
  mMap_Seed = 0;
  mMap_Slots = 0;
  mMap_Fill = 0;
  mMap_Keys = 0;
  mMap_Vals = 0;
  mMap_Assocs = 0;
  mMap_Changes = 0;
  mMap_Buckets = 0;
  mMap_FreeList = 0;
  MORK_MEMSET(&mMap_Form, 0, sizeof(morkMapForm));
  
  mMap_Heap = 0;
  if ( ioSlotHeap )
  {
    nsIMdbHeap_SlotStrongHeap(ioSlotHeap, ev, &mMap_Heap);
  }
  else
    ev->NilPointerError();
}
示例#9
0
mork_bool
morkMap::new_arrays(morkEnv* ev, morkHashArrays* old, mork_num inSlots)
{
  mork_bool outNew = morkBool_kFalse;
    
  /* see if we can allocate all the new arrays before we go any further: */
  morkAssoc** newBuckets = this->new_buckets(ev, inSlots);
  morkAssoc* newAssocs = this->new_assocs(ev, inSlots);
  mork_u1* newKeys = this->new_keys(ev, inSlots);
  mork_u1* newValues = this->new_values(ev, inSlots);
  mork_change* newChanges = this->new_changes(ev, inSlots);
  
  /* it is okay for newChanges to be null when changes are not held: */
  mork_bool okayChanges = ( newChanges || !this->FormHoldChanges() );
  
  /* it is okay for newValues to be null when values are zero sized: */
  mork_bool okayValues = ( newValues || !this->FormValSize() );
  
  if ( newBuckets && newAssocs && newKeys && okayChanges && okayValues )
  {
    outNew = morkBool_kTrue; /* yes, we created all the arrays we need */

    /* init the old hashArrays with slots from this hash table: */
    old->mHashArrays_Heap = mMap_Heap;
    
    old->mHashArrays_Slots = mMap_Slots;
    old->mHashArrays_Keys = mMap_Keys;
    old->mHashArrays_Vals = mMap_Vals;
    old->mHashArrays_Assocs = mMap_Assocs;
    old->mHashArrays_Buckets = mMap_Buckets;
    old->mHashArrays_Changes = mMap_Changes;
    
    /* now replace all our array slots with the new structures: */
    ++mMap_Seed; /* note the map is now changed */
    mMap_Keys = newKeys;
    mMap_Vals = newValues;
    mMap_Buckets = newBuckets;
    mMap_Assocs = newAssocs;
    mMap_FreeList = newAssocs; /* all are free to start with */
    mMap_Changes = newChanges;
    mMap_Slots = inSlots;
  }
  else /* free the partial set of arrays that were actually allocated */
  {
    nsIMdbEnv* menv = ev->AsMdbEnv();
    nsIMdbHeap* heap = mMap_Heap;
    if ( newBuckets )
      heap->Free(menv, newBuckets);
    if ( newAssocs )
      heap->Free(menv, newAssocs);
    if ( newKeys )
      heap->Free(menv, newKeys);
    if ( newValues )
      heap->Free(menv, newValues);
    if ( newChanges )
      heap->Free(menv, newChanges);
    
    MORK_MEMSET(old, 0, sizeof(morkHashArrays));
  }
  
  return outNew;
}