[lld] r255870 - ELF: Avoid string concatenation if there's no error.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 14:05:46 PST 2015


error takes a Twine. Was this really computing a concatenated string?

Cheers,
Rafael


On 16 December 2015 at 20:51, Rui Ueyama via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: ruiu
> Date: Wed Dec 16 19:51:23 2015
> New Revision: 255870
>
> URL: http://llvm.org/viewvc/llvm-project?rev=255870&view=rev
> Log:
> ELF: Avoid string concatenation if there's no error.
>
> Modified:
>     lld/trunk/ELF/InputFiles.cpp
>
> Modified: lld/trunk/ELF/InputFiles.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=255870&r1=255869&r2=255870&view=diff
> ==============================================================================
> --- lld/trunk/ELF/InputFiles.cpp (original)
> +++ lld/trunk/ELF/InputFiles.cpp Wed Dec 16 19:51:23 2015
> @@ -318,10 +318,11 @@ MemoryBufferRef ArchiveFile::getMember(c
>    if (!Seen.insert(C.getChildOffset()).second)
>      return MemoryBufferRef();
>
> -  ErrorOr<MemoryBufferRef> Ret = C.getMemoryBufferRef();
> -  error(Ret, "Could not get the buffer for the member defining symbol " +
> -                 Sym->getName());
> -  return *Ret;
> +  ErrorOr<MemoryBufferRef> RefOrErr = C.getMemoryBufferRef();
> +  if (!RefOrErr)
> +    error(RefOrErr, "Could not get the buffer for the member defining symbol " +
> +          Sym->getName());
> +  return *RefOrErr;
>  }
>
>  std::vector<MemoryBufferRef> ArchiveFile::getMembers() {
> @@ -333,8 +334,9 @@ std::vector<MemoryBufferRef> ArchiveFile
>            "Could not get the child of the archive " + File->getFileName());
>      const Archive::Child Child(*ChildOrErr);
>      ErrorOr<MemoryBufferRef> MbOrErr = Child.getMemoryBufferRef();
> -    error(MbOrErr, "Could not get the buffer for a child of the archive " +
> -                       File->getFileName());
> +    if (!MbOrErr)
> +      error(MbOrErr, "Could not get the buffer for a child of the archive " +
> +            File->getFileName());
>      Result.push_back(MbOrErr.get());
>    }
>    return Result;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list