diff options
author | nyamatongwe <devnull@localhost> | 2004-01-20 12:09:08 +0000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2004-01-20 12:09:08 +0000 |
commit | 3b4321e0bd6090f1e83bf13111d6f6158e49d667 (patch) | |
tree | b4ae7513d811353fb24759e4674935b05979a2af /src/CellBuffer.cxx | |
parent | f5c3d93ebb9148ff12ea7acbe27f17079a5f62d8 (diff) | |
download | scintilla-mirror-3b4321e0bd6090f1e83bf13111d6f6158e49d667.tar.gz |
Method to preallocate document space.
Diffstat (limited to 'src/CellBuffer.cxx')
-rw-r--r-- | src/CellBuffer.cxx | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 6dae67507..f6c1f7b17 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -627,21 +627,11 @@ void CellBuffer::RoomFor(int insertionLength) { //Platform::DebugPrintf("need room %d %d\n", gaplen, insertionLength); if (gaplen <= insertionLength) { //Platform::DebugPrintf("need room %d %d\n", gaplen, insertionLength); - GapTo(length); if (growSize * 6 < size) growSize *= 2; int newSize = size + insertionLength + growSize; - //Platform::DebugPrintf("moved gap %d\n", newSize); - char *newBody = new char[newSize]; - memcpy(newBody, body, size); - delete []body; - body = newBody; - gaplen += newSize - size; - part2body = body + gaplen; - size = newSize; - //Platform::DebugPrintf("end need room %d %d - size=%d length=%d\n", gaplen, insertionLength,size,length); + Allocate(newSize); } - } // To make it easier to write code that uses ByteAt, a position outside the range of the buffer @@ -791,6 +781,19 @@ int CellBuffer::Length() { return ByteLength() / 2; } +void CellBuffer::Allocate(int newSize) { + if (newSize > size) { + GapTo(length); + char *newBody = new char[newSize]; + memcpy(newBody, body, size); + delete []body; + body = newBody; + gaplen += newSize - size; + part2body = body + gaplen; + size = newSize; + } +} + int CellBuffer::Lines() { //Platform::DebugPrintf("Lines = %d\n", lv.lines); return lv.lines; |