message_parsers: Use const reference where possible
The code was passing std::shared_ptr<xxx> by value (or const value),
which creates unnecessary copies of shared_ptr.
Use `const std::shared_ptr<xxx>&` where possible to eliminate such
copies.
Tested: No code logic changes. Verify the build passes and the net-ipmid
is working as before.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: Iad6c3b209ab8299fa477784e86c22be19f98a344
diff --git a/message_parsers.cpp b/message_parsers.cpp
index 9c7218c..e5e9721 100644
--- a/message_parsers.cpp
+++ b/message_parsers.cpp
@@ -66,9 +66,9 @@
}
}
-std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
+std::vector<uint8_t> flatten(const std::shared_ptr<Message>& outMessage,
SessionHeader authType,
- std::shared_ptr<session::Session> session)
+ const std::shared_ptr<session::Session>& session)
{
// Call the flatten routine based on the header type
switch (authType)
@@ -133,8 +133,8 @@
return message;
}
-std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
- std::shared_ptr<session::Session> session)
+std::vector<uint8_t> flatten(const std::shared_ptr<Message>& outMessage,
+ const std::shared_ptr<session::Session>& session)
{
std::vector<uint8_t> packet(sizeof(SessionHeader_t));
@@ -244,8 +244,8 @@
return message;
}
-std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
- std::shared_ptr<session::Session> session)
+std::vector<uint8_t> flatten(const std::shared_ptr<Message>& outMessage,
+ const std::shared_ptr<session::Session>& session)
{
std::vector<uint8_t> packet(sizeof(SessionHeader_t));
@@ -300,7 +300,7 @@
{
void addSequenceNumber(std::vector<uint8_t>& packet,
- std::shared_ptr<session::Session> session)
+ const std::shared_ptr<session::Session>& session)
{
SessionHeader_t* header = reinterpret_cast<SessionHeader_t*>(packet.data());
@@ -316,7 +316,7 @@
}
bool verifyPacketIntegrity(const std::vector<uint8_t>& packet,
- const std::shared_ptr<Message> message,
+ const std::shared_ptr<Message>& message,
size_t payloadLen,
const std::shared_ptr<session::Session>& session)
{
@@ -369,7 +369,8 @@
}
void addIntegrityData(std::vector<uint8_t>& packet,
- const std::shared_ptr<Message> message, size_t payloadLen,
+ const std::shared_ptr<Message>& message,
+ size_t payloadLen,
const std::shared_ptr<session::Session>& session)
{
// The following logic calculates the number of padding bytes to be added to
@@ -393,7 +394,7 @@
std::vector<uint8_t>
decryptPayload(const std::vector<uint8_t>& packet,
- const std::shared_ptr<Message> message, size_t payloadLen,
+ const std::shared_ptr<Message>& message, size_t payloadLen,
const std::shared_ptr<session::Session>& session)
{
return session->getCryptAlgo()->decryptPayload(
@@ -401,7 +402,7 @@
}
std::vector<uint8_t>
- encryptPayload(std::shared_ptr<Message> message,
+ encryptPayload(const std::shared_ptr<Message>& message,
const std::shared_ptr<session::Session>& session)
{
return session->getCryptAlgo()->encryptPayload(message->payload);
diff --git a/message_parsers.hpp b/message_parsers.hpp
index a992e0a..d6069cc 100644
--- a/message_parsers.hpp
+++ b/message_parsers.hpp
@@ -94,9 +94,9 @@
*
* @return IPMI packet on success
*/
-std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
+std::vector<uint8_t> flatten(const std::shared_ptr<Message>& outMessage,
SessionHeader authType,
- std::shared_ptr<session::Session> session);
+ const std::shared_ptr<session::Session>& session);
} // namespace parser
@@ -134,8 +134,8 @@
*
* @return IPMI packet on success
*/
-std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
- std::shared_ptr<session::Session> session);
+std::vector<uint8_t> flatten(const std::shared_ptr<Message>& outMessage,
+ const std::shared_ptr<session::Session>& session);
} // namespace ipmi15parser
@@ -182,8 +182,8 @@
*
* @return IPMI packet on success
*/
-std::vector<uint8_t> flatten(std::shared_ptr<Message> outMessage,
- std::shared_ptr<session::Session> session);
+std::vector<uint8_t> flatten(const std::shared_ptr<Message>& outMessage,
+ const std::shared_ptr<session::Session>& session);
namespace internal
{
@@ -196,7 +196,7 @@
*
*/
void addSequenceNumber(std::vector<uint8_t>& packet,
- std::shared_ptr<session::Session> session);
+ const std::shared_ptr<session::Session>& session);
/**
* @brief Verify the integrity data of the incoming IPMI packet
@@ -208,7 +208,7 @@
*
*/
bool verifyPacketIntegrity(const std::vector<uint8_t>& packet,
- const std::shared_ptr<Message> message,
+ const std::shared_ptr<Message>& message,
size_t payloadLen,
const std::shared_ptr<session::Session>& session);
@@ -220,7 +220,8 @@
* @param[in] payloadLen - Length of the IPMI payload
*/
void addIntegrityData(std::vector<uint8_t>& packet,
- const std::shared_ptr<Message> message, size_t payloadLen,
+ const std::shared_ptr<Message>& message,
+ size_t payloadLen,
const std::shared_ptr<session::Session>& session);
/**
@@ -235,7 +236,7 @@
*/
std::vector<uint8_t>
decryptPayload(const std::vector<uint8_t>& packet,
- const std::shared_ptr<Message> message, size_t payloadLen,
+ const std::shared_ptr<Message>& message, size_t payloadLen,
const std::shared_ptr<session::Session>& session);
/**
@@ -247,7 +248,7 @@
* @return on successful completion, return the encrypted payload
*/
std::vector<uint8_t>
- encryptPayload(std::shared_ptr<Message> message,
+ encryptPayload(const std::shared_ptr<Message>& message,
const std::shared_ptr<session::Session>& session);
} // namespace internal