This is an archive of the discontinued LLVM Phabricator instance.

ADT: Add SmallVectorImpl::truncate() to replace uses of set_size()
ClosedPublic

Authored by dexonsmith on Dec 8 2021, 12:53 PM.

Details

Summary

Add SmallVectorImpl::truncate(), a variant of resize() that cannot
increase the size.

  • Compared to resize(), this has no code path for growing the allocation and can be better optimized.
  • Compared to set_size(), this formally calls destructors, and does not skip any constructors.
  • Compared to pop_back_n(), this takes the new desired size, which in many contexts is more intuitive than the number of elements to remove.

The immediate motivation is to pair this with resize_for_overwrite()
to remove uses of set_size(), which can then be made private.

See also: https://reviews.llvm.org/D115380

Diff Detail

Event Timeline

dexonsmith requested review of this revision.Dec 8 2021, 12:53 PM
dexonsmith created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 8 2021, 12:53 PM
dblaikie accepted this revision.Dec 8 2021, 1:41 PM

Sure, sounds good

This revision is now accepted and ready to land.Dec 8 2021, 1:41 PM
This revision was landed with ongoing or failed builds.Dec 8 2021, 1:57 PM
This revision was automatically updated to reflect the committed changes.