Skip to content

Commit

Permalink
Use boost::circular_buffer:
Browse files Browse the repository at this point in the history
The existing code used std::deque along with a size check to constrain the
size of a buffer and, effectively, "hand rolled" a circular buffer. This
change simply migrates directly to boost::circular_buffer.
  • Loading branch information
nbougalis authored and manojsdoshi committed May 27, 2020
1 parent 9f91870 commit 3936110
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
8 changes: 0 additions & 8 deletions src/ripple/overlay/impl/PeerImp.cpp
Expand Up @@ -1961,9 +1961,6 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMHaveTransactionSet> const& m)
return;
}

if (recentTxSets_.size() == 128)
recentTxSets_.pop_front();

recentTxSets_.push_back(hash);
}
}
Expand Down Expand Up @@ -2324,11 +2321,6 @@ PeerImp::addLedger(
recentLedgers_.end())
return;

// VFALCO TODO See if a sorted vector would be better.

if (recentLedgers_.size() == 128)
recentLedgers_.pop_front();

recentLedgers_.push_back(hash);
}

Expand Down
16 changes: 3 additions & 13 deletions src/ripple/overlay/impl/PeerImp.h
Expand Up @@ -37,7 +37,6 @@
#include <boost/endian/conversion.hpp>
#include <boost/optional.hpp>
#include <cstdint>
#include <deque>
#include <queue>
#include <shared_mutex>

Expand Down Expand Up @@ -134,8 +133,9 @@ class PeerImp : public Peer,
LedgerIndex maxLedger_ = 0;
uint256 closedLedgerHash_;
uint256 previousLedgerHash_;
std::deque<uint256> recentLedgers_;
std::deque<uint256> recentTxSets_;

boost::circular_buffer<uint256> recentLedgers_{128};
boost::circular_buffer<uint256> recentTxSets_{128};

boost::optional<std::chrono::milliseconds> latency_;
boost::optional<std::uint32_t> lastPingSeq_;
Expand Down Expand Up @@ -495,13 +495,6 @@ class PeerImp : public Peer,
//
//--------------------------------------------------------------------------

static error_code
invalid_argument_error()
{
return boost::system::errc::make_error_code(
boost::system::errc::invalid_argument);
}

void
onMessageUnknown(std::uint16_t type);

Expand Down Expand Up @@ -565,9 +558,6 @@ class PeerImp : public Peer,
}

//--------------------------------------------------------------------------
void
setLedgerState();

// lockedRecentLock is passed as a reminder to callers that recentLock_
// must be locked.
void
Expand Down

0 comments on commit 3936110

Please sign in to comment.