Avoid string duplication when returning StringBuilder strings

The const-ref result of .str() must be copied into the returned
value, whereas the result of .Release() can be moved.

Bug: webrtc:374845009
Change-Id: I3abc98be30ce9947127c7664f5ffa6846b772ea2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/366480
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43288}
This commit is contained in:
Tom Sepez 2024-10-22 19:42:24 +00:00 committed by WebRTC LUCI CQ
parent b7cac14fd4
commit 7085a884aa
5 changed files with 7 additions and 8 deletions

View File

@ -181,7 +181,7 @@ std::string SdpVideoFormat::ToString() const {
builder << "]";
}
return builder.str();
return builder.Release();
}
bool SdpVideoFormat::IsSameCodec(const SdpVideoFormat& other) const {

View File

@ -90,6 +90,6 @@ std::string ForwardTsnChunk::ToString() const {
for (const auto& skipped : skipped_streams()) {
sb << ", skip " << skipped.stream_id.value() << ":" << *skipped.ssn;
}
return sb.str();
return sb.Release();
}
} // namespace dcsctp

View File

@ -894,7 +894,7 @@ void Connection::PrintPingsSinceLastResponse(std::string* s, size_t max) {
oss << rtc::hex_encode(ping.id) << " ";
}
}
*s = oss.str();
*s = oss.Release();
}
bool Connection::selected() const {

View File

@ -196,7 +196,7 @@ std::string SimulcastSdpSerializer::SerializeSimulcastDescription(
<< simulcast.receive_layers();
}
return sb.str();
return sb.Release();
}
// https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-13#section-5.1
@ -305,7 +305,7 @@ std::string SimulcastSdpSerializer::SerializeRidDescription(
propertyDelimiter = kDelimiterSemicolon;
}
return builder.str();
return builder.Release();
}
// https://tools.ietf.org/html/draft-ietf-mmusic-rid-15#section-10

View File

@ -804,7 +804,7 @@ static void GetDefaultDestination(const std::vector<Candidate>& candidates,
// Gets "a=rtcp" line if found default RTCP candidate from `candidates`.
static std::string GetRtcpLine(const std::vector<Candidate>& candidates) {
std::string rtcp_line, rtcp_port, rtcp_ip, addr_type;
std::string rtcp_port, rtcp_ip, addr_type;
GetDefaultDestination(candidates, ICE_CANDIDATE_COMPONENT_RTCP, &rtcp_port,
&rtcp_ip, &addr_type);
// Found default RTCP candidate.
@ -819,8 +819,7 @@ static std::string GetRtcpLine(const std::vector<Candidate>& candidates) {
InitAttrLine(kAttributeRtcp, &os);
os << kSdpDelimiterColon << rtcp_port << " " << kConnectionNettype << " "
<< addr_type << " " << rtcp_ip;
rtcp_line = os.str();
return rtcp_line;
return os.Release();
}
// Get candidates according to the mline index from SessionDescriptionInterface.