[fbreader] Removed unnecessary stuff from ZLTextParagraphCursorCache

ourLastAdded member was causing a crash on destruction (double free),
get() and put() methods were just unnecessary.
This commit is contained in:
Slava Monich 2016-10-30 11:40:57 +03:00
parent 8169b31531
commit c2558fbb3f
2 changed files with 4 additions and 15 deletions

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com> * Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2016 Slava Monich <slava.monich@jolla.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -81,14 +82,14 @@ ZLTextElementPool::~ZLTextElementPool() {
ZLTextParagraphCursorPtr ZLTextParagraphCursorCache::cursor(const ZLTextModel &model, size_t index) { ZLTextParagraphCursorPtr ZLTextParagraphCursorCache::cursor(const ZLTextModel &model, size_t index) {
const ZLTextParagraph *paragraph = model[index]; const ZLTextParagraph *paragraph = model[index];
ZLTextParagraphCursorPtr result = get(paragraph); ZLTextParagraphCursorPtr result = ourCache[paragraph];
if (result.isNull()) { if (result.isNull()) {
if (model.kind() == ZLTextModel::TREE_MODEL) { if (model.kind() == ZLTextModel::TREE_MODEL) {
result = new ZLTextTreeParagraphCursor((const ZLTextTreeModel&)model, index, this); result = new ZLTextTreeParagraphCursor((const ZLTextTreeModel&)model, index, this);
} else { } else {
result = new ZLTextPlainParagraphCursor(model, index, this); result = new ZLTextPlainParagraphCursor(model, index, this);
} }
put(paragraph, result); ourCache[paragraph] = result;
} }
return result; return result;
} }
@ -256,17 +257,7 @@ void ZLTextParagraphCursor::clear() {
myElements.clear(); myElements.clear();
} }
void ZLTextParagraphCursorCache::put(const ZLTextParagraph *paragraph, ZLTextParagraphCursorPtr cursor) {
ourCache[paragraph] = cursor;
ourLastAdded = cursor;
}
ZLTextParagraphCursorPtr ZLTextParagraphCursorCache::get(const ZLTextParagraph *paragraph) {
return ourCache[paragraph];
}
void ZLTextParagraphCursorCache::clear() { void ZLTextParagraphCursorCache::clear() {
ourLastAdded.reset();
ourCache.clear(); ourCache.clear();
} }

View file

@ -1,5 +1,6 @@
/* /*
* Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com> * Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
* Copyright (C) 2016 Slava Monich <slava.monich@jolla.com>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -136,14 +137,11 @@ public:
void clear(); void clear();
void cleanup(); void cleanup();
void put(const ZLTextParagraph *paragraph, ZLTextParagraphCursorPtr cursor);
ZLTextParagraphCursorPtr get(const ZLTextParagraph *paragraph);
ZLTextParagraphCursorPtr cursor(const ZLTextModel &model, size_t index); ZLTextParagraphCursorPtr cursor(const ZLTextModel &model, size_t index);
ZLTextElementPool *elementPool() { return &ourElementPool; } ZLTextElementPool *elementPool() { return &ourElementPool; }
private: private:
std::map<const ZLTextParagraph*, weak_ptr<ZLTextParagraphCursor> > ourCache; std::map<const ZLTextParagraph*, weak_ptr<ZLTextParagraphCursor> > ourCache;
ZLTextParagraphCursorPtr ourLastAdded;
ZLTextElementPool ourElementPool; ZLTextElementPool ourElementPool;
}; };