Optimize FindCodecById and ReferencedCodecsMatch
These functions currently copy cricket::Codec classes by value which is
expensive since they contain e.g. std::map<std::string, std::string>
containers with parameters. This CL avoids copying them altogether.
BUG=webrtc:6337
Review-Url: https://codereview.webrtc.org/2493733003
Cr-Commit-Position: refs/heads/master@{#15040}
diff --git a/webrtc/api/webrtcsdp.cc b/webrtc/api/webrtcsdp.cc
index b7ef28e..d78112c 100644
--- a/webrtc/api/webrtcsdp.cc
+++ b/webrtc/api/webrtcsdp.cc
@@ -2438,10 +2438,12 @@
// with that payload type.
template <class T>
T GetCodecWithPayloadType(const std::vector<T>& codecs, int payload_type) {
+ const T* codec = FindCodecById(codecs, payload_type);
+ if (codec)
+ return *codec;
+ // Return empty codec with |payload_type|.
T ret_val;
- if (!FindCodecById(codecs, payload_type, &ret_val)) {
- ret_val.id = payload_type;
- }
+ ret_val.id = payload_type;
return ret_val;
}