diff options
author | nyamatongwe <unknown> | 2013-05-03 13:50:45 +1000 |
---|---|---|
committer | nyamatongwe <unknown> | 2013-05-03 13:50:45 +1000 |
commit | e4cfb287a2b9f8a283f5347a262efd95c88014d1 (patch) | |
tree | 84bcb791864bc7f0faf70df267bf40e0f4a79ed6 /src/CellBuffer.cxx | |
parent | 516c6ae7a1ce3fbef7e6dca0f81d5273e7cde668 (diff) | |
download | scintilla-mirror-e4cfb287a2b9f8a283f5347a262efd95c88014d1.tar.gz |
Moved allocation of data owned by Action into Action::Create.
Made more variables const.
Diffstat (limited to 'src/CellBuffer.cxx')
-rw-r--r-- | src/CellBuffer.cxx | 22 |
1 files changed, 10 insertions, 12 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); } |