summaryrefslogtreecommitdiffstats
path: root/scintilla/src/CellBuffer.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'scintilla/src/CellBuffer.cxx')
-rw-r--r--scintilla/src/CellBuffer.cxx24
1 files changed, 12 insertions, 12 deletions
diff --git a/scintilla/src/CellBuffer.cxx b/scintilla/src/CellBuffer.cxx
index 7c1b42c..95e2a80 100644
--- a/scintilla/src/CellBuffer.cxx
+++ b/scintilla/src/CellBuffer.cxx
@@ -10,6 +10,8 @@
#include <stdlib.h>
#include <stdarg.h>
+#include <algorithm>
+
#include "Platform.h"
#include "Scintilla.h"
@@ -81,11 +83,15 @@ Action::~Action() {
Destroy();
}
-void Action::Create(actionType at_, int position_, char *data_, int lenData_, bool mayCoalesce_) {
+void Action::Create(actionType at_, int position_, const char *data_, int lenData_, bool mayCoalesce_) {
delete []data;
+ data = NULL;
position = position_;
at = at_;
- data = data_;
+ if (lenData_) {
+ data = new char[lenData_];
+ memcpy(data, data_, lenData_);
+ }
lenData = lenData_;
mayCoalesce = mayCoalesce_;
}
@@ -162,7 +168,7 @@ void UndoHistory::EnsureUndoRoom() {
}
}
-void UndoHistory::AppendAction(actionType at, int position, char *data, int lengthData,
+void UndoHistory::AppendAction(actionType at, int position, const char *data, int lengthData,
bool &startSequence, bool mayCoalesce) {
EnsureUndoRoom();
//Platform::DebugPrintf("%% %d action %d %d %d\n", at, position, lengthData, currentAction);
@@ -393,11 +399,7 @@ const char *CellBuffer::InsertString(int position, const char *s, int insertLeng
if (collectingUndo) {
// Save into the undo/redo stack, but only the characters - not the formatting
// This takes up about half load time
- data = new char[insertLength];
- for (int i = 0; i < insertLength; i++) {
- data[i] = s[i];
- }
- uh.AppendAction(insertAction, position, data, insertLength, startSequence);
+ uh.AppendAction(insertAction, position, s, insertLength, startSequence);
}
BasicInsertString(position, s, insertLength);
@@ -439,10 +441,8 @@ const char *CellBuffer::DeleteChars(int position, int deleteLength, bool &startS
if (!readOnly) {
if (collectingUndo) {
// Save into the undo/redo stack, but only the characters - not the formatting
- data = new char[deleteLength];
- for (int i = 0; i < deleteLength; i++) {
- data[i] = substance.ValueAt(position + i);
- }
+ // The gap would be moved to position anyway for the deletion so this doesn't cost extra
+ const char *data = substance.RangePointer(position, deleteLength);
uh.AppendAction(removeAction, position, data, deleteLength, startSequence);
}