Closed Bug 1387376 Opened 7 years ago Closed 7 years ago

Reserve memory before using push_back with vector

Categories

(Developer Infrastructure :: Source Code Analysis, enhancement)

enhancement
Not set
normal

Tracking

(firefox57 fixed)

RESOLVED FIXED
mozilla57
Tracking Status
firefox57 --- fixed

People

(Reporter: Sylvestre, Assigned: Sylvestre)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

Summary: Reserve memory before using push_back in vector → Reserve memory before using push_back with vector
Comment on attachment 8893723 [details]
Bug 1387376 - Reserve memory before using push_back with vector

https://reviewboard.mozilla.org/r/164838/#review170392

::: media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp:559
(Diff revision 1)
>      std::vector<std::string> attrs;
> +    attrs.reserve(aCandidateList.size());
>      for (const auto& candidate : aCandidateList) {
>        attrs.push_back("candidate:" + candidate);
>      }
>      attrs.push_back("ice-ufrag:" + aUfrag);
>      attrs.push_back("ice-pwd:" + aPassword);

Should be size() + 2 (see following lines).  r+ with that change
Attachment #8893723 - Flags: review?(rjesup) → review+
Comment on attachment 8893722 [details]
Bug 1387376 - Reserve memory before using push_back with vector

https://reviewboard.mozilla.org/r/164836/#review170702

It isn't useful to do this in gtests. This code isn't built into firefox and the change will not affect the time we spend running the tests. I don't really care either way. If this is reported by some static analysis and doing this removes noise from the analysis output, then why not. Otherwise, you don't need to bother with fine tuning the performance of loops that are only ever run once in gtests.
Attachment #8893722 - Flags: review?(nical.bugzilla) → review+
Comment on attachment 8893722 [details]
Bug 1387376 - Reserve memory before using push_back with vector

https://reviewboard.mozilla.org/r/164836/#review170702

Yeah, this is just to make clang-tidy happy and not bother with ignoring that warning.
Pushed by sledru@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/d0352fcfda33
Reserve memory before using push_back with vector r=nical
https://hg.mozilla.org/integration/autoland/rev/f35d46bca9a9
Reserve memory before using push_back with vector r=jesup
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: