Basic: Initialize FileEntry's fields inline, almost NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 10 Dec 2020 21:44:06 +0000 (13:44 -0800)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 10 Dec 2020 21:57:21 +0000 (13:57 -0800)
Initialize most of FileEntry's fields inline (all the ones that can be).
The only functionality change is to avoid leaving some fields
uninitialized.

clang/include/clang/Basic/FileEntry.h
clang/lib/Basic/FileEntry.cpp
clang/unittests/Basic/FileEntryTest.cpp

index 8db5446..aa7bede 100644 (file)
@@ -328,13 +328,13 @@ class FileEntry {
   friend class FileManager;
 
   std::string RealPathName;   // Real path to the file; could be empty.
-  off_t Size;                 // File size in bytes.
-  time_t ModTime;             // Modification time of file.
-  const DirectoryEntry *Dir // Directory file lives in.
+  off_t Size = 0;             // File size in bytes.
+  time_t ModTime = 0;         // Modification time of file.
+  const DirectoryEntry *Dir = nullptr; // Directory file lives in.
   llvm::sys::fs::UniqueID UniqueID;
-  unsigned UID;               // A unique (small) ID for the file.
-  bool IsNamedPipe;
-  bool IsValid;               // Is this \c FileEntry initialized and valid?
+  unsigned UID = 0; // A unique (small) ID for the file.
+  bool IsNamedPipe = false;
+  bool IsValid = false; // Is this \c FileEntry initialized and valid?
 
   /// The open file, if it is owned by the \p FileEntry.
   mutable std::unique_ptr<llvm::vfs::File> File;
index 29218c7..2efdcbb 100644 (file)
@@ -16,7 +16,7 @@
 
 using namespace clang;
 
-FileEntry::FileEntry() : UniqueID(0, 0), IsNamedPipe(false), IsValid(false) {}
+FileEntry::FileEntry() : UniqueID(0, 0) {}
 
 FileEntry::~FileEntry() = default;
 
index 3cc0187..a3e03e6 100644 (file)
@@ -55,6 +55,17 @@ struct RefMaps {
   }
 };
 
+TEST(FileEntryTest, Constructor) {
+  FileEntry FE;
+  EXPECT_EQ(0U, FE.getSize());
+  EXPECT_EQ(0, FE.getModificationTime());
+  EXPECT_EQ(nullptr, FE.getDir());
+  EXPECT_EQ(0U, FE.getUniqueID().getDevice());
+  EXPECT_EQ(0U, FE.getUniqueID().getFile());
+  EXPECT_EQ(false, FE.isNamedPipe());
+  EXPECT_EQ(false, FE.isValid());
+}
+
 TEST(FileEntryTest, FileEntryRef) {
   RefMaps Refs;
   FileEntryRef R1 = Refs.addFile("1");