From ea2e7c10cc227cee9f939d38116c1cd3608d7a1b Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Tue, 20 Jan 2004 12:09:08 +0000 Subject: Method to preallocate document space. --- src/CellBuffer.cxx | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'src/CellBuffer.cxx') 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; -- cgit v1.2.3