D11828: Simplify orPostingIterator and make it faster
Stefan BrĂ¼ns
noreply at phabricator.kde.org
Mon Apr 9 15:42:19 UTC 2018
bruns added a comment.
In D11828#242372 <https://phabricator.kde.org/D11828#242372>, @michaelh wrote:
> While reading in IDE realized `(*it)` resolves to `PostingIterator**` I got a little dizzy at first, then started to play with this code and came up with this.
> In Constructor:
>
> for (PostingIterator* it : m_iterators) {
> if (it == nullptr) {
> m_iterators.erase(&it);
Thats not how QVector<>::iterator works
- you can not create an QVector<>::iterator from an PostingIterator*. The latter is just a (pointer to) a PostingIterator, it does not know about the container (QVector) it is member of [1]
- deleting an element from a container using `.erase(it)` typically invalidates the `it`, thats the reason `.erase(it)` returns an iterator to the next element
- `it = m_iterators.erase(it)` thus implicitly moves the iterator forward
> } else {
> auto docId = it->next();
> if (docId && (docId < m_nextId || m_nextId == 0)) {
> m_nextId = docId;
> }
> }
>
> }
>
> In `OrPostingIterator::next()`
does not work for the same reason ...
What could work is deleting the PostingIterator immediately and setting the iterator value to `nullptr`, and then do a cleanup pass afterwards with `QVector<>::removeAll(nullptr)`.
REPOSITORY
R293 Baloo
REVISION DETAIL
https://phabricator.kde.org/D11828
To: bruns, #baloo, michaelh
Cc: #frameworks, ashaposhnikov, michaelh, astippich, spoorun, ngraham, bruns, alexeymin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20180409/3d3a28e0/attachment.html>
More information about the Kde-frameworks-devel
mailing list