From 0978c83e6fcc7a8aea18e24eb3b2ad5523581757 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 10 Dec 2020 13:44:06 -0800 Subject: [PATCH] Basic: Initialize FileEntry's fields inline, almost NFC 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 | 12 ++++++------ clang/lib/Basic/FileEntry.cpp | 2 +- clang/unittests/Basic/FileEntryTest.cpp | 11 +++++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 8db5446..aa7bede 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -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 File; diff --git a/clang/lib/Basic/FileEntry.cpp b/clang/lib/Basic/FileEntry.cpp index 29218c7..2efdcbb 100644 --- a/clang/lib/Basic/FileEntry.cpp +++ b/clang/lib/Basic/FileEntry.cpp @@ -16,7 +16,7 @@ using namespace clang; -FileEntry::FileEntry() : UniqueID(0, 0), IsNamedPipe(false), IsValid(false) {} +FileEntry::FileEntry() : UniqueID(0, 0) {} FileEntry::~FileEntry() = default; diff --git a/clang/unittests/Basic/FileEntryTest.cpp b/clang/unittests/Basic/FileEntryTest.cpp index 3cc0187..a3e03e6 100644 --- a/clang/unittests/Basic/FileEntryTest.cpp +++ b/clang/unittests/Basic/FileEntryTest.cpp @@ -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"); -- 2.7.4