Make MultiFrame pointer instead of ref inside impl of iterators

This commit is contained in:
jeremy 2022-12-09 12:20:01 +01:00
parent 0353262cc2
commit 50f76b926b
2 changed files with 20 additions and 20 deletions

View File

@ -69,7 +69,7 @@ ValidFramesConsumer MultiFrame::GetValidFramesConsumer() { return ValidFramesCon
InvalidFramesPopulator MultiFrame::GetInvalidFramesPopulator() { return InvalidFramesPopulator{*this}; } InvalidFramesPopulator MultiFrame::GetInvalidFramesPopulator() { return InvalidFramesPopulator{*this}; }
ValidFramesReader::ValidFramesReader(MultiFrame &multiframe) : multiframe_(multiframe) { ValidFramesReader::ValidFramesReader(MultiFrame &multiframe) : multiframe_(&multiframe) {
/* /*
From: https://en.cppreference.com/w/cpp/algorithm/find From: https://en.cppreference.com/w/cpp/algorithm/find
Returns an iterator to the first element in the range [first, last) that satisfies specific criteria: Returns an iterator to the first element in the range [first, last) that satisfies specific criteria:
@ -81,55 +81,55 @@ ValidFramesReader::ValidFramesReader(MultiFrame &multiframe) : multiframe_(multi
*/ */
auto it = std::find_if(multiframe.frames_.begin(), multiframe.frames_.end(), auto it = std::find_if(multiframe.frames_.begin(), multiframe.frames_.end(),
[](const auto &frame) { return !frame.IsValid(); }); [](const auto &frame) { return !frame.IsValid(); });
after_last_valid_frame_ = multiframe_.frames_.data() + std::distance(multiframe.frames_.begin(), it); after_last_valid_frame_ = multiframe_->frames_.data() + std::distance(multiframe.frames_.begin(), it);
} }
ValidFramesReader::Iterator ValidFramesReader::begin() { ValidFramesReader::Iterator ValidFramesReader::begin() {
if (multiframe_.frames_[0].IsValid()) { if (multiframe_->frames_[0].IsValid()) {
return Iterator{&multiframe_.frames_[0]}; return Iterator{&multiframe_->frames_[0]};
} }
return end(); return end();
} }
ValidFramesReader::Iterator ValidFramesReader::end() { return Iterator{after_last_valid_frame_}; } ValidFramesReader::Iterator ValidFramesReader::end() { return Iterator{after_last_valid_frame_}; }
ValidFramesModifier::ValidFramesModifier(MultiFrame &multiframe) : multiframe_(multiframe) {} ValidFramesModifier::ValidFramesModifier(MultiFrame &multiframe) : multiframe_(&multiframe) {}
ValidFramesModifier::Iterator ValidFramesModifier::begin() { ValidFramesModifier::Iterator ValidFramesModifier::begin() {
if (multiframe_.frames_[0].IsValid()) { if (multiframe_->frames_[0].IsValid()) {
return Iterator{&multiframe_.frames_[0], *this}; return Iterator{&multiframe_->frames_[0], *this};
} }
return end(); return end();
} }
ValidFramesModifier::Iterator ValidFramesModifier::end() { ValidFramesModifier::Iterator ValidFramesModifier::end() {
return Iterator{multiframe_.frames_.data() + multiframe_.frames_.size(), *this}; return Iterator{multiframe_->frames_.data() + multiframe_->frames_.size(), *this};
} }
ValidFramesConsumer::ValidFramesConsumer(MultiFrame &multiframe) : multiframe_(multiframe) {} ValidFramesConsumer::ValidFramesConsumer(MultiFrame &multiframe) : multiframe_(&multiframe) {}
// NOLINTNEXTLINE (bugprone-exception-escape) // NOLINTNEXTLINE (bugprone-exception-escape)
ValidFramesConsumer::~ValidFramesConsumer() noexcept { ValidFramesConsumer::~ValidFramesConsumer() noexcept {
// TODO Possible optimisation: only DefragmentValidFrames if one frame has been invalidated? Only if does not // TODO Possible optimisation: only DefragmentValidFrames if one frame has been invalidated? Only if does not
// cost too much to store it // cost too much to store it
multiframe_.DefragmentValidFrames(); multiframe_->DefragmentValidFrames();
} }
ValidFramesConsumer::Iterator ValidFramesConsumer::begin() { ValidFramesConsumer::Iterator ValidFramesConsumer::begin() {
if (multiframe_.frames_[0].IsValid()) { if (multiframe_->frames_[0].IsValid()) {
return Iterator{&multiframe_.frames_[0], *this}; return Iterator{&multiframe_->frames_[0], *this};
} }
return end(); return end();
} }
ValidFramesConsumer::Iterator ValidFramesConsumer::end() { ValidFramesConsumer::Iterator ValidFramesConsumer::end() {
return Iterator{multiframe_.frames_.data() + multiframe_.frames_.size(), *this}; return Iterator{multiframe_->frames_.data() + multiframe_->frames_.size(), *this};
} }
InvalidFramesPopulator::InvalidFramesPopulator(MultiFrame &multiframe) : multiframe_(multiframe) {} InvalidFramesPopulator::InvalidFramesPopulator(MultiFrame &multiframe) : multiframe_(&multiframe) {}
InvalidFramesPopulator::Iterator InvalidFramesPopulator::begin() { InvalidFramesPopulator::Iterator InvalidFramesPopulator::begin() {
for (auto &frame : multiframe_.frames_) { for (auto &frame : multiframe_->frames_) {
if (!frame.IsValid()) { if (!frame.IsValid()) {
return Iterator{&frame}; return Iterator{&frame};
} }
@ -138,7 +138,7 @@ InvalidFramesPopulator::Iterator InvalidFramesPopulator::begin() {
} }
InvalidFramesPopulator::Iterator InvalidFramesPopulator::end() { InvalidFramesPopulator::Iterator InvalidFramesPopulator::end() {
return Iterator{multiframe_.frames_.data() + multiframe_.frames_.size()}; return Iterator{multiframe_->frames_.data() + multiframe_->frames_.size()};
} }
} // namespace memgraph::query::v2 } // namespace memgraph::query::v2

View File

@ -137,7 +137,7 @@ class ValidFramesReader {
private: private:
FrameWithValidity *after_last_valid_frame_; FrameWithValidity *after_last_valid_frame_;
MultiFrame &multiframe_; MultiFrame *multiframe_;
}; };
class ValidFramesModifier { class ValidFramesModifier {
@ -192,7 +192,7 @@ class ValidFramesModifier {
Iterator end(); Iterator end();
private: private:
MultiFrame &multiframe_; MultiFrame *multiframe_;
}; };
class ValidFramesConsumer { class ValidFramesConsumer {
@ -246,7 +246,7 @@ class ValidFramesConsumer {
Iterator end(); Iterator end();
private: private:
MultiFrame &multiframe_; MultiFrame *multiframe_;
}; };
class InvalidFramesPopulator { class InvalidFramesPopulator {
@ -296,7 +296,7 @@ class InvalidFramesPopulator {
Iterator end(); Iterator end();
private: private:
MultiFrame &multiframe_; MultiFrame *multiframe_;
}; };
} // namespace memgraph::query::v2 } // namespace memgraph::query::v2