aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <unknown>2004-01-20 12:09:08 +0000
committernyamatongwe <unknown>2004-01-20 12:09:08 +0000
commitea2e7c10cc227cee9f939d38116c1cd3608d7a1b (patch)
treeb4ae7513d811353fb24759e4674935b05979a2af
parent3e1668f499d347b5f091d22789dba243cc98f860 (diff)
downloadscintilla-mirror-ea2e7c10cc227cee9f939d38116c1cd3608d7a1b.tar.gz
Method to preallocate document space.
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface3
-rw-r--r--src/CellBuffer.cxx25
-rw-r--r--src/CellBuffer.h3
-rw-r--r--src/Document.h5
-rw-r--r--src/Editor.cxx4
6 files changed, 27 insertions, 14 deletions
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 68c5427b6..d39e3b7ed 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -570,6 +570,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define SCI_SETWHITESPACECHARS 2443
#define SCI_SETCHARSDEFAULT 2444
#define SCI_AUTOCGETCURRENT 2445
+#define SCI_ALLOCATE 2446
#define SCI_STARTRECORD 3001
#define SCI_STOPRECORD 3002
#define SCI_SETLEXER 4001
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index 5ee7afd5f..d84ab688e 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -1549,6 +1549,9 @@ fun void SetCharsDefault=2444(,)
# Get currently selected item position in the auto-completion list
fun int AutoCGetCurrent=2445(,)
+# Enlarge the document to a particular size of text bytes.
+fun void Allocate=2446(int bytes,)
+
# Start notifying the container of all key presses and commands.
fun void StartRecord=3001(,)
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;
diff --git a/src/CellBuffer.h b/src/CellBuffer.h
index 5cfcbfe1f..726ec015f 100644
--- a/src/CellBuffer.h
+++ b/src/CellBuffer.h
@@ -184,6 +184,7 @@ public:
int ByteLength();
int Length();
+ void Allocate(int newSize);
int Lines();
int LineStart(int line);
int LineFromPosition(int pos) { return lv.LineFromPosition(pos); }
@@ -212,7 +213,7 @@ public:
int GetMark(int line);
void DeleteAllMarks(int markerNum);
int LineFromHandle(int markerHandle);
-
+
/// Actions without undo
void BasicInsertString(int position, char *s, int insertLength);
void BasicDeleteChars(int position, int deleteLength);
diff --git a/src/Document.h b/src/Document.h
index f5436ab4f..18b47eaf5 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -87,7 +87,7 @@ public:
userData = 0;
}
};
-
+
enum charClassification { ccSpace, ccNewLine, ccWord, ccPunctuation };
private:
@@ -193,6 +193,7 @@ public:
int NextWordStart(int pos, int delta);
int NextWordEnd(int pos, int delta);
int Length() { return cb.Length(); }
+ void Allocate(int newSize) { cb.Allocate(newSize*2); }
long FindText(int minPos, int maxPos, const char *s,
bool caseSensitive, bool word, bool wordStart, bool regExp, bool posix, int *length);
long FindText(int iMessage, unsigned long wParam, long lParam);
@@ -200,7 +201,7 @@ public:
int LinesTotal();
void ChangeCase(Range r, bool makeUpperCase);
-
+
void SetDefaultCharClasses();
void SetCharClasses(unsigned char *chars, charClassification newCharClass);
void SetStylingBits(int bits);
diff --git a/src/Editor.cxx b/src/Editor.cxx
index f9d20aa47..a11f99688 100644
--- a/src/Editor.cxx
+++ b/src/Editor.cxx
@@ -5788,6 +5788,10 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
case SCI_GETLENGTH:
return pdoc->Length();
+ case SCI_ALLOCATE:
+ pdoc->Allocate(wParam);
+ break;
+
case SCI_GETCHARAT:
return pdoc->CharAt(wParam);