mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Remove ReadViewFwdRange end iterator cache:
ReadViewFwdRange was storing a cached `end_` iterator that was lazily created in an iterators `end()` function. When the cache is empty, and the range it iterated from multiple threads, this creates a race condition. This change has performance consequences for "old style" for loops. For example: ``` // don't do this for(auto i = tx_range.begin(); i != tx_range.end(); ++i) ``` Can call the now expensive `end()` function more often than needed. Range-based for loop (I.e. `for(auto const& t : tx_range)`) should be used instead.
This commit is contained in:
@@ -204,7 +204,7 @@ public:
|
||||
explicit sles_type(ReadView const& view);
|
||||
iterator
|
||||
begin() const;
|
||||
iterator const&
|
||||
iterator
|
||||
end() const;
|
||||
iterator
|
||||
upper_bound(key_type const& key) const;
|
||||
@@ -217,7 +217,7 @@ public:
|
||||
empty() const;
|
||||
iterator
|
||||
begin() const;
|
||||
iterator const&
|
||||
iterator
|
||||
end() const;
|
||||
};
|
||||
|
||||
|
||||
@@ -147,7 +147,6 @@ public:
|
||||
|
||||
protected:
|
||||
ReadView const* view_;
|
||||
boost::optional<iterator> mutable end_;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
@@ -135,11 +135,9 @@ ReadView::sles_type::begin() const -> iterator
|
||||
}
|
||||
|
||||
auto
|
||||
ReadView::sles_type::end() const -> iterator const&
|
||||
ReadView::sles_type::end() const -> iterator
|
||||
{
|
||||
if (!end_)
|
||||
end_ = iterator(view_, view_->slesEnd());
|
||||
return *end_;
|
||||
return iterator(view_, view_->slesEnd());
|
||||
}
|
||||
|
||||
auto
|
||||
@@ -165,11 +163,9 @@ ReadView::txs_type::begin() const -> iterator
|
||||
}
|
||||
|
||||
auto
|
||||
ReadView::txs_type::end() const -> iterator const&
|
||||
ReadView::txs_type::end() const -> iterator
|
||||
{
|
||||
if (!end_)
|
||||
end_ = iterator(view_, view_->txsEnd());
|
||||
return *end_;
|
||||
return iterator(view_, view_->txsEnd());
|
||||
}
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
Reference in New Issue
Block a user