[lld] r234436 - vec.data() and vec.data() + vec.size() are both safe even if the vector is empty.

Rui Ueyama ruiu at google.com
Wed Apr 8 14:13:23 PDT 2015


Author: ruiu
Date: Wed Apr  8 16:13:23 2015
New Revision: 234436

URL: http://llvm.org/viewvc/llvm-project?rev=234436&view=rev
Log:
vec.data() and vec.data() + vec.size() are both safe even if the vector is empty.

Modified:
    lld/trunk/include/lld/Core/File.h

Modified: lld/trunk/include/lld/Core/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/File.h?rev=234436&r1=234435&r2=234436&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/File.h (original)
+++ lld/trunk/include/lld/Core/File.h Wed Apr  8 16:13:23 2015
@@ -199,14 +199,12 @@ protected:
   class atom_collection_vector : public atom_collection<T> {
   public:
     atom_iterator<T> begin() const override {
-      auto *it = _atoms.empty() ? nullptr
-                                : reinterpret_cast<const void *>(_atoms.data());
+      const void *it = _atoms.data();
       return atom_iterator<T>(*this, it);
     }
 
     atom_iterator<T> end() const override {
-      auto *it = _atoms.empty() ? nullptr : reinterpret_cast<const void *>(
-                                                _atoms.data() + _atoms.size());
+      const void *it = _atoms.data() + _atoms.size();
       return atom_iterator<T>(*this, it);
     }
 





More information about the llvm-commits mailing list