(file) Return to Buffer.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/Buffer.cpp between version 1.12 and 1.12.14.1

version 1.12, 2007/02/13 19:21:44 version 1.12.14.1, 2008/01/16 13:22:59
Line 50 
Line 50 
     {0} /* data[0] */     {0} /* data[0] */
 }; };
  
 static const Uint32 MIN_CAPACITY = 2048;  static Uint32 _next_pow_2(Uint32 x, Uint32 minCap)
   
 static Uint32 _next_pow_2(Uint32 x)  
 { {
     // Check for potential overflow in x.     // Check for potential overflow in x.
     PEGASUS_CHECK_CAPACITY_OVERFLOW(x);     PEGASUS_CHECK_CAPACITY_OVERFLOW(x);
  
     if (x < MIN_CAPACITY)      if (x < minCap)
         return MIN_CAPACITY;          return minCap;
  
     x--;     x--;
     x |= (x >> 1);     x |= (x >> 1);
Line 71 
Line 69 
     return x;     return x;
 } }
  
 static inline BufferRep* _allocate(Uint32 cap)  static inline BufferRep* _allocate(Uint32 cap, Uint32 minCap)
 { {
     if (cap < MIN_CAPACITY)      if (cap < minCap)
         cap = MIN_CAPACITY;          cap = minCap;
  
     // Allocate an extra byte for null-termination performed by getData().     // Allocate an extra byte for null-termination performed by getData().
     BufferRep* rep = (BufferRep*)malloc(sizeof(BufferRep) + cap + 1);     BufferRep* rep = (BufferRep*)malloc(sizeof(BufferRep) + cap + 1);
Line 102 
Line 100 
  
 Buffer::Buffer(const Buffer& x) Buffer::Buffer(const Buffer& x)
 { {
     _rep = _allocate(x._rep->cap);      _rep = _allocate(x._rep->cap, x._minCap);
     memcpy(_rep->data, x._rep->data, x._rep->size);     memcpy(_rep->data, x._rep->data, x._rep->size);
     _rep->size = x._rep->size;     _rep->size = x._rep->size;
       _minCap=x._minCap;
 } }
  
 Buffer::Buffer(const char* data, Uint32 size)  Buffer::Buffer(const char* data, Uint32 size, Uint32 minCap): _minCap(minCap)
 { {
     _rep = _allocate(size);      _rep = _allocate(size, _minCap);
     _rep->size = size;     _rep->size = size;
     memcpy(_rep->data, data, size);     memcpy(_rep->data, data, size);
 } }
Line 123 
Line 122 
             if (_rep->cap != 0)             if (_rep->cap != 0)
                 free(_rep);                 free(_rep);
  
             _rep = _allocate(x._rep->cap);              _rep = _allocate(x._rep->cap, x._minCap);
         }         }
  
         memcpy(_rep->data, x._rep->data, x._rep->size);         memcpy(_rep->data, x._rep->data, x._rep->size);
         _rep->size = x._rep->size;         _rep->size = x._rep->size;
           _minCap = x._minCap;
     }     }
     return *this;     return *this;
 } }
Line 136 
Line 136 
 { {
     if (_rep->cap == 0)     if (_rep->cap == 0)
     {     {
         _rep = _allocate(cap);          _rep = _allocate(cap, _minCap);
         _rep->size = 0;         _rep->size = 0;
     }     }
     else     else
         _rep = _reallocate(_rep, _next_pow_2(cap));          _rep = _reallocate(_rep, _next_pow_2(cap, _minCap));
 } }
  
 void Buffer::_append_char_aux() void Buffer::_append_char_aux()
 { {
     if (_rep->cap == 0)     if (_rep->cap == 0)
     {     {
         _rep = _allocate(MIN_CAPACITY);          _rep = _allocate(_minCap, _minCap);
         _rep->size = 0;         _rep->size = 0;
     }     }
     else     else
     {     {
         // Check for potential overflow.         // Check for potential overflow.
         PEGASUS_CHECK_CAPACITY_OVERFLOW(_rep->cap);         PEGASUS_CHECK_CAPACITY_OVERFLOW(_rep->cap);
         _rep = _reallocate(_rep, _rep->cap ? (2 * _rep->cap) : MIN_CAPACITY);          _rep = _reallocate(_rep, _rep->cap ? (2 * _rep->cap) : _minCap);
     }     }
 } }
  
Line 168 
Line 168 
  
     if (cap > _rep->cap)     if (cap > _rep->cap)
     {     {
         BufferRep* rep = _allocate(cap);          BufferRep* rep = _allocate(cap, _minCap);
         rep->size = cap;         rep->size = cap;
  
         memcpy(rep->data, _rep->data, pos);         memcpy(rep->data, _rep->data, pos);


Legend:
Removed from v.1.12  
changed lines
  Added in v.1.12.14.1

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2