(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.4.2.3 and 1.6

version 1.4.2.3, 2006/07/28 20:06:32 version 1.6, 2006/05/10 19:40:38
Line 39 
Line 39 
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 //  BufferRep Buffer::_empty_rep = { 0, 0, {0} };
 // Note: _empty_rep is the only BufferRep object that may have a zero capacity.  
 // So "_rep->cap == 0" implies "_rep == _empty_rep". But some platforms produce  
 // more than one instance of _empty_rep (strangely). Therefore, it is safer to  
 // use the former test rather than the latter.  
 //  
 BufferRep Buffer::_empty_rep =  
 {  
     0, /* size */  
     0, /* cap (zero implies it is the _empty_rep) */  
     {0} /* data[0] */  
 };  
  
 static const size_t MIN_CAPACITY = 2048; static const size_t MIN_CAPACITY = 2048;
  
Line 75 
Line 64 
  
 static inline BufferRep* _allocate(size_t cap) static inline BufferRep* _allocate(size_t cap)
 { {
     if (cap < MIN_CAPACITY)      BufferRep* rep = (BufferRep*)malloc(sizeof(BufferRep) + cap);
         cap = MIN_CAPACITY;  
   
     // Allocate an extra byte for null-termination performed by getData().  
     BufferRep* rep = (BufferRep*)malloc(sizeof(BufferRep) + cap + 1);  
   
     if (!rep)     if (!rep)
     {     {
         throw PEGASUS_STD(bad_alloc)();         throw PEGASUS_STD(bad_alloc)();
Line 91 
Line 75 
  
 static inline BufferRep* _reallocate(BufferRep* rep, size_t cap) static inline BufferRep* _reallocate(BufferRep* rep, size_t cap)
 { {
     // Allocate an extra byte for null-termination performed by getData().      rep = (BufferRep*)realloc(rep, sizeof(BufferRep) + cap);
     rep = (BufferRep*)realloc(rep, sizeof(BufferRep) + cap + 1);  
   
     if (!rep)     if (!rep)
     {     {
         throw PEGASUS_STD(bad_alloc)();         throw PEGASUS_STD(bad_alloc)();
Line 122 
Line 104 
     {     {
         if (x._rep->size > _rep->cap)         if (x._rep->size > _rep->cap)
         {         {
             if (_rep->cap != 0)              if (_rep != &_empty_rep)
                 free(_rep);                 free(_rep);
  
             _rep = _allocate(x._rep->cap);             _rep = _allocate(x._rep->cap);
Line 136 
Line 118 
  
 void Buffer::_reserve_aux(size_t cap) void Buffer::_reserve_aux(size_t cap)
 { {
     if (_rep->cap == 0)      if (_rep == &_empty_rep)
     {     {
         _rep = _allocate(cap);         _rep = _allocate(cap);
         _rep->size = 0;         _rep->size = 0;
Line 147 
Line 129 
  
 void Buffer::_append_char_aux() void Buffer::_append_char_aux()
 { {
     if (_rep->cap == 0)      if (_rep == &_empty_rep)
     {     {
         _rep = _allocate(MIN_CAPACITY);         _rep = _allocate(MIN_CAPACITY);
         _rep->size = 0;         _rep->size = 0;
Line 177 
Line 159 
         memcpy(rep->data + pos, data, size);         memcpy(rep->data + pos, data, size);
         memcpy(rep->data + pos + size, _rep->data + pos, rem);         memcpy(rep->data + pos + size, _rep->data + pos, rem);
  
         if (_rep->cap != 0)          if (_rep != &_empty_rep)
             free(_rep);             free(_rep);
  
         _rep = rep;         _rep = rep;


Legend:
Removed from v.1.4.2.3  
changed lines
  Added in v.1.6

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2