Commit a8f674ce authored by Aditya Kumar's avatar Aditya Kumar Committed by Facebook Github Bot

Reducing calls to malloc in AsyncSocket

Summary:
Reduce calls to string::operator+.
Constructing a single string by precalculating the size.

Reviewed By: yfeldblum

Differential Revision: D17573761

fbshipit-source-id: 3918d1774949873fab3ba702d47cdeb80b44ab1d
parent d3f8fa39
......@@ -2897,7 +2897,7 @@ std::ostream& operator<<(
return os;
}
std::string AsyncSocket::withAddr(const std::string& s) {
std::string AsyncSocket::withAddr(folly::StringPiece s) {
// Don't use addr_ directly because it may not be initialized
// e.g. if constructed from fd
folly::SocketAddress peer, local;
......@@ -2915,7 +2915,9 @@ std::string AsyncSocket::withAddr(const std::string& s) {
} catch (...) {
// ignore
}
return s + " (peer=" + peer.describe() + ", local=" + local.describe() + ")";
return folly::to<std::string>(
s, " (peer=", peer.describe(), ", local=", local.describe(), ")");
}
void AsyncSocket::setBufferCallback(BufferCallback* cb) {
......
......@@ -1237,7 +1237,7 @@ class AsyncSocket : virtual public AsyncTransportWrapper {
void invalidState(ReadCallback* callback);
void invalidState(WriteCallback* callback);
std::string withAddr(const std::string& s);
std::string withAddr(folly::StringPiece s);
void cacheLocalAddress() const;
void cachePeerAddress() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment