This is an archive of the discontinued LLVM Phabricator instance.

[Coverage] Avoid unnecessary copying of an std::vector.
ClosedPublic

Authored by ikudrin on Apr 4 2016, 8:07 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

ikudrin updated this revision to Diff 52558.Apr 4 2016, 8:07 AM
ikudrin retitled this revision from to [Coverage] Avoid unnecessary copying of an array. NFC..
ikudrin updated this object.
ikudrin added reviewers: bogner, davidxl.
ikudrin added a subscriber: llvm-commits.

This seems like more than a performance fix - the API itself seems a little
problematic. If buildSegments was called more than once on the same
SegmentBuilder, tehre would be trouble, right? (before this patch, it could
build on top of existing segments - after this patch it will use a
moved-from-vector which might be in some non-empty state (moved from
objects are in a "valid but unspecified" state - I'm not sure there's
anything other than empty that a vector could be in, but it's still a bit
subtle/risky))

Could the API be redesigned so it doesn't have this problem?

vsk added a subscriber: vsk.Apr 4 2016, 10:50 AM

I agree with dblaikie, the API could be a bit cleaner. Wdyt of this:

  1. Have the SegmentBuilder constructor accept a vector<CoverageSegment>&; assert that it's empty.
  2. Replace Segments = SegmentBuilder().buildSegments(...) with SegmentBuilder(Segments).build(...).
ikudrin updated this revision to Diff 52660.Apr 5 2016, 12:09 AM
ikudrin retitled this revision from [Coverage] Avoid unnecessary copying of an array. NFC. to [Coverage] Avoid unnecessary copying of an std::vector..
  • Use NRVO instead of std::move.
  • Prevent unexpected using of SegmentBuilder by making method buildSegments() static.
This revision was automatically updated to reflect the committed changes.