fix memory leak - issue #19

This commit is contained in:
Vadim Lopatin 2014-12-10 15:17:00 +03:00
parent 80280ca0f7
commit 1bdf1ce3fa
2 changed files with 12 additions and 5 deletions

View File

@ -82,7 +82,7 @@ struct Collection(T, bool ownItems = false) {
void add(T item, size_t index = size_t.max) { void add(T item, size_t index = size_t.max) {
if (index > _len) if (index > _len)
index = _len; index = _len;
if (_items.length >= _len) { if (_items.length <= _len) {
if (_items.length < 4) if (_items.length < 4)
_items.length = 4; _items.length = 4;
else else

View File

@ -292,12 +292,15 @@ class EditOperation {
_action = action; _action = action;
_range = range; _range = range;
_content.length = 1; _content.length = 1;
_content[0] = text; _content[0] = text.dup;
} }
this(EditAction action, TextRange range, dstring[] text) { this(EditAction action, TextRange range, dstring[] text) {
_action = action; _action = action;
_range = range; _range = range;
_content = text; _content.length = text.length;
for(int i = 0; i < text.length; i++)
_content[i] = text[i].dup;
//_content = text;
} }
/// try to merge two operations (simple entering of characters in the same line), return true if succeded /// try to merge two operations (simple entering of characters in the same line), return true if succeded
bool merge(EditOperation op) { bool merge(EditOperation op) {
@ -318,12 +321,12 @@ class EditOperation {
_range.start.pos--; _range.start.pos--;
_newRange.start.pos--; _newRange.start.pos--;
_newRange.end.pos--; _newRange.end.pos--;
_oldContent[0] = (op._oldContent[0] ~ _oldContent[0]).dup; _oldContent[0] = (op._oldContent[0].dup ~ _oldContent[0].dup).dup;
return true; return true;
} else if (_newRange.end.pos == op._range.start.pos) { } else if (_newRange.end.pos == op._range.start.pos) {
// removed char after // removed char after
_range.end.pos++; _range.end.pos++;
_oldContent[0] = (_oldContent[0] ~ op._oldContent[0]).dup; _oldContent[0] = (_oldContent[0].dup ~ op._oldContent[0].dup).dup;
return true; return true;
} }
} }
@ -354,7 +357,11 @@ class UndoBuffer {
return; // merged - no need to add new operation return; // merged - no need to add new operation
} }
} }
long ts = currentTimeMillis();
_undoList.pushBack(op); _undoList.pushBack(op);
long duration = currentTimeMillis() - ts;
if (duration > 3)
Log.w("Too long saveForUndo: ", duration, " ms");
} }
/// returns operation to be undone (put it to redo), null if no undo ops available /// returns operation to be undone (put it to redo), null if no undo ops available