Logo Search packages:      
Sourcecode: sam2p version File versions

void SimBuffer::B::vi_grow2 ( slendiff_t  left,
slendiff_t  right,
char **  lbeg,
char **  rbeg 
) [virtual]

Overridden.

Definition at line 543 of file gensi.cpp.

References alloced.

Referenced by appendDump(), appendDumpC(), appendDumpPS(), appendFnq(), appendHppq(), appendUnslash(), B(), getAt(), grow_set0_by(), operator<<(), operator=(), substr_grow(), term0(), vformat(), and vi_write().

                                                                                     {
  assert(alloced>=len);
  char *origbeg=const_cast<char*>(beg);
  if (left<0)  { if (len<=(slen_t)-left) len=0; else beg-=left; left=0; } /* ! */
  if (right<0) { if (len<=(slen_t)-right)len=0; else len+=right;right=0; }
  /* ^^^ BUGFIX at Tue Jun 11 16:07:56 CEST 2002 */
  assert(left>=0);
  assert(right>=0);
  slen_t newlen=left+right+len;
  assert(newlen>=len);
  char *newbeg;
  assert(alloced>=sizeof(small)/1);
  if (beg==small) {
    assert(alloced==sizeof(small));
    if (newlen>sizeof(small)) {
      assert(newlen>len);
      newbeg=new char[alloced=2*newlen];
      memcpy(newbeg+left, beg, len);
      beg=newbeg;
    }
  } else { /* beg!=small */
    // assert(len>=alloced/2); /* -- may not always be true, especially not after appending a `long' */
    if (newlen<alloced/2) { /* shrink */
      // assert(newlen<=len); /* filled-expectations are true _after_ vi_grow2, not before */
      if (newlen>sizeof(small)) {
        newbeg=new char[alloced=newlen];
        memcpy(newbeg+left, beg, len);
      } else {
        memcpy((newbeg=small)+left, beg, len);
        delete [] origbeg;
        alloced=sizeof(small);
      }
      beg=newbeg;
    } else if (newlen>alloced) { /* grow */
      assert(newlen>sizeof(small));
      assert(newlen>len);
      newbeg=new char[alloced=2*newlen];
      memcpy(newbeg+left, beg, len);
      delete [] origbeg;
      beg=newbeg;
    } else if (beg!=origbeg) { /* called with negative `left' @param */
      assert(left==0);
      memmove(origbeg, beg, len); /* Slow, may move the whole buffer. */
    }
  }
  // fprintf(stderr, "newlen=%u\n", newlen);
  len=newlen;
  if (lbeg) *lbeg=const_cast<char*>(beg);
  if (rbeg) *rbeg=const_cast<char*>(beg+newlen-right);
  assert(alloced==sizeof(small) || (alloced>sizeof(small) && len>=alloced/2));
  assert(alloced>=len);
}


Generated by  Doxygen 1.6.0   Back to index