diff options
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);  		} | 
