refactor matches to be returned as shared pointers#298
refactor matches to be returned as shared pointers#298hendrikmuhs merged 23 commits intoKeyviDev:masterfrom
Conversation
04bea4e to
e804a8f
Compare
|
|
||
| // de-duplicate | ||
| while (data->last_result.GetMatchedString() == data->results.back().GetMatchedString()) { | ||
| while (data->last_result && data->last_result->GetMatchedString() == data->results.back()->GetMatchedString()) { |
There was a problem hiding this comment.
you have slightly different conventions: here you explicitly check for == nullptr but now you're just using operator bool for last_result. Since obj in the first case and last_result in this case are both of type match_t, I'm not sure whether there's a reason you're doing it different ways.
Co-authored-by: George Mossessian <gmossessian@gmail.com>
narekgharibyan
left a comment
There was a problem hiding this comment.
Had a quick pass, and I see that in most of cases std::move is used, which makes me think that almost always we have single ownership instead of shared ownership.
So maybe we better use unique_ptr<Match> to enforce this semantics ?
Or we really need the shared_ptr<> ?
fwiw, unique_ptr<> is more lightweight compared to shared_ptr<>
We have single ownership within keyvi everywhere. However I think this is more a question for the client that is using it:
Conceptually no, However autowrap(python) heavily uses |
|
I tried With other words: the match iterator requires:
The above is needed when accessing the current object in an iterator. |
|
Okie-dokie, thanks @hendrikmuhs for giving it a try ...
So we are "sharing" the Not sure if we have to, prob we can overcome this obstacle later on if we want to. Another alternative idea I had is to not use pointers at all, and just delete copy constructor/assignment for Match and just let it be moved ... but again this is something for the future. Again, thanks for giving it a try. |
That's what I tried 1st and I couldn't overcome some compile errors. As far as I remember similar issues regarding the match iterator. |
|
Does it stem from As if I think about it, theoretically at least we should not need the copy, we should be able to move it ... as it is just a one off data transfer object, or I'm missing something ? 🤔 |
|
I don't remember all the details, |
|
Okie, thanks. ... will keep this in mind. |
refactor matches to be returned as shared pointers with the intention to further modernize the code, remove some quirks with copy/assignment and avoid copying match objects in various places.
This avoids 1 deep-copy for every match in the python extension as well as copies when creating the match iterator.