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

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 17:51:24 PST 2015


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;




More information about the llvm-commits mailing list