[llvm] r284974 - [Object] Replace TimeValue with std::chrono
Pavel Labath via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 24 06:38:28 PDT 2016
Author: labath
Date: Mon Oct 24 08:38:27 2016
New Revision: 284974
URL: http://llvm.org/viewvc/llvm-project?rev=284974&view=rev
Log:
[Object] Replace TimeValue with std::chrono
Summary:
Most of the changes are very straight-forward. The only choice I had to make was
to use second-precision time points in the Archive classes. I did this because
the archive files use that precision in the on-disk representation anyway.
Reviewers: rafael, zturner
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D25773
Modified:
llvm/trunk/include/llvm/Object/Archive.h
llvm/trunk/include/llvm/Object/ArchiveWriter.h
llvm/trunk/lib/Object/Archive.cpp
llvm/trunk/lib/Object/ArchiveWriter.cpp
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
Modified: llvm/trunk/include/llvm/Object/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Archive.h?rev=284974&r1=284973&r2=284974&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Archive.h (original)
+++ llvm/trunk/include/llvm/Object/Archive.h Mon Oct 24 08:38:27 2016
@@ -18,11 +18,11 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Object/Binary.h"
+#include "llvm/Support/Chrono.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/TimeValue.h"
namespace llvm {
namespace object {
@@ -46,7 +46,7 @@ public:
Expected<uint32_t> getSize() const;
Expected<sys::fs::perms> getAccessMode() const;
- Expected<sys::TimeValue> getLastModified() const;
+ Expected<sys::TimePoint<std::chrono::seconds>> getLastModified() const;
llvm::StringRef getRawLastModified() const {
return StringRef(ArMemHdr->LastModified,
sizeof(ArMemHdr->LastModified)).rtrim(' ');
@@ -103,7 +103,7 @@ public:
Expected<StringRef> getName() const;
Expected<std::string> getFullName() const;
Expected<StringRef> getRawName() const { return Header.getRawName(); }
- Expected<sys::TimeValue> getLastModified() const {
+ Expected<sys::TimePoint<std::chrono::seconds>> getLastModified() const {
return Header.getLastModified();
}
StringRef getRawLastModified() const {
Modified: llvm/trunk/include/llvm/Object/ArchiveWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ArchiveWriter.h?rev=284974&r1=284973&r2=284974&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ArchiveWriter.h (original)
+++ llvm/trunk/include/llvm/Object/ArchiveWriter.h Mon Oct 24 08:38:27 2016
@@ -22,7 +22,7 @@ namespace llvm {
struct NewArchiveMember {
std::unique_ptr<MemoryBuffer> Buf;
- sys::TimeValue ModTime = sys::TimeValue::PosixZeroTime();
+ sys::TimePoint<std::chrono::seconds> ModTime;
unsigned UID = 0, GID = 0, Perms = 0644;
NewArchiveMember() = default;
Modified: llvm/trunk/lib/Object/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/Archive.cpp?rev=284974&r1=284973&r2=284974&view=diff
==============================================================================
--- llvm/trunk/lib/Object/Archive.cpp (original)
+++ llvm/trunk/lib/Object/Archive.cpp Mon Oct 24 08:38:27 2016
@@ -239,7 +239,8 @@ Expected<sys::fs::perms> ArchiveMemberHe
return static_cast<sys::fs::perms>(Ret);
}
-Expected<sys::TimeValue> ArchiveMemberHeader::getLastModified() const {
+Expected<sys::TimePoint<std::chrono::seconds>>
+ArchiveMemberHeader::getLastModified() const {
unsigned Seconds;
if (StringRef(ArMemHdr->LastModified,
sizeof(ArMemHdr->LastModified)).rtrim(' ')
@@ -256,9 +257,7 @@ Expected<sys::TimeValue> ArchiveMemberHe
"archive member header at offset " + Twine(Offset));
}
- sys::TimeValue Ret;
- Ret.fromEpochTime(Seconds);
- return Ret;
+ return sys::toTimePoint(Seconds);
}
Expected<unsigned> ArchiveMemberHeader::getUID() const {
Modified: llvm/trunk/lib/Object/ArchiveWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/ArchiveWriter.cpp?rev=284974&r1=284973&r2=284974&view=diff
==============================================================================
--- llvm/trunk/lib/Object/ArchiveWriter.cpp (original)
+++ llvm/trunk/lib/Object/ArchiveWriter.cpp Mon Oct 24 08:38:27 2016
@@ -47,7 +47,7 @@ NewArchiveMember::getOldMember(const obj
NewArchiveMember M;
M.Buf = MemoryBuffer::getMemBuffer(*BufOrErr, false);
if (!Deterministic) {
- Expected<sys::TimeValue> ModTimeOrErr = OldMember.getLastModified();
+ auto ModTimeOrErr = OldMember.getLastModified();
if (!ModTimeOrErr)
return ModTimeOrErr.takeError();
M.ModTime = ModTimeOrErr.get();
@@ -95,7 +95,8 @@ Expected<NewArchiveMember> NewArchiveMem
NewArchiveMember M;
M.Buf = std::move(*MemberBufferOrErr);
if (!Deterministic) {
- M.ModTime = Status.getLastModificationTime();
+ M.ModTime = std::chrono::time_point_cast<std::chrono::seconds>(
+ Status.getLastModificationTime());
M.UID = Status.getUser();
M.GID = Status.getGroup();
M.Perms = Status.permissions();
@@ -127,11 +128,10 @@ static void print32(raw_ostream &Out, ob
support::endian::Writer<support::little>(Out).write(Val);
}
-static void printRestOfMemberHeader(raw_fd_ostream &Out,
- const sys::TimeValue &ModTime, unsigned UID,
- unsigned GID, unsigned Perms,
- unsigned Size) {
- printWithSpacePadding(Out, ModTime.toEpochTime(), 12);
+static void printRestOfMemberHeader(
+ raw_fd_ostream &Out, const sys::TimePoint<std::chrono::seconds> &ModTime,
+ unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
+ printWithSpacePadding(Out, sys::toTimeT(ModTime), 12);
printWithSpacePadding(Out, UID, 6, true);
printWithSpacePadding(Out, GID, 6, true);
printWithSpacePadding(Out, format("%o", Perms), 8);
@@ -139,17 +139,20 @@ static void printRestOfMemberHeader(raw_
Out << "`\n";
}
-static void printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name,
- const sys::TimeValue &ModTime,
- unsigned UID, unsigned GID,
- unsigned Perms, unsigned Size) {
+static void
+printGNUSmallMemberHeader(raw_fd_ostream &Out, StringRef Name,
+ const sys::TimePoint<std::chrono::seconds> &ModTime,
+ unsigned UID, unsigned GID, unsigned Perms,
+ unsigned Size) {
printWithSpacePadding(Out, Twine(Name) + "/", 16);
printRestOfMemberHeader(Out, ModTime, UID, GID, Perms, Size);
}
-static void printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name,
- const sys::TimeValue &ModTime, unsigned UID,
- unsigned GID, unsigned Perms, unsigned Size) {
+static void
+printBSDMemberHeader(raw_fd_ostream &Out, StringRef Name,
+ const sys::TimePoint<std::chrono::seconds> &ModTime,
+ unsigned UID, unsigned GID, unsigned Perms,
+ unsigned Size) {
uint64_t PosAfterHeader = Out.tell() + 60 + Name.size();
// Pad so that even 64 bit object files are aligned.
unsigned Pad = OffsetToAlignment(PosAfterHeader, 8);
@@ -171,8 +174,8 @@ static void
printMemberHeader(raw_fd_ostream &Out, object::Archive::Kind Kind, bool Thin,
StringRef Name,
std::vector<unsigned>::iterator &StringMapIndexIter,
- const sys::TimeValue &ModTime, unsigned UID, unsigned GID,
- unsigned Perms, unsigned Size) {
+ const sys::TimePoint<std::chrono::seconds> &ModTime,
+ unsigned UID, unsigned GID, unsigned Perms, unsigned Size) {
if (Kind == object::Archive::K_BSD)
return printBSDMemberHeader(Out, Name, ModTime, UID, GID, Perms, Size);
if (!useStringTable(Thin, Name))
@@ -239,12 +242,12 @@ static void writeStringTable(raw_fd_ostr
Out.seek(Pos);
}
-static sys::TimeValue now(bool Deterministic) {
+static sys::TimePoint<std::chrono::seconds> now(bool Deterministic) {
+ using namespace std::chrono;
+
if (!Deterministic)
- return sys::TimeValue::now();
- sys::TimeValue TV;
- TV.fromEpochTime(0);
- return TV;
+ return time_point_cast<seconds>(system_clock::now());
+ return sys::TimePoint<seconds>();
}
// Returns the offset of the first reference to a member offset.
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=284974&r1=284973&r2=284974&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Mon Oct 24 08:38:27 2016
@@ -528,7 +528,7 @@ static InsertAction computeInsertAction(
failIfError(sys::fs::status(*MI, Status), *MI);
auto ModTimeOrErr = Member.getLastModified();
failIfError(ModTimeOrErr.takeError());
- if (sys::TimeValue(Status.getLastModificationTime()) < ModTimeOrErr.get()) {
+ if (Status.getLastModificationTime() < ModTimeOrErr.get()) {
if (PosName.empty())
return IA_AddOldMember;
return IA_MoveOldMember;
More information about the llvm-commits
mailing list