[PATCH] Add empty() to atom_collection.

Rui Ueyama ruiu at google.com
Thu Apr 3 11:43:06 PDT 2014


Hi Bigcheese, shankarke, kledzik,

"x.empty()" is more idiomatic than "x.size() == 0". This patch is to
add such method and use it in LLD.

http://llvm-reviews.chandlerc.com/D3279

Files:
  include/lld/Core/File.h
  lib/Core/Resolver.cpp
  lib/ReaderWriter/PECOFF/IdataPass.cpp

Index: include/lld/Core/File.h
===================================================================
--- include/lld/Core/File.h
+++ include/lld/Core/File.h
@@ -105,6 +105,7 @@
     virtual const T *deref(const void *it) const = 0;
     virtual void next(const void *&it) const = 0;
     virtual uint64_t size() const = 0;
+    bool empty() const { return size() == 0; }
   };
 
   /// \brief The class is the iterator type used to iterate through a File's
Index: lib/Core/Resolver.cpp
===================================================================
--- lib/Core/Resolver.cpp
+++ lib/Core/Resolver.cpp
@@ -78,7 +78,7 @@
 
   if (!sharedLibraryFile ||
       _context.addUndefinedAtomsFromSharedLibrary(sharedLibraryFile)) {
-    progress = (file.undefined().size() > 0);
+    progress = !file.undefined().empty();
 
     for (const UndefinedAtom *undefAtom : file.undefined()) {
       doUndefinedAtom(*undefAtom);
@@ -101,8 +101,8 @@
 
   // If we make some progress on linking, notify that fact to the input file
   // manager, because it may want to know that for --start-group/end-group.
-  progress = progress || file.sharedLibrary().size() ||
-             file.absolute().size() || file.defined().size();
+  progress = progress || !file.sharedLibrary().empty() ||
+      !file.absolute().empty() || !file.defined().empty();
   if (progress) {
     _context.inputGraph().notifyProgress();
   }
Index: lib/ReaderWriter/PECOFF/IdataPass.cpp
===================================================================
--- lib/ReaderWriter/PECOFF/IdataPass.cpp
+++ lib/ReaderWriter/PECOFF/IdataPass.cpp
@@ -111,7 +111,7 @@
 } // namespace idata
 
 void IdataPass::perform(std::unique_ptr<MutableFile> &file) {
-  if (file->sharedLibrary().size() == 0)
+  if (file->sharedLibrary().empty())
     return;
 
   idata::Context context(*file, _dummyFile);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3279.1.patch
Type: text/x-patch
Size: 1847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140403/284ad065/attachment.bin>


More information about the llvm-commits mailing list