diff options
author | nyamatongwe <unknown> | 2004-01-20 12:09:08 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2004-01-20 12:09:08 +0000 |
commit | ea2e7c10cc227cee9f939d38116c1cd3608d7a1b (patch) | |
tree | b4ae7513d811353fb24759e4674935b05979a2af /src/CellBuffer.cxx | |
parent | 3e1668f499d347b5f091d22789dba243cc98f860 (diff) | |
download | scintilla-mirror-ea2e7c10cc227cee9f939d38116c1cd3608d7a1b.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; |