aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/CellBuffer.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/CellBuffer.cxx')
-rw-r--r--src/CellBuffer.cxx25
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;