> On Oct. 13, 2017, 7:06 p.m., Benjamin Mahler wrote: > > Ship It! > > Benjamin Mahler wrote: > I couldn't figure out where std::vector documents this optimization, so I > avoided declaring this was an optimization in favor of saying that this > allows for optimization if the vector implementation leverages the distance > provided when the iterator is a `RandomAcesssIterator`. Let me know if this > is inaccurate!
It is required by the C++ standard, that when such constructor is used, then only N calls to copy constructor are made, and no relocations are performed, provided forward/bidirectional/random access iterators are used (see http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf, section 23.3.6.2, clause 10). The original code, however, does what second part of the clause says about input iterators - O(N) copies and O(log(N)) relocations. - Dmitry ----------------------------------------------------------- This is an automatically generated e-mail. To reply, visit: https://reviews.apache.org/r/62973/#review187998 ----------------------------------------------------------- On Oct. 13, 2017, 1:20 p.m., Dmitry Zhuk wrote: > > ----------------------------------------------------------- > This is an automatically generated e-mail. To reply, visit: > https://reviews.apache.org/r/62973/ > ----------------------------------------------------------- > > (Updated Oct. 13, 2017, 1:20 p.m.) > > > Review request for mesos and Benjamin Mahler. > > > Repository: mesos > > > Description > ------- > > `vector` can take advantage of `RepeatedPtrField` iterators implementing > `RandomAccessIterator` concept and avoid buffer resizes, when > constructed from range. > > > Diffs > ----- > > 3rdparty/libprocess/include/process/protobuf.hpp > 808b385efb49e6e76919ed87c626b29c3e01bdaf > > > Diff: https://reviews.apache.org/r/62973/diff/1/ > > > Testing > ------- > > make check > > > Thanks, > > Dmitry Zhuk > >