diff options
author | denplusplus <denplusplus@yandex-team.ru> | 2022-02-10 16:47:34 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:34 +0300 |
commit | 57c20d143e8a438cd76b9fdc3ca2e8ee3ac1f32a (patch) | |
tree | cc63639f8e502db19a82c20e2861c6d1edbf9fea /util | |
parent | 464ba3814a83db4f2d5327393b0b6eaf0c86bfd7 (diff) | |
download | ydb-57c20d143e8a438cd76b9fdc3ca2e8ee3ac1f32a.tar.gz |
Restoring authorship annotation for <denplusplus@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
40 files changed, 312 insertions, 312 deletions
diff --git a/util/datetime/constants.h b/util/datetime/constants.h index 352403270e..a6395da3d3 100644 --- a/util/datetime/constants.h +++ b/util/datetime/constants.h @@ -1,7 +1,7 @@ #pragma once -#include <time.h> +#include <time.h> const time_t SECONDS_IN_DAY = 86400; const time_t SECONDS_IN_HOUR = 3600; -const time_t SECONDS_IN_HALFHOUR = 1800; +const time_t SECONDS_IN_HALFHOUR = 1800; diff --git a/util/datetime/cputimer.cpp b/util/datetime/cputimer.cpp index 516d372c37..a4e8eb1cbc 100644 --- a/util/datetime/cputimer.cpp +++ b/util/datetime/cputimer.cpp @@ -1,12 +1,12 @@ -#include "cputimer.h" +#include "cputimer.h" -#include <util/system/defaults.h> +#include <util/system/defaults.h> #include <util/system/hp_timer.h> #include <util/string/printf.h> #include <util/stream/output.h> -#include <util/generic/singleton.h> +#include <util/generic/singleton.h> -#if defined(_unix_) +#if defined(_unix_) #include <unistd.h> #include <sched.h> #include <sys/types.h> @@ -21,15 +21,15 @@ TTimer::TTimer(const TStringBuf message) { Message_.Reserve(message.length() + SMALL_DURATION_CHAR_LENGTH + 1); // +"\n" Message_ << message; // Do not measure the allocations above. - Start_ = TInstant::Now(); -} - -TTimer::~TTimer() { + Start_ = TInstant::Now(); +} + +TTimer::~TTimer() { const TDuration duration = TInstant::Now() - Start_; Message_ << duration << "\n"; Cerr << Message_.Str(); -} - +} + static ui64 ManuallySetCyclesPerSecond = 0; static ui64 GetCyclesPerSecond() { @@ -38,8 +38,8 @@ static ui64 GetCyclesPerSecond() { } else { return NHPTimer::GetCyclesPerSecond(); } -} - +} + void SetCyclesPerSecond(ui64 cycles) { ManuallySetCyclesPerSecond = cycles; } @@ -58,79 +58,79 @@ ui64 DurationToCycles(TDuration duration) { TPrecisionTimer::TPrecisionTimer() : Start(::GetCycleCount()) -{ -} - +{ +} + ui64 TPrecisionTimer::GetCycleCount() const { return ::GetCycleCount() - Start; -} - +} + TString FormatCycles(ui64 cycles) { - ui64 milliseconds = cycles / GetCyclesPerMillisecond(); - ui32 ms = ui32(milliseconds % 1000); - milliseconds /= 1000; - ui32 secs = ui32(milliseconds % 60); - milliseconds /= 60; - ui32 mins = ui32(milliseconds); + ui64 milliseconds = cycles / GetCyclesPerMillisecond(); + ui32 ms = ui32(milliseconds % 1000); + milliseconds /= 1000; + ui32 secs = ui32(milliseconds % 60); + milliseconds /= 60; + ui32 mins = ui32(milliseconds); TString result; - sprintf(result, "%" PRIu32 " m %.2" PRIu32 " s %.3" PRIu32 " ms", mins, secs, ms); - return result; -} - + sprintf(result, "%" PRIu32 " m %.2" PRIu32 " s %.3" PRIu32 " ms", mins, secs, ms); + return result; +} + TFormattedPrecisionTimer::TFormattedPrecisionTimer(const char* message, IOutputStream* out) : Message(message) , Out(out) -{ - Start = GetCycleCount(); -} - +{ + Start = GetCycleCount(); +} + TFormattedPrecisionTimer::~TFormattedPrecisionTimer() { const ui64 end = GetCycleCount(); const ui64 diff = end - Start; *Out << Message << ": " << diff << " ticks " << FormatCycles(diff) << Endl; -} - -TFuncTimer::TFuncTimer(const char* func) - : Start_(TInstant::Now()) - , Func_(func) -{ - Cerr << "enter " << Func_ << Endl; -} - +} + +TFuncTimer::TFuncTimer(const char* func) + : Start_(TInstant::Now()) + , Func_(func) +{ + Cerr << "enter " << Func_ << Endl; +} + TFuncTimer::~TFuncTimer() { - Cerr << "leave " << Func_ << " -> " << (TInstant::Now() - Start_) << Endl; -} - + Cerr << "leave " << Func_ << " -> " << (TInstant::Now() - Start_) << Endl; +} + TTimeLogger::TTimeLogger(const TString& message, bool verbose) : Message(message) - , Verbose(verbose) + , Verbose(verbose) , OK(false) , Begin(time(nullptr)) - , BeginCycles(GetCycleCount()) + , BeginCycles(GetCycleCount()) { - if (Verbose) { - fprintf(stderr, "=========================================================\n"); + if (Verbose) { + fprintf(stderr, "=========================================================\n"); fprintf(stderr, "%s started: %.24s (%lu) (%d)\n", Message.data(), ctime(&Begin), (unsigned long)Begin, (int)getpid()); - } + } } -double TTimeLogger::ElapsedTime() const { +double TTimeLogger::ElapsedTime() const { return time(nullptr) - Begin; -} - +} + void TTimeLogger::SetOK() { OK = true; } TTimeLogger::~TTimeLogger() { time_t tim = time(nullptr); - ui64 endCycles = GetCycleCount(); - if (Verbose) { - const char* prefix = (OK) ? "" : "!"; + ui64 endCycles = GetCycleCount(); + if (Verbose) { + const char* prefix = (OK) ? "" : "!"; fprintf(stderr, "%s%s ended: %.24s (%lu) (%d) (took %lus = %s)\n", prefix, Message.data(), ctime(&tim), (unsigned long)tim, (int)getpid(), (unsigned long)tim - (unsigned long)Begin, FormatCycles(endCycles - BeginCycles).data()); - fprintf(stderr, "%s=========================================================\n", prefix); - } + fprintf(stderr, "%s=========================================================\n", prefix); + } } diff --git a/util/datetime/cputimer.h b/util/datetime/cputimer.h index 7d38d5bdb3..d43102dff6 100644 --- a/util/datetime/cputimer.h +++ b/util/datetime/cputimer.h @@ -6,14 +6,14 @@ #include <util/generic/string.h> #include <util/stream/str.h> -class TTimer { +class TTimer { private: TInstant Start_; TStringStream Message_; public: TTimer(const TStringBuf message = TStringBuf(" took: ")); - ~TTimer(); + ~TTimer(); }; class TSimpleTimer { @@ -56,38 +56,38 @@ public: /// Return cached processor cycle count per second. Method takes 1 second at first invocation. /// Note, on older systems cycle rate may change during program lifetime, /// so returned value may be incorrect. Modern Intel and AMD processors keep constant TSC rate. -ui64 GetCyclesPerMillisecond(); +ui64 GetCyclesPerMillisecond(); void SetCyclesPerSecond(ui64 cycles); - + TDuration CyclesToDuration(ui64 cycles); ui64 DurationToCycles(TDuration duration); class TPrecisionTimer { -private: +private: ui64 Start = 0; - -public: + +public: TPrecisionTimer(); ui64 GetCycleCount() const; -}; - +}; + TString FormatCycles(ui64 cycles); - + class TFormattedPrecisionTimer { -private: - ui64 Start; - const char* Message; +private: + ui64 Start; + const char* Message; IOutputStream* Out; - -public: + +public: TFormattedPrecisionTimer(const char* message = "took ", IOutputStream* out = &Cout); - ~TFormattedPrecisionTimer(); -}; - + ~TFormattedPrecisionTimer(); +}; + class TFuncTimer { public: - TFuncTimer(const char* func); + TFuncTimer(const char* func); ~TFuncTimer(); private: @@ -105,20 +105,20 @@ public: #define TDebugTimer TFuncTimer #else #define TDebugTimer TFakeTimer -#endif +#endif class TTimeLogger { private: TString Message; - bool Verbose; + bool Verbose; bool OK; - time_t Begin; - ui64 BeginCycles; + time_t Begin; + ui64 BeginCycles; public: TTimeLogger(const TString& message, bool verbose = true); ~TTimeLogger(); void SetOK(); - double ElapsedTime() const; + double ElapsedTime() const; }; diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp index ffc9b09f96..c603c28dcc 100644 --- a/util/folder/dirut.cpp +++ b/util/folder/dirut.cpp @@ -189,7 +189,7 @@ using disk_type = enum { dk_error = 8 }; -// root slash (if any) - part of disk +// root slash (if any) - part of disk template <typename T> static int skip_disk(T*& ptr) { int result = dk_noflags; @@ -240,7 +240,7 @@ int correctpath(char* cpath, const char* path) { *cptr = 0; // replace '/' by '\' int dk = skip_disk(cpath); - + if (dk == dk_error) return 0; @@ -366,15 +366,15 @@ bool resolvepath(TString& folder, const TString& home) { return false; } -#endif // !defined _win32_ - +#endif // !defined _win32_ + char GetDirectorySeparator() { - return LOCSLASH_C; -} - + return LOCSLASH_C; +} + const char* GetDirectorySeparatorS() { - return LOCSLASH_S; -} + return LOCSLASH_S; +} void RemoveDirWithContents(TString dirName) { SlashFolderLocal(dirName); diff --git a/util/folder/dirut.h b/util/folder/dirut.h index 2537027b12..91b65c028e 100644 --- a/util/folder/dirut.h +++ b/util/folder/dirut.h @@ -56,9 +56,9 @@ void SlashFolderLocal(TString& folder); bool correctpath(TString& filename); bool resolvepath(TString& folder, const TString& home); -char GetDirectorySeparator(); -const char* GetDirectorySeparatorS(); - +char GetDirectorySeparator(); +const char* GetDirectorySeparatorS(); + void RemoveDirWithContents(TString dirName); const char* GetFileNameComponent(const char* f); @@ -84,36 +84,36 @@ TString ResolveDir(const char* path); bool SafeResolveDir(const char* path, TString& result); TString GetDirName(const TString& path); - + TString GetBaseName(const TString& path); TString StripFileComponent(const TString& fileName); -class TExistenceChecker { -public: - TExistenceChecker(bool strict = false) - : Strict(strict) - { - } - - void SetStrict(bool strict) { - Strict = strict; - } - - bool IsStrict() const { - return Strict; - } - - const char* Check(const char* fname) const { - if (!fname || !*fname) +class TExistenceChecker { +public: + TExistenceChecker(bool strict = false) + : Strict(strict) + { + } + + void SetStrict(bool strict) { + Strict = strict; + } + + bool IsStrict() const { + return Strict; + } + + const char* Check(const char* fname) const { + if (!fname || !*fname) return nullptr; - if (Strict) { + if (Strict) { NFs::EnsureExists(fname); } else if (!NFs::Exists(fname)) fname = nullptr; - return fname; - } - -private: - bool Strict; -}; + return fname; + } + +private: + bool Strict; +}; diff --git a/util/folder/filelist.h b/util/folder/filelist.h index 3f615fa4c2..384f5ed1bc 100644 --- a/util/folder/filelist.h +++ b/util/folder/filelist.h @@ -22,12 +22,12 @@ public: TFileEntitiesList(EMask mask) : Mask(mask) { - Clear(); + Clear(); } void Clear() { Cur = nullptr; - FileNamesSize = CurName = 0; + FileNamesSize = CurName = 0; FileNames.Clear(); FileNames.Append("", 1); } @@ -36,8 +36,8 @@ public: return Cur = (CurName++ < FileNamesSize ? strchr(Cur, 0) + 1 : nullptr); } - size_t Size() { - return FileNamesSize; + size_t Size() { + return FileNamesSize; } inline void Fill(const TString& dirname, bool sort = false) { @@ -57,25 +57,25 @@ public: protected: TBuffer FileNames; - size_t FileNamesSize, CurName; + size_t FileNamesSize, CurName; const char* Cur; - EMask Mask; + EMask Mask; }; Y_DECLARE_OPERATORS_FOR_FLAGS(TFileEntitiesList::EMask) class TFileList: public TFileEntitiesList { -public: +public: TFileList() : TFileEntitiesList(TFileEntitiesList::EM_FILES) { } -}; - +}; + class TDirsList: public TFileEntitiesList { -public: +public: TDirsList() : TFileEntitiesList(TFileEntitiesList::EM_DIRS) { } -}; +}; diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index badfb88993..caf5edc64b 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -452,7 +452,7 @@ template <class T> static inline void Rotate(T f, T m, T l) { std::rotate(f, m, l); } - + template <typename It, typename Val> Val Accumulate(It begin, It end, Val val) { // std::move since C++20 @@ -463,7 +463,7 @@ template <typename It, typename Val, typename BinOp> Val Accumulate(It begin, It end, Val val, BinOp binOp) { // std::move since C++20 return std::accumulate(begin, end, std::move(val), binOp); -} +} template <typename C, typename Val> Val Accumulate(const C& c, Val val) { diff --git a/util/generic/bitops.h b/util/generic/bitops.h index 2db15fc59b..6885624b9a 100644 --- a/util/generic/bitops.h +++ b/util/generic/bitops.h @@ -83,7 +83,7 @@ namespace NBitOps { value >>= 1; ++result; } - + return result; } #endif diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp index 8b907457bc..e4fd0ca177 100644 --- a/util/generic/guid.cpp +++ b/util/generic/guid.cpp @@ -67,8 +67,8 @@ TGUID TGUID::CreateTimebased() { TString GetGuidAsString(const TGUID& g) { return g.AsGuidString(); -} - +} + TString CreateGuidAsString() { return TGUID::Create().AsGuidString(); } diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..b02afc0f10 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -606,7 +606,7 @@ public: THashTable& operator=(THashTable&& ht) noexcept { basic_clear(); swap(ht); - + return *this; } @@ -945,8 +945,8 @@ private: void delete_node(node* n) { n->val.~Value(); //n->next = (node*) 0xDeadBeeful; - put_node(n); - } + put_node(n); + } void erase_bucket(const size_type n, node* first, node* last); void erase_bucket(const size_type n, node* last); diff --git a/util/generic/ptr.cpp b/util/generic/ptr.cpp index b29baebc17..d1238fecec 100644 --- a/util/generic/ptr.cpp +++ b/util/generic/ptr.cpp @@ -7,11 +7,11 @@ #include <cstdlib> void TFree::DoDestroy(void* t) noexcept { - free(t); + free(t); } void TDelete::Destroy(void* t) noexcept { - ::operator delete(t); + ::operator delete(t); } TThrRefBase::~TThrRefBase() = default; diff --git a/util/generic/strbase.h b/util/generic/strbase.h index ab39fc7537..973aa2c068 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -226,7 +226,7 @@ public: TCharType null{0}; return TStringViewWithTraits(p ? p : &null).compare(s2.AsStringView()); } - + static int compare(const TSelf& s1, const TCharType* p) noexcept { TCharType null{0}; return s1.AsStringView().compare(p ? p : &null); diff --git a/util/generic/string.h b/util/generic/string.h index 8cd8aa6917..22d8d3cdae 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -215,7 +215,7 @@ protected: const TStdStr& StdStr() const noexcept { return *S_; - } + } /** * Makes a distinct copy of this string. `IsDetached()` is always true after this call. @@ -238,7 +238,7 @@ public: #else return StdStr(); #endif - } + } inline TStringType& MutRef() { #ifdef TSTRING_IS_STD_STRING @@ -296,7 +296,7 @@ public: inline size_t length() const noexcept { return ConstRef().length(); - } + } inline const TCharType* data() const noexcept { return ConstRef().data(); @@ -309,7 +309,7 @@ public: // ~~~ STL compatible method to obtain data pointer ~~~ iterator begin() { return &*MutRef().begin(); - } + } iterator vend() { return &*MutRef().end(); @@ -342,7 +342,7 @@ public: return S_->capacity(); #endif - } + } TCharType* Detach() { #ifdef TSTRING_IS_STD_STRING @@ -364,7 +364,7 @@ public: #endif } - // ~~~ Size and capacity ~~~ + // ~~~ Size and capacity ~~~ TBasicString& resize(size_t n, TCharType c = ' ') { // remove or append MutRef().resize(n, c); @@ -377,7 +377,7 @@ public: : S_(Construct()) #endif { - } + } inline explicit TBasicString(::NDetail::TReserveTag rt) #ifndef TSTRING_IS_STD_STRING @@ -394,7 +394,7 @@ public: : S_(s.S_) #endif { - } + } inline TBasicString(TBasicString&& s) noexcept #ifdef TSTRING_IS_STD_STRING @@ -573,8 +573,8 @@ public: Construct().Swap(S_); #endif - } - + } + template <typename... R> static inline TBasicString Join(const R&... r) { TBasicString s{TUninitialized{SumLength(r...)}}; @@ -595,15 +595,15 @@ public: TBasicString(s).swap(*this); return *this; - } + } TBasicString& assign(const TBasicString& s, size_t pos, size_t n) { return assign(TBasicString(s, pos, n)); - } + } TBasicString& assign(const TCharType* pc) { return assign(pc, TBase::StrLen(pc)); - } + } TBasicString& assign(TCharType ch) { return assign(&ch, 1); @@ -620,7 +620,7 @@ public: } return *this; - } + } TBasicString& assign(const TCharType* first, const TCharType* last) { return assign(first, last - first); @@ -628,7 +628,7 @@ public: TBasicString& assign(const TCharType* pc, size_t pos, size_t n) { return assign(pc + pos, n); - } + } TBasicString& assign(const TBasicStringBuf<TCharType, TTraits> s) { return assign(s.data(), s.size()); @@ -722,19 +722,19 @@ public: MutRef().append(s.ConstRef()); return *this; - } + } inline TBasicString& append(const TBasicString& s, size_t pos, size_t n) { MutRef().append(s.ConstRef(), pos, n); return *this; - } + } inline TBasicString& append(const TCharType* pc) Y_NOEXCEPT { MutRef().append(pc); return *this; - } + } inline TBasicString& append(TCharType c) { MutRef().push_back(c); @@ -787,7 +787,7 @@ public: TBasicString& append(const TCharType* pc, size_t pos, size_t n, size_t pc_len = TBase::npos) { return append(pc + pos, Min(n, pc_len - pos)); - } + } /** * WARN: @@ -802,26 +802,26 @@ public: inline void push_back(TCharType c) { // TODO - append(c); + append(c); } template <class T> TBasicString& operator+=(const T& s) { return append(s); - } + } - template <class T> + template <class T> friend TBasicString operator*(const TBasicString& s, T count) { TBasicString result; for (T i = 0; i < count; ++i) { - result += s; + result += s; } - return result; - } - - template <class T> + return result; + } + + template <class T> TBasicString& operator*=(T count) { TBasicString temp; @@ -829,10 +829,10 @@ public: temp += *this; } - swap(temp); + swap(temp); return *this; - } + } operator const TStringType&() const noexcept { return this->ConstRef(); @@ -866,7 +866,7 @@ public: friend TBasicString operator+(TBasicString&& s1, const TBasicString& s2) Y_WARN_UNUSED_RESULT { s1 += s2; return std::move(s1); - } + } friend TBasicString operator+(const TBasicString& s1, TBasicString&& s2) Y_WARN_UNUSED_RESULT { s2.prepend(s1); @@ -887,12 +887,12 @@ public: friend TBasicString operator+(TBasicString&& s1, const TBasicStringBuf<TCharType, TTraits> s2) Y_WARN_UNUSED_RESULT { s1 += s2; return std::move(s1); - } + } friend TBasicString operator+(TBasicString&& s1, const TCharType* s2) Y_WARN_UNUSED_RESULT { s1 += s2; return std::move(s1); - } + } friend TBasicString operator+(TBasicString&& s1, TCharType s2) Y_WARN_UNUSED_RESULT { s1 += s2; @@ -950,19 +950,19 @@ public: MutRef().insert(0, s.ConstRef()); return *this; - } + } TBasicString& prepend(const TBasicString& s, size_t pos, size_t n) { MutRef().insert(0, s.ConstRef(), pos, n); return *this; - } + } TBasicString& prepend(const TCharType* pc) { MutRef().insert(0, pc); return *this; - } + } TBasicString& prepend(size_t n, TCharType c) { MutRef().insert(size_t(0), n, c); @@ -974,7 +974,7 @@ public: MutRef().insert(size_t(0), 1, c); return *this; - } + } TBasicString& prepend(const TBasicStringBuf<TCharType, TTraits> s, size_t spos = 0, size_t sn = TBase::npos) { return insert(0, s, spos, sn); @@ -985,19 +985,19 @@ public: MutRef().insert(pos, s.ConstRef()); return *this; - } + } TBasicString& insert(size_t pos, const TBasicString& s, size_t pos1, size_t n1) { MutRef().insert(pos, s.ConstRef(), pos1, n1); return *this; - } + } TBasicString& insert(size_t pos, const TCharType* pc) { MutRef().insert(pos, pc); return *this; - } + } TBasicString& insert(size_t pos, const TCharType* pc, size_t len) { MutRef().insert(pos, pc, len); @@ -1035,14 +1035,14 @@ public: return *this; } - // ~~~ Removing ~~~ + // ~~~ Removing ~~~ TBasicString& remove(size_t pos, size_t n) Y_NOEXCEPT { if (pos < length()) { MutRef().erase(pos, n); } return *this; - } + } TBasicString& remove(size_t pos = 0) Y_NOEXCEPT { if (pos < length()) { @@ -1056,7 +1056,7 @@ public: MutRef().erase(pos, n); return *this; - } + } TBasicString& erase(const_iterator b, const_iterator e) Y_NOEXCEPT { return erase(this->off(b), e - b); @@ -1079,19 +1079,19 @@ public: MutRef().replace(pos, n, s.ConstRef()); return *this; - } + } TBasicString& replace(size_t pos, size_t n, const TBasicString& s, size_t pos1, size_t n1) Y_NOEXCEPT { MutRef().replace(pos, n, s.ConstRef(), pos1, n1); return *this; - } + } TBasicString& replace(size_t pos, size_t n, const TCharType* pc) Y_NOEXCEPT { MutRef().replace(pos, n, pc); return *this; - } + } TBasicString& replace(size_t pos, size_t n, const TCharType* s, size_t len) Y_NOEXCEPT { MutRef().replace(pos, n, s, len); @@ -1115,7 +1115,7 @@ public: MutRef().replace(pos, n, s, spos, sn); return *this; - } + } void swap(TBasicString& s) noexcept { #ifdef TSTRING_IS_STD_STRING diff --git a/util/generic/string_transparent_hash_ut.cpp b/util/generic/string_transparent_hash_ut.cpp index b87fa2843e..047315a817 100644 --- a/util/generic/string_transparent_hash_ut.cpp +++ b/util/generic/string_transparent_hash_ut.cpp @@ -4,7 +4,7 @@ #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/containers/absl_flat_hash/flat_hash_set.h> - + #include <util/str_stl.h> Y_UNIT_TEST_SUITE(StringHashFunctorTests) { diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp index ac82e9091d..de74c080ab 100644 --- a/util/generic/string_ut.cpp +++ b/util/generic/string_ut.cpp @@ -19,7 +19,7 @@ static_assert(sizeof(TString) == sizeof(std::string), "expect sizeof(TString) == #else static_assert(sizeof(TString) == sizeof(const char*), "expect sizeof(TString) == sizeof(const char*)"); #endif - + class TStringTestZero: public TTestBase { UNIT_TEST_SUITE(TStringTestZero); UNIT_TEST(TestZero); diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index 44bb10bdeb..533b48cb44 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -3,7 +3,7 @@ #include "string.h" #include <library/cpp/testing/unittest/registar.h> - + #include <util/string/reverse.h> template <typename CharT, size_t N> @@ -38,7 +38,7 @@ struct TCharBuffer<char, 0> { #define DECLARE_AND_RETURN_BUFFER(s) \ static TCharBuffer<CharT, sizeof(s)> buf(s); \ return buf.GetData(); - + //! @attention this class can process characters less than 0x7F only (the low half of ASCII table) template <typename CharT> struct TTestData { @@ -679,7 +679,7 @@ public: void TestFind() { const TStringType s(Data._0123456_12345()); const TStringType s2(Data._0123()); - + UNIT_ASSERT(s.find(Data._345()) == 3); UNIT_ASSERT(s.find(Data._345(), 5) == 10); @@ -843,7 +843,7 @@ public: s2 = Data.asdf1234qwer(); s2.to_upper(); UNIT_ASSERT(s2 == Data.ASDF1234QWER()); - + // to_lower() s2.to_lower(); UNIT_ASSERT(s2 == Data.asdf1234qwer()); @@ -957,14 +957,14 @@ public: data[4] = 1; s.strcpy(data, 4); - + UNIT_ASSERT_EQUAL(data[0], *Data.a()); UNIT_ASSERT_EQUAL(data[1], *Data.b()); UNIT_ASSERT_EQUAL(data[2], *Data.c()); UNIT_ASSERT_EQUAL(data[3], 0); UNIT_ASSERT_EQUAL(data[4], 1); } - + { TStringType s(Data.abcd()); char_type data[5]; diff --git a/util/generic/ymath.h b/util/generic/ymath.h index 9ff9ae2abe..2cb68419cd 100644 --- a/util/generic/ymath.h +++ b/util/generic/ymath.h @@ -3,8 +3,8 @@ #include <util/system/yassert.h> #include <util/system/defaults.h> -#include <cmath> -#include <cfloat> +#include <cmath> +#include <cfloat> #include <cstdlib> #include "typetraits.h" diff --git a/util/memory/pool.cpp b/util/memory/pool.cpp index 9a011f0e4f..77c4231940 100644 --- a/util/memory/pool.cpp +++ b/util/memory/pool.cpp @@ -1,4 +1,4 @@ - + #include "pool.h" TMemoryPool::IGrowPolicy* TMemoryPool::TLinearGrow::Instance() noexcept { diff --git a/util/network/hostip.cpp b/util/network/hostip.cpp index cb8d43bf90..87f2cbd38c 100644 --- a/util/network/hostip.cpp +++ b/util/network/hostip.cpp @@ -4,7 +4,7 @@ #include <util/system/defaults.h> #include <util/system/byteorder.h> -#if defined(_unix_) || defined(_cygwin_) +#if defined(_unix_) || defined(_cygwin_) #include <netdb.h> #endif diff --git a/util/str_stl.h b/util/str_stl.h index f1e137181d..670271ffda 100644 --- a/util/str_stl.h +++ b/util/str_stl.h @@ -141,10 +141,10 @@ struct THash<std::tuple<TArgs...>> { } }; -template <class T> +template <class T> struct THash: public ::hash<T> { -}; - +}; + namespace NHashPrivate { template <class TFirst, class TSecond, bool IsEmpty = std::is_empty<THash<TFirst>>::value&& std::is_empty<THash<TSecond>>::value> struct TPairHash { diff --git a/util/stream/buffer.cpp b/util/stream/buffer.cpp index 2facece4ea..a5d5e75b48 100644 --- a/util/stream/buffer.cpp +++ b/util/stream/buffer.cpp @@ -41,8 +41,8 @@ public: private: TBuffer& Data_; static constexpr size_t MinBufferGrowSize = 16; -}; - +}; + namespace { using TImpl = TBufferOutput::TImpl; @@ -58,14 +58,14 @@ namespace { TBufferOutput::TBufferOutput(size_t buflen) : Impl_(new TOwnedImpl(buflen)) -{ -} - +{ +} + TBufferOutput::TBufferOutput(TBuffer& buffer) : Impl_(new TImpl(buffer)) { -} - +} + TBufferOutput::TBufferOutput(TBufferOutput&&) noexcept = default; TBufferOutput& TBufferOutput::operator=(TBufferOutput&&) noexcept = default; @@ -85,8 +85,8 @@ void TBufferOutput::DoUndo(size_t len) { void TBufferOutput::DoWrite(const void* buf, size_t len) { Impl_->DoWrite(buf, len); -} - +} + void TBufferOutput::DoWriteC(char c) { Impl_->DoWriteC(c); } @@ -95,8 +95,8 @@ TBufferInput::TBufferInput(const TBuffer& buffer) : Buf_(buffer) , Readed_(0) { -} - +} + TBufferInput::~TBufferInput() = default; const TBuffer& TBufferInput::Buffer() const noexcept { diff --git a/util/stream/buffer.h b/util/stream/buffer.h index 9dc99dbe49..5932d54c5d 100644 --- a/util/stream/buffer.h +++ b/util/stream/buffer.h @@ -53,8 +53,8 @@ private: private: THolder<TImpl> Impl_; -}; - +}; + /** * Input stream that reads from an external `TBuffer`. */ diff --git a/util/stream/file.cpp b/util/stream/file.cpp index dc5d2f6311..35fd925612 100644 --- a/util/stream/file.cpp +++ b/util/stream/file.cpp @@ -69,7 +69,7 @@ void TUnbufferedFileOutput::DoFlush() { File_.Flush(); } } - + class TMappedFileInput::TImpl: public TBlob { public: inline TImpl(TFile file) diff --git a/util/stream/file.h b/util/stream/file.h index c1cf4f591d..3975aacf0a 100644 --- a/util/stream/file.h +++ b/util/stream/file.h @@ -84,8 +84,8 @@ public: } ~TFileInput() override = default; -}; - +}; + /** * Buffered file output stream. * @@ -103,6 +103,6 @@ public: } ~TFixedBufferFileOutput() override = default; -}; - +}; + /** @} */ diff --git a/util/stream/ios_ut.cpp b/util/stream/ios_ut.cpp index 139f4296e5..307470e196 100644 --- a/util/stream/ios_ut.cpp +++ b/util/stream/ios_ut.cpp @@ -254,30 +254,30 @@ void TStreamsTest::TestBufferedIO() { bo.Finish(); } } - + void TStreamsTest::TestBufferStream() { - TBufferStream stream; + TBufferStream stream; TString s = "test"; stream.Write(s.data(), s.size()); - char buf[5]; + char buf[5]; size_t bytesRead = stream.Read(buf, 4); UNIT_ASSERT_EQUAL(4, bytesRead); UNIT_ASSERT_EQUAL(0, strncmp(s.data(), buf, 4)); - + stream.Write(s.data(), s.size()); bytesRead = stream.Read(buf, 2); UNIT_ASSERT_EQUAL(2, bytesRead); - UNIT_ASSERT_EQUAL(0, strncmp("te", buf, 2)); + UNIT_ASSERT_EQUAL(0, strncmp("te", buf, 2)); bytesRead = stream.Read(buf, 2); UNIT_ASSERT_EQUAL(2, bytesRead); - UNIT_ASSERT_EQUAL(0, strncmp("st", buf, 2)); - + UNIT_ASSERT_EQUAL(0, strncmp("st", buf, 2)); + bytesRead = stream.Read(buf, 2); UNIT_ASSERT_EQUAL(0, bytesRead); -} - +} + namespace { class TStringListInput: public IWalkInput { public: diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..4939d63d6e 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -396,12 +396,12 @@ struct TSimplePusher { }; template <class T> -static inline void Split(char* buf, char ch, T* res) { +static inline void Split(char* buf, char ch, T* res) { res->resize(0); if (*buf == 0) return; - TCharDelimiter<char> delim(ch); + TCharDelimiter<char> delim(ch); TSimplePusher<T> pusher = {res}; SplitString(buf, delim, pusher); diff --git a/util/system/compat.cpp b/util/system/compat.cpp index 18fbfa296a..b6e178d5d7 100644 --- a/util/system/compat.cpp +++ b/util/system/compat.cpp @@ -11,18 +11,18 @@ #include <util/generic/string.h> -#ifdef _win_ +#ifdef _win_ #include "winint.h" #include <io.h> -#endif - +#endif + #ifndef HAVE_NATIVE_GETPROGNAME const char* getprogname() { return GetProgramName().data(); } #endif -#ifdef _win_ +#ifdef _win_ void sleep(i64 len) { Sleep((unsigned long)len * 1000); @@ -35,11 +35,11 @@ void usleep(i64 len) { #include <fcntl.h> int ftruncate(int fd, i64 length) { return _chsize_s(fd, length); -} +} int truncate(const char* name, i64 length) { int fd = ::_open(name, _O_WRONLY); int ret = ftruncate(fd, length); ::close(fd); return ret; } -#endif +#endif diff --git a/util/system/compat.h b/util/system/compat.h index c53dbcca17..e77dbd251b 100644 --- a/util/system/compat.h +++ b/util/system/compat.h @@ -54,14 +54,14 @@ extern "C" { #define pclose _pclose #endif -#ifdef _win_ +#ifdef _win_ #define NAME_MAX FILENAME_MAX #endif #ifdef _sun_ #define NAME_MAX PATH_MAX #endif -#ifdef _win_ +#ifdef _win_ #ifdef sleep // may be defined by perl #undef sleep @@ -72,11 +72,11 @@ void usleep(i64 len); #endif -#ifdef _win_ +#ifdef _win_ int ftruncate(int fd, i64 length); int truncate(const char* name, i64 length); -#endif - +#endif + #if defined(GNUC) #ifndef va_copy #define va_copy __va_copy diff --git a/util/system/context_i686.asm b/util/system/context_i686.asm index 11f8cecc8e..6a334981ba 100644 --- a/util/system/context_i686.asm +++ b/util/system/context_i686.asm @@ -19,25 +19,25 @@ %define VAL JBUF + PTR_SIZE EXPORT __mylongjmp - mov ecx, [esp + JBUF] - mov eax, [esp + VAL] - mov edx, [ecx + MJB_PC*4] - mov ebx, [ecx + MJB_BX*4] - mov esi, [ecx + MJB_SI*4] - mov edi, [ecx + MJB_DI*4] - mov ebp, [ecx + MJB_BP*4] - mov esp, [ecx + MJB_SP*4] + mov ecx, [esp + JBUF] + mov eax, [esp + VAL] + mov edx, [ecx + MJB_PC*4] + mov ebx, [ecx + MJB_BX*4] + mov esi, [ecx + MJB_SI*4] + mov edi, [ecx + MJB_DI*4] + mov ebp, [ecx + MJB_BP*4] + mov esp, [ecx + MJB_SP*4] jmp edx EXPORT __mysetjmp - mov eax, [esp + JMPBUF] - mov [eax + MJB_BX*4], ebx - mov [eax + MJB_SI*4], esi - mov [eax + MJB_DI*4], edi - lea ecx, [esp + JMPBUF] - mov [eax + MJB_SP*4], ecx - mov ecx, [esp + PCOFF] - mov [eax + MJB_PC*4], ecx - mov [eax + MJB_BP*4], ebp - xor eax, eax - ret + mov eax, [esp + JMPBUF] + mov [eax + MJB_BX*4], ebx + mov [eax + MJB_SI*4], esi + mov [eax + MJB_DI*4], edi + lea ecx, [esp + JMPBUF] + mov [eax + MJB_SP*4], ecx + mov ecx, [esp + PCOFF] + mov [eax + MJB_PC*4], ecx + mov [eax + MJB_BP*4], ebp + xor eax, eax + ret diff --git a/util/system/context_x86_64.asm b/util/system/context_x86_64.asm index 8bcc01e4fc..616e553639 100644 --- a/util/system/context_x86_64.asm +++ b/util/system/context_x86_64.asm @@ -1,13 +1,13 @@ [bits 64] - %define MJB_RBX 0 - %define MJB_RBP 1 - %define MJB_R12 2 - %define MJB_R13 3 - %define MJB_R14 4 - %define MJB_R15 5 - %define MJB_RSP 6 - %define MJB_PC 7 + %define MJB_RBX 0 + %define MJB_RBP 1 + %define MJB_R12 2 + %define MJB_R13 3 + %define MJB_R14 4 + %define MJB_R15 5 + %define MJB_RSP 6 + %define MJB_PC 7 %define MJB_SIZE (8*8) EXPORT __mylongjmp diff --git a/util/system/defaults.h b/util/system/defaults.h index dcd7abea38..ca18b0dac2 100644 --- a/util/system/defaults.h +++ b/util/system/defaults.h @@ -81,18 +81,18 @@ #include <alloca.h> #endif -#ifdef NDEBUG +#ifdef NDEBUG #define Y_IF_DEBUG(X) #ifdef __cplusplus constexpr bool Y_IS_DEBUG_BUILD = false; #endif -#else +#else #define Y_IF_DEBUG(X) X #ifdef __cplusplus constexpr bool Y_IS_DEBUG_BUILD = true; #endif -#endif - +#endif + /** * @def Y_ARRAY_SIZE * diff --git a/util/system/error.cpp b/util/system/error.cpp index f778ec42cb..0cbe9fe63e 100644 --- a/util/system/error.cpp +++ b/util/system/error.cpp @@ -16,14 +16,14 @@ #include <unistd.h> #endif -void ClearLastSystemError() { -#if defined(_win_) - SetLastError(0); +void ClearLastSystemError() { +#if defined(_win_) + SetLastError(0); #else errno = 0; -#endif -} - +#endif +} + int LastSystemError() { #if defined(_win_) int ret = GetLastError(); diff --git a/util/system/error.h b/util/system/error.h index 5f2d4cc547..299900a5f3 100644 --- a/util/system/error.h +++ b/util/system/error.h @@ -81,7 +81,7 @@ #define EDQUOT WSAEDQUOT #endif -void ClearLastSystemError(); +void ClearLastSystemError(); int LastSystemError(); void LastSystemErrorText(char* str, size_t size, int code); const char* LastSystemErrorText(int code); diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 7454a4cb94..3cdba4efdd 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -248,7 +248,7 @@ public: if (result.Ptr == (char*)(-1)) { result.Ptr = nullptr; - } + } #if defined(_unix_) } else { result.Ptr = PtrStart_ ? static_cast<caddr_t>(PtrStart_) + base : nullptr; @@ -314,7 +314,7 @@ public: if (PtrStart_) { munmap((caddr_t)PtrStart_, Length_); } -#endif +#endif } inline i64 Length() const noexcept { @@ -345,7 +345,7 @@ private: void* PtrStart_; #endif }; - + TMemoryMap::TMemoryMap(const TString& name) : Impl_(new TImpl(name, EOpenModeFlag::oRdOnly)) { @@ -355,7 +355,7 @@ TMemoryMap::TMemoryMap(const TString& name, EOpenMode om) : Impl_(new TImpl(name, om)) { } - + TMemoryMap::TMemoryMap(const TString& name, i64 length, EOpenMode om) : Impl_(new TImpl(name, length, om)) { @@ -453,27 +453,27 @@ TFileMap::TFileMap(const TString& name, EOpenMode om) : Map_(name, om) { } - + TFileMap::TFileMap(const TString& name, i64 length, EOpenMode om) : Map_(name, length, om) { } - + TFileMap::TFileMap(FILE* f, EOpenMode om, TString dbgName) : Map_(f, om, dbgName) { } - + TFileMap::TFileMap(const TFile& file, EOpenMode om, TString dbgName) : Map_(file, om, dbgName) { } - + TFileMap::TFileMap(const TFileMap& fm) noexcept : Map_(fm.Map_) { } - + void TFileMap::Flush(void* ptr, size_t size, bool sync) { Y_ASSERT(ptr >= Ptr()); Y_ASSERT(static_cast<char*>(ptr) + size <= static_cast<char*>(Ptr()) + MappedSize()); @@ -486,11 +486,11 @@ void TFileMap::Flush(void* ptr, size_t size, bool sync) { if (sync) { FlushViewOfFile(ptr, size); } -#else +#else msync(ptr, size, sync ? MS_SYNC : MS_ASYNC); -#endif +#endif } - + TFileMap::TMapResult TFileMap::Map(i64 offset, size_t size) { Unmap(); Region_ = Map_.Map(offset, size); @@ -508,14 +508,14 @@ void TFileMap::Unmap() { if (!Region_.IsMapped()) { return; } - + if (Map_.Unmap(Region_)) { Region_.Reset(); } else { ythrow yexception() << "can't unmap file"; } } - + TFileMap::~TFileMap() { try { // explicit Unmap() is required because in oNotGreedy mode the Map_ object doesn't own the mapped area diff --git a/util/system/filemap.h b/util/system/filemap.h index 11be64bff4..2d99051a11 100644 --- a/util/system/filemap.h +++ b/util/system/filemap.h @@ -49,13 +49,13 @@ struct TMemoryMapCommon { }; enum EOpenModeFlag { - oRdOnly = 1, - oRdWr = 2, + oRdOnly = 1, + oRdWr = 2, oCopyOnWr = 4, oAccessMask = 7, - oNotGreedy = 8, - oPrecharge = 16, + oNotGreedy = 8, + oPrecharge = 16, oPopulate = 32, // Populate page table entries (see mmap's MAP_POPULATE) }; Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag) @@ -115,7 +115,7 @@ public: TFileMap(FILE* f, EOpenMode om = oRdOnly, TString dbgName = UnknownFileName()); TFileMap(const TFile& file, EOpenMode om = oRdOnly, TString dbgName = UnknownFileName()); TFileMap(const TFileMap& fm) noexcept; - + ~TFileMap(); TMapResult Map(i64 offset, size_t size); @@ -145,7 +145,7 @@ public: inline bool IsOpen() const noexcept { return Map_.IsOpen(); } - + inline bool IsWritable() const noexcept { return Map_.IsWritable(); } @@ -157,7 +157,7 @@ public: inline void* Ptr() const noexcept { return Region_.MappedData(); } - + inline size_t MappedSize() const noexcept { return Region_.MappedSize(); } @@ -232,7 +232,7 @@ public: size_t Size() const { return Size_; } - const T& GetAt(size_t pos) const { + const T& GetAt(size_t pos) const { if (pos < Size_) return Ptr_[pos]; return Dummy(); @@ -258,7 +258,7 @@ public: Y_PURE_FUNCTION bool Empty() const noexcept { return 0 == Size_; - } + } /// for STL compatibility only, Begin() usage is recommended const T* begin() const noexcept { return Begin(); diff --git a/util/system/hostname.cpp b/util/system/hostname.cpp index 386f646d6b..308fea7cf5 100644 --- a/util/system/hostname.cpp +++ b/util/system/hostname.cpp @@ -11,8 +11,8 @@ #if defined(_win_) #include <WinSock2.h> -#endif - +#endif + #include "defaults.h" #include "yassert.h" #include "hostname.h" diff --git a/util/system/tls.cpp b/util/system/tls.cpp index c2f1a04a14..3dbf738d5c 100644 --- a/util/system/tls.cpp +++ b/util/system/tls.cpp @@ -111,7 +111,7 @@ namespace { return MyStorageSlow(); #endif } - + virtual TPerThreadStorage* MyStorageSlow() = 0; virtual ~TGenericTlsBase() = default; diff --git a/util/system/yassert.h b/util/system/yassert.h index 529823440c..2194a90b76 100644 --- a/util/system/yassert.h +++ b/util/system/yassert.h @@ -101,13 +101,13 @@ namespace NPrivate { ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, #expr, " " __VA_ARGS__); \ } \ } while (false) - + #define Y_FAIL(...) \ do { \ ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, nullptr, " " __VA_ARGS__); \ } while (false) -#ifndef NDEBUG +#ifndef NDEBUG /// Assert that depend on NDEBUG macro and outputs message like printf #define Y_VERIFY_DEBUG(expr, ...) \ do { \ @@ -115,7 +115,7 @@ namespace NPrivate { ::NPrivate::Panic(__SOURCE_FILE_IMPL__, __LINE__, __FUNCTION__, #expr, " " __VA_ARGS__); \ } \ } while (false) -#else +#else #define Y_VERIFY_DEBUG(expr, ...) \ do { \ if (false) { \ @@ -123,4 +123,4 @@ namespace NPrivate { Y_UNUSED(__xxx); \ } \ } while (false) -#endif +#endif diff --git a/util/ysafeptr.cpp b/util/ysafeptr.cpp index 96f2514067..01d4ced72c 100644 --- a/util/ysafeptr.cpp +++ b/util/ysafeptr.cpp @@ -1,5 +1,5 @@ #include "ysafeptr.h" - + #ifdef CHECK_YPTR2 Y_POD_THREAD(bool) IObjectBase::DisableThreadCheck; diff --git a/util/ysaveload.cpp b/util/ysaveload.cpp index 1ae3acb01e..150e0e03e5 100644 --- a/util/ysaveload.cpp +++ b/util/ysaveload.cpp @@ -1,4 +1,4 @@ -#include "ysaveload.h" +#include "ysaveload.h" #include <util/generic/buffer.h> |