aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2013-05-03 13:50:45 +1000
committernyamatongwe <devnull@localhost>2013-05-03 13:50:45 +1000
commit9f15e5c80d736bf2e5cd15f63295cd0ed82284e2 (patch)
tree7d161ea9ebff26cbb6a5fb42b86b1955369348af /src
parent42ef5cfc1cae639a17da2eaea805e71bf851d063 (diff)
downloadscintilla-mirror-9f15e5c80d736bf2e5cd15f63295cd0ed82284e2.tar.gz
Moved allocation of data owned by Action into Action::Create.
Made more variables const.
Diffstat (limited to 'src')
-rw-r--r--src/CellBuffer.cxx22
-rw-r--r--src/CellBuffer.h4
2 files changed, 12 insertions, 14 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx
index 316940621..769f72464 100644
--- a/src/CellBuffer.cxx
+++ b/src/CellBuffer.cxx
@@ -83,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_;
}
@@ -164,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);
@@ -395,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);
@@ -441,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);
}
diff --git a/src/CellBuffer.h b/src/CellBuffer.h
index cde6f5a1a..6fe698e13 100644
--- a/src/CellBuffer.h
+++ b/src/CellBuffer.h
@@ -80,7 +80,7 @@ public:
Action();
~Action();
- void Create(actionType at_, int position_=0, char *data_=0, int lenData_=0, bool mayCoalesce_=true);
+ void Create(actionType at_, int position_=0, const char *data_=0, int lenData_=0, bool mayCoalesce_=true);
void Destroy();
void Grab(Action *source);
};
@@ -105,7 +105,7 @@ public:
UndoHistory();
~UndoHistory();
- void AppendAction(actionType at, int position, char *data, int length, bool &startSequence, bool mayCoalesce=true);
+ void AppendAction(actionType at, int position, const char *data, int length, bool &startSequence, bool mayCoalesce=true);
void BeginUndoAction();
void EndUndoAction();