[lld] r182033 - [lld] Do not create a temporary pair.

Reid Kleckner rnk at google.com
Thu May 16 11:41:55 PDT 2013


I don't know what the lld zeitgeist is on out-params, but if they prefer to
return pairs, you can use llvm::tie():
Elf_Phdr *phdr;
bool allocatedNew;
llvm::tie(phdr, allocatedNew) = thingReturningPair();


On Thu, May 16, 2013 at 1:58 PM, Rui Ueyama <ruiu at google.com> wrote:

> Author: ruiu
> Date: Thu May 16 12:58:14 2013
> New Revision: 182033
>
> URL: http://llvm.org/viewvc/llvm-project?rev=182033&view=rev
> Log:
> [lld] Do not create a temporary pair.
>
> Modified:
>     lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h?rev=182033&r1=182032&r2=182033&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h Thu May 16 12:58:14 2013
> @@ -163,20 +163,18 @@ public:
>    }
>
>  private:
> -  std::pair<Elf_Phdr *, bool> allocateProgramHeader() {
> +  Elf_Phdr *allocateProgramHeader(bool &allocatedNew) {
>      Elf_Phdr *phdr;
> -    bool ret = false;
>      if (_phi == _ph.end()) {
>        phdr = new (_allocator) Elf_Phdr;
>        _ph.push_back(phdr);
>        _phi = _ph.end();
> -      ret = true;
> +      allocatedNew = true;
>      } else {
>        phdr = (*_phi);
>        ++_phi;
>      }
> -
> -    return std::make_pair(phdr, ret);
> +    return phdr;
>    }
>
>    std::vector<Elf_Phdr *> _ph;
> @@ -191,17 +189,15 @@ bool ProgramHeader<ELFT>::addSegment(Seg
>    // just pick the values directly from the segment as there
>    // wouldnt be any slices within that
>    if (segment->segmentType() != llvm::ELF::PT_LOAD) {
> -    auto phdr = allocateProgramHeader();
> -    if (phdr.second)
> -      allocatedNew = true;
> -    phdr.first->p_type = segment->segmentType();
> -    phdr.first->p_offset = segment->fileOffset();
> -    phdr.first->p_vaddr = segment->virtualAddr();
> -    phdr.first->p_paddr = segment->virtualAddr();
> -    phdr.first->p_filesz = segment->fileSize();
> -    phdr.first->p_memsz = segment->memSize();
> -    phdr.first->p_flags = segment->flags();
> -    phdr.first->p_align = segment->align2();
> +    Elf_Phdr *phdr = allocateProgramHeader(allocatedNew);
> +    phdr->p_type = segment->segmentType();
> +    phdr->p_offset = segment->fileOffset();
> +    phdr->p_vaddr = segment->virtualAddr();
> +    phdr->p_paddr = segment->virtualAddr();
> +    phdr->p_filesz = segment->fileSize();
> +    phdr->p_memsz = segment->memSize();
> +    phdr->p_flags = segment->flags();
> +    phdr->p_align = segment->align2();
>      this->_fsize = fileSize();
>      this->_msize = this->_fsize;
>      return allocatedNew;
> @@ -209,17 +205,15 @@ bool ProgramHeader<ELFT>::addSegment(Seg
>    // For all other segments, use the slice
>    // to derive program headers
>    for (auto slice : segment->slices()) {
> -    auto phdr = allocateProgramHeader();
> -    if (phdr.second)
> -      allocatedNew = true;
> -    phdr.first->p_type = segment->segmentType();
> -    phdr.first->p_offset = slice->fileOffset();
> -    phdr.first->p_vaddr = slice->virtualAddr();
> -    phdr.first->p_paddr = slice->virtualAddr();
> -    phdr.first->p_filesz = slice->fileSize();
> -    phdr.first->p_memsz = slice->memSize();
> -    phdr.first->p_flags = segment->flags();
> -    phdr.first->p_align = (phdr.first->p_type == llvm::ELF::PT_LOAD) ?
> +    Elf_Phdr *phdr = allocateProgramHeader(allocatedNew);
> +    phdr->p_type = segment->segmentType();
> +    phdr->p_offset = slice->fileOffset();
> +    phdr->p_vaddr = slice->virtualAddr();
> +    phdr->p_paddr = slice->virtualAddr();
> +    phdr->p_filesz = slice->fileSize();
> +    phdr->p_memsz = slice->memSize();
> +    phdr->p_flags = segment->flags();
> +    phdr->p_align = (phdr->p_type == llvm::ELF::PT_LOAD) ?
>                            segment->pageSize() : slice->align2();
>    }
>    this->_fsize = fileSize();
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130516/783e4a55/attachment.html>


More information about the llvm-commits mailing list