diff options
author | Ivan Komarov <Ivan.Komarov@dfyz.info> | 2022-02-10 16:46:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
commit | 59aca5c5180c31691884667783dc966eb99d743a (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util | |
parent | 4de97ab2fe437cbe83e4c63234e809ddd5ac34f2 (diff) | |
download | ydb-59aca5c5180c31691884667783dc966eb99d743a.tar.gz |
Restoring authorship annotation for Ivan Komarov <Ivan.Komarov@dfyz.info>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/datetime/base.cpp | 192 | ||||
-rw-r--r-- | util/datetime/base.h | 92 | ||||
-rw-r--r-- | util/stream/output.cpp | 12 | ||||
-rw-r--r-- | util/system/context.h | 2 | ||||
-rw-r--r-- | util/system/datetime.cpp | 2 | ||||
-rw-r--r-- | util/system/datetime.h | 20 | ||||
-rw-r--r-- | util/system/direct_io.cpp | 4 | ||||
-rw-r--r-- | util/system/info.cpp | 2 |
8 files changed, 163 insertions, 163 deletions
diff --git a/util/datetime/base.cpp b/util/datetime/base.cpp index 8144dcc1a2..38ecc3ab96 100644 --- a/util/datetime/base.cpp +++ b/util/datetime/base.cpp @@ -67,80 +67,80 @@ namespace { return o << p.I; } - + inline IOutputStream& operator<<(IOutputStream& o, const TPad<6>& p) { - if (p.I < 100000) { - if (p.I >= 0) { - if (p.I < 10) { - o << '0' << '0' << '0' << '0' << '0'; - } else if (p.I < 100) { - o << '0' << '0' << '0' << '0'; - } else if (p.I < 1000) { - o << '0' << '0' << '0'; - } else if (p.I < 10000) { - o << '0' << '0'; - } else { - o << '0'; - } - } - } - - return o << p.I; - } - + if (p.I < 100000) { + if (p.I >= 0) { + if (p.I < 10) { + o << '0' << '0' << '0' << '0' << '0'; + } else if (p.I < 100) { + o << '0' << '0' << '0' << '0'; + } else if (p.I < 1000) { + o << '0' << '0' << '0'; + } else if (p.I < 10000) { + o << '0' << '0'; + } else { + o << '0'; + } + } + } + + return o << p.I; + } + void WriteMicroSecondsToStream(IOutputStream& os, ui32 microSeconds) { - os << '.' << Pad<6>(microSeconds); - } - + os << '.' << Pad<6>(microSeconds); + } + void WriteTmToStream(IOutputStream& os, const struct tm& theTm) { - os << Pad<4>(theTm.tm_year + 1900) << '-' << Pad<2>(theTm.tm_mon + 1) << '-' << Pad<2>(theTm.tm_mday) << 'T' + os << Pad<4>(theTm.tm_year + 1900) << '-' << Pad<2>(theTm.tm_mon + 1) << '-' << Pad<2>(theTm.tm_mday) << 'T' << Pad<2>(theTm.tm_hour) << ':' << Pad<2>(theTm.tm_min) << ':' << Pad<2>(theTm.tm_sec); - } - + } + template <bool PrintUpToSeconds, bool iso> void WritePrintableLocalTimeToStream(IOutputStream& os, const ::NPrivate::TPrintableLocalTime<PrintUpToSeconds, iso>& timeToPrint) { const TInstant& momentToPrint = timeToPrint.MomentToPrint; - struct tm localTime; - momentToPrint.LocalTime(&localTime); - WriteTmToStream(os, localTime); - if (!PrintUpToSeconds) { - WriteMicroSecondsToStream(os, momentToPrint.MicroSecondsOfSecond()); - } -#ifndef _win_ - i64 utcOffsetInMinutes = localTime.tm_gmtoff / 60; -#else - TIME_ZONE_INFORMATION tz; - if (GetTimeZoneInformation(&tz) == TIME_ZONE_ID_INVALID) { - ythrow TSystemError() << "Failed to get the system time zone"; - } - i64 utcOffsetInMinutes = -tz.Bias; -#endif - if (utcOffsetInMinutes == 0) { - os << 'Z'; - } else { - if (utcOffsetInMinutes < 0) { - os << '-'; - utcOffsetInMinutes = -utcOffsetInMinutes; - } else { - os << '+'; - } + struct tm localTime; + momentToPrint.LocalTime(&localTime); + WriteTmToStream(os, localTime); + if (!PrintUpToSeconds) { + WriteMicroSecondsToStream(os, momentToPrint.MicroSecondsOfSecond()); + } +#ifndef _win_ + i64 utcOffsetInMinutes = localTime.tm_gmtoff / 60; +#else + TIME_ZONE_INFORMATION tz; + if (GetTimeZoneInformation(&tz) == TIME_ZONE_ID_INVALID) { + ythrow TSystemError() << "Failed to get the system time zone"; + } + i64 utcOffsetInMinutes = -tz.Bias; +#endif + if (utcOffsetInMinutes == 0) { + os << 'Z'; + } else { + if (utcOffsetInMinutes < 0) { + os << '-'; + utcOffsetInMinutes = -utcOffsetInMinutes; + } else { + os << '+'; + } os << Pad<2>(utcOffsetInMinutes / 60); if (iso) { os << ':'; } os << Pad<2>(utcOffsetInMinutes % 60); - } - } + } + } } -template <> +template <> void Out<TDuration>(IOutputStream& os, TTypeTraits<TDuration>::TFuncParam duration) { - os << duration.Seconds(); - WriteMicroSecondsToStream(os, duration.MicroSecondsOfSecond()); - os << 's'; -} - -template <> + os << duration.Seconds(); + WriteMicroSecondsToStream(os, duration.MicroSecondsOfSecond()); + os << 's'; +} + +template <> void Out<TInstant>(IOutputStream& os, TTypeTraits<TInstant>::TFuncParam instant) { char buf[64]; auto len = FormatDate8601(buf, sizeof(buf), instant.TimeT()); @@ -149,20 +149,20 @@ void Out<TInstant>(IOutputStream& os, TTypeTraits<TInstant>::TFuncParam instant) Y_ENSURE(len, TStringBuf("Out<TInstant>: year does not fit into an integer")); os.Write(buf, len - 1 /* 'Z' */); - WriteMicroSecondsToStream(os, instant.MicroSecondsOfSecond()); - os << 'Z'; -} - -template <> + WriteMicroSecondsToStream(os, instant.MicroSecondsOfSecond()); + os << 'Z'; +} + +template <> void Out<::NPrivate::TPrintableLocalTime<false, false>>(IOutputStream& os, TTypeTraits<::NPrivate::TPrintableLocalTime<false, false>>::TFuncParam localTime) { - WritePrintableLocalTimeToStream(os, localTime); -} - -template <> + WritePrintableLocalTimeToStream(os, localTime); +} + +template <> void Out<::NPrivate::TPrintableLocalTime<false, true>>(IOutputStream& os, TTypeTraits<::NPrivate::TPrintableLocalTime<false, true>>::TFuncParam localTime) { - WritePrintableLocalTimeToStream(os, localTime); -} - + WritePrintableLocalTimeToStream(os, localTime); +} + template <> void Out<::NPrivate::TPrintableLocalTime<true, false>>(IOutputStream& os, TTypeTraits<::NPrivate::TPrintableLocalTime<true, false>>::TFuncParam localTime) { WritePrintableLocalTimeToStream(os, localTime); @@ -174,13 +174,13 @@ void Out<::NPrivate::TPrintableLocalTime<true, true>>(IOutputStream& os, TTypeTr } TString TDuration::ToString() const { - return ::ToString(*this); -} - + return ::ToString(*this); +} + TString TInstant::ToString() const { - return ::ToString(*this); -} - + return ::ToString(*this); +} + TString TInstant::ToRfc822String() const { return FormatGmTime("%a, %d %b %Y %H:%M:%S GMT"); } @@ -189,19 +189,19 @@ TString TInstant::ToStringUpToSeconds() const { char buf[64]; auto len = FormatDate8601(buf, sizeof(buf), TimeT()); if (!len) { - ythrow yexception() << "TInstant::ToStringUpToSeconds: year does not fit into an integer"; + ythrow yexception() << "TInstant::ToStringUpToSeconds: year does not fit into an integer"; } return TString(buf, len); -} - +} + TString TInstant::ToIsoStringLocal() const { return ::ToString(FormatIsoLocal(*this)); } TString TInstant::ToStringLocal() const { - return ::ToString(FormatLocal(*this)); -} - + return ::ToString(FormatLocal(*this)); +} + TString TInstant::ToRfc822StringLocal() const { return FormatLocalTime("%a, %d %b %Y %H:%M:%S %Z"); } @@ -211,9 +211,9 @@ TString TInstant::ToIsoStringLocalUpToSeconds() const { } TString TInstant::ToStringLocalUpToSeconds() const { - return ::ToString(FormatLocalUpToSeconds(*this)); -} - + return ::ToString(FormatLocalUpToSeconds(*this)); +} + TString TInstant::FormatLocalTime(const char* format) const noexcept { struct tm theTm; LocalTime(&theTm); @@ -228,12 +228,12 @@ TString TInstant::FormatGmTime(const char* format) const noexcept { ::NPrivate::TPrintableLocalTime<false, true> FormatIsoLocal(TInstant instant) { return ::NPrivate::TPrintableLocalTime<false, true>(instant); -} - +} + ::NPrivate::TPrintableLocalTime<false, false> FormatLocal(TInstant instant) { return ::NPrivate::TPrintableLocalTime<false, false>(instant); -} - +} + ::NPrivate::TPrintableLocalTime<true, true> FormatIsoLocalUpToSeconds(TInstant instant) { return ::NPrivate::TPrintableLocalTime<true, true>(instant); } @@ -242,10 +242,10 @@ TString TInstant::FormatGmTime(const char* format) const noexcept { return ::NPrivate::TPrintableLocalTime<true, false>(instant); } -void Sleep(TDuration duration) { - NanoSleep(duration.NanoSeconds()); -} - +void Sleep(TDuration duration) { + NanoSleep(duration.NanoSeconds()); +} + void sprint_gm_date(char* buf, time_t when, long* sec) { struct tm theTm; ::Zero(theTm); @@ -317,8 +317,8 @@ size_t FormatDate8601(char* buf, size_t len, time_t when) { if (ret) { TMemoryOutput out(buf, len); - WriteTmToStream(out, theTm); - out << 'Z'; + WriteTmToStream(out, theTm); + out << 'Z'; return out.Buf() - buf; } diff --git a/util/datetime/base.h b/util/datetime/base.h index 5088a7b929..5e902b8f63 100644 --- a/util/datetime/base.h +++ b/util/datetime/base.h @@ -443,15 +443,15 @@ public: return GmTimeR(&clock, tm); } - /** - * Formats the instant using the UTC time zone, with microsecond precision. - * - * @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27.991669Z'. + /** + * Formats the instant using the UTC time zone, with microsecond precision. + * + * @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27.991669Z'. * @note Global Out method is defined to TInstant, so it can be written as text to IOutputStream. - */ + */ TString ToString() const; - - /** + + /** * Formats the instant using the UTC time zone. * * @returns An RFC822 formatted string, e.g. 'Sun, 06 Nov 1994 08:49:37 GMT'. @@ -459,18 +459,18 @@ public: TString ToRfc822String() const; /** - * Formats the instant using the UTC time zone, with second precision. - * - * @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27Z'. - */ + * Formats the instant using the UTC time zone, with second precision. + * + * @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27Z'. + */ TString ToStringUpToSeconds() const; - /** - * Formats the instant using the system time zone, with microsecond precision. - * + /** + * Formats the instant using the system time zone, with microsecond precision. + * * @returns An ISO 8601 / RFC 3339 formatted string, * e.g. '2015-11-22T04:30:27.991669+05:00'. - */ + */ TString ToIsoStringLocal() const; /** @@ -480,8 +480,8 @@ public: * e.g. '2015-11-22T04:30:27.991669+0500'. */ TString ToStringLocal() const; - - /** + + /** * Formats the instant using the system time zone. * * @returns An RFC822 formatted string, e.g. 'Sun, 06 Nov 1994 08:49:37 MSK'. @@ -489,11 +489,11 @@ public: TString ToRfc822StringLocal() const; /** - * Formats the instant using the system time zone, with second precision. - * + * Formats the instant using the system time zone, with second precision. + * * @returns An ISO 8601 / RFC 3339 formatted string, * e.g. '2015-11-22T04:30:27+05:00'. - */ + */ TString ToIsoStringLocalUpToSeconds() const; /** @@ -503,7 +503,7 @@ public: * e.g. '2015-11-22T04:30:27+0500'. */ TString ToStringLocalUpToSeconds() const; - + TString FormatLocalTime(const char* format) const noexcept; TString FormatGmTime(const char* format) const noexcept; @@ -566,41 +566,41 @@ struct THash<TInstant> { } }; -namespace NPrivate { +namespace NPrivate { template <bool PrintUpToSeconds, bool iso> - struct TPrintableLocalTime { - TInstant MomentToPrint; - + struct TPrintableLocalTime { + TInstant MomentToPrint; + constexpr explicit TPrintableLocalTime(TInstant momentToPrint) - : MomentToPrint(momentToPrint) - { - } - }; -} - + : MomentToPrint(momentToPrint) + { + } + }; +} + /** @name Helpers for printing local times to `IOutputStream`s. - * The FormatLocal* functions create an opaque object that, when written to + * The FormatLocal* functions create an opaque object that, when written to * a `IOutputStream`, outputs this instant as an ISO 8601 formatted string - * using the system time zone. - * - * @note The only reason behind this set of functions is to avoid excessive - * allocations when you directly print the local time to a stream. - * - * If you need something beyond just printing the value or your code - * is not performance-critical, feel free to use the corresponding - * TInstant::ToString*() functions. - */ -///@{ + * using the system time zone. + * + * @note The only reason behind this set of functions is to avoid excessive + * allocations when you directly print the local time to a stream. + * + * If you need something beyond just printing the value or your code + * is not performance-critical, feel free to use the corresponding + * TInstant::ToString*() functions. + */ +///@{ /// @see TInstant::ToIsoStringLocal() ::NPrivate::TPrintableLocalTime<false, true> FormatIsoLocal(TInstant instant); -/// @see TInstant::ToStringLocal() +/// @see TInstant::ToStringLocal() ::NPrivate::TPrintableLocalTime<false, false> FormatLocal(TInstant instant); /// @see TInstant::ToIsoStringLocalUpToSeconds() ::NPrivate::TPrintableLocalTime<true, true> FormatIsoLocalUpToSeconds(TInstant instant); -/// @see TInstant::ToStringLocalUpToSeconds() +/// @see TInstant::ToStringLocalUpToSeconds() ::NPrivate::TPrintableLocalTime<true, false> FormatLocalUpToSeconds(TInstant instant); -///@} - +///@} + template <class S> static constexpr bool operator<(const TTimeBase<S>& l, const TTimeBase<S>& r) noexcept { return l.GetValue() < r.GetValue(); diff --git a/util/stream/output.cpp b/util/stream/output.cpp index d43eb527a2..db81b81b70 100644 --- a/util/stream/output.cpp +++ b/util/stream/output.cpp @@ -272,21 +272,21 @@ namespace { private: virtual void DoWrite(const void* buf, size_t len) override { with_lock (BufferMutex) { - Buffer.Write(buf, len); - } + Buffer.Write(buf, len); + } } virtual void DoFlush() override { with_lock (BufferMutex) { - LogFuncPtr(ANDROID_LOG_DEBUG, GetTag(), Buffer.Data()); - Buffer.Clear(); - } + LogFuncPtr(ANDROID_LOG_DEBUG, GetTag(), Buffer.Data()); + Buffer.Clear(); + } } virtual const char* GetTag() const = 0; private: - TMutex BufferMutex; + TMutex BufferMutex; TStringStream Buffer; TLogFuncPtr LogFuncPtr; }; diff --git a/util/system/context.h b/util/system/context.h index e02b6a13ca..d2a349bfc5 100644 --- a/util/system/context.h +++ b/util/system/context.h @@ -20,7 +20,7 @@ /* * switch method */ -#if defined(_bionic_) || defined(__IOS__) +#if defined(_bionic_) || defined(__IOS__) #define USE_GENERIC_CONT #elif defined(_cygwin_) #define USE_UCONTEXT_CONT diff --git a/util/system/datetime.cpp b/util/system/datetime.cpp index 60c4150298..b07b50679a 100644 --- a/util/system/datetime.cpp +++ b/util/system/datetime.cpp @@ -94,7 +94,7 @@ void NanoSleep(ui64 ns) noexcept { #endif } -#if defined(_x86_) +#if defined(_x86_) extern const bool HaveRdtscp = NX86::HaveRDTSCP(); #endif diff --git a/util/system/datetime.h b/util/system/datetime.h index e7fedbbfed..aa009974e0 100644 --- a/util/system/datetime.h +++ b/util/system/datetime.h @@ -68,20 +68,20 @@ Y_FORCE_INLINE ui64 GetCycleCount() noexcept { return ((unsigned long long)lo) | (((unsigned long long)hi) << 32); #elif defined(_i386_) - extern const bool HaveRdtscp; - + extern const bool HaveRdtscp; + ui64 x; - if (HaveRdtscp) { - __asm__ volatile("rdtscp\n\t" - : "=A"(x)::"%ecx"); - } else { - __asm__ volatile("rdtsc\n\t" - : "=A"(x)); - } + if (HaveRdtscp) { + __asm__ volatile("rdtscp\n\t" + : "=A"(x)::"%ecx"); + } else { + __asm__ volatile("rdtsc\n\t" + : "=A"(x)); + } return x; #elif defined(_darwin_) return mach_absolute_time(); -#elif defined(__clang__) && !defined(_arm_) +#elif defined(__clang__) && !defined(_arm_) return __builtin_readcyclecounter(); #elif defined(_arm32_) return MicroSeconds(); diff --git a/util/system/direct_io.cpp b/util/system/direct_io.cpp index 58a72e0f48..f59c54b0cb 100644 --- a/util/system/direct_io.cpp +++ b/util/system/direct_io.cpp @@ -2,7 +2,7 @@ #include <util/generic/singleton.h> #include <util/generic/yexception.h> -#include <util/system/info.h> +#include <util/system/info.h> #include "align.h" #ifdef _linux_ @@ -32,7 +32,7 @@ namespace { if (linuxVersionCode < KERNEL_VERSION(2, 4, 10)) { Alignment = 0; } else if (linuxVersionCode < KERNEL_VERSION(2, 6, 0)) { - Alignment = NSystemInfo::GetPageSize(); + Alignment = NSystemInfo::GetPageSize(); } else { // Default alignment used to be 512, but most modern devices rely on 4k physical blocks. // 4k alignment works well for both 512 and 4k blocks and doesn't require 512e support in the kernel. diff --git a/util/system/info.cpp b/util/system/info.cpp index 88cd24afb2..cf6681e89a 100644 --- a/util/system/info.cpp +++ b/util/system/info.cpp @@ -183,7 +183,7 @@ size_t NSystemInfo::GetPageSize() noexcept { return sysInfo.dwPageSize; #else - return sysconf(_SC_PAGESIZE); + return sysconf(_SC_PAGESIZE); #endif } |