[lld] r329107 - Instead of using std::copy, clear the vector first and add new elements. NFC.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 14:48:28 PDT 2018


Rui Ueyama via llvm-commits <llvm-commits at lists.llvm.org> writes:

> +  ISD->Sections.clear();
> +  for (InputSection *IS : makeArrayRef(UnorderedSections).slice(0, InsPt))
> +    ISD->Sections.push_back(IS);
>    for (std::pair<InputSection *, int> P : OrderedSections)
> -    *SectionsPos++ = P.first;
> -  std::copy(UnorderedSections.begin() + UnorderedInsPt, UnorderedSections.end(),
> -            SectionsPos);
> +    ISD->Sections.push_back(P.first);
> +  for (InputSection *IS : makeArrayRef(UnorderedSections).slice(InsPt))
> +    ISD->Sections.push_back(IS);

The first and last loops could use llvm::copy:

  auto Back = std::back_inserter(ISD->Sections);
  llvm::copy(makeArrayRef(UnorderedSections).slice(0, InsPt), Back);
  for (std::pair<InputSection *, int> P : OrderedSections)
    ISD->Sections.push_back(P.first);
  llvm::copy(makeArrayRef(UnorderedSections).slice(InsPt), Back);

Cheers,
Rafael


More information about the llvm-commits mailing list