Avoid an allocate/copy/free

This commit is contained in:
JoelKatz
2012-10-29 18:24:09 -07:00
parent ca404beef7
commit 74629254a5
2 changed files with 8 additions and 8 deletions

View File

@@ -538,8 +538,8 @@ void Peer::processReadBuffer()
case ripple::mtVALIDATION:
{
ripple::TMValidation msg;
if (msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE))
boost::shared_ptr<ripple::TMValidation> msg = boost::make_shared<ripple::TMValidation>();
if (msg->ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE))
recvValidation(msg);
else
cLog(lsWARNING) << "parse error: " << type;
@@ -773,7 +773,7 @@ void Peer::recvHaveTxSet(ripple::TMHaveTransactionSet& packet)
}
static void checkValidation(Job&, SerializedValidation::pointer val, uint256 signingHash,
bool isTrusted, ripple::TMValidation packet, boost::weak_ptr<Peer> peer)
bool isTrusted, boost::shared_ptr<ripple::TMValidation> packet, boost::weak_ptr<Peer> peer)
{
#ifndef TRUST_NETWORK
try
@@ -789,7 +789,7 @@ static void checkValidation(Job&, SerializedValidation::pointer val, uint256 sig
if (theApp->getOPs().recvValidation(val))
{
Peer::pointer pp = peer.lock();
PackedMessage::pointer message = boost::make_shared<PackedMessage>(packet, ripple::mtVALIDATION);
PackedMessage::pointer message = boost::make_shared<PackedMessage>(*packet, ripple::mtVALIDATION);
theApp->getConnectionPool().relayMessage(pp ? pp.get() : NULL, message);
}
}
@@ -802,9 +802,9 @@ static void checkValidation(Job&, SerializedValidation::pointer val, uint256 sig
#endif
}
void Peer::recvValidation(ripple::TMValidation& packet)
void Peer::recvValidation(const boost::shared_ptr<ripple::TMValidation>& packet)
{
if (packet.validation().size() < 50)
if (packet->validation().size() < 50)
{
cLog(lsWARNING) << "Too small validation from peer";
punishPeer(PP_UNKNOWN_REQUEST);
@@ -815,7 +815,7 @@ void Peer::recvValidation(ripple::TMValidation& packet)
try
#endif
{
Serializer s(packet.validation());
Serializer s(packet->validation());
SerializerIterator sit(s);
SerializedValidation::pointer val = boost::make_shared<SerializedValidation>(boost::ref(sit), false);

View File

@@ -96,7 +96,7 @@ protected:
void recvHello(ripple::TMHello& packet);
void recvTransaction(ripple::TMTransaction& packet);
void recvValidation(ripple::TMValidation& packet);
void recvValidation(const boost::shared_ptr<ripple::TMValidation>& packet);
void recvGetValidation(ripple::TMGetValidations& packet);
void recvContact(ripple::TMContact& packet);
void recvGetContacts(ripple::TMGetContacts& packet);