diff options
author | eeight <eeight@yandex-team.ru> | 2022-02-10 16:46:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:18 +0300 |
commit | 475c0a46f28166e83fd263badc7546377cddcabe (patch) | |
tree | 39c5a49b8aaad78fe390b6f1f2886bdbda40f3e7 /util | |
parent | a6e0145a095c7bb3770d6e07aee301de5c73f96e (diff) | |
download | ydb-475c0a46f28166e83fd263badc7546377cddcabe.tar.gz |
Restoring authorship annotation for <eeight@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
89 files changed, 1614 insertions, 1614 deletions
diff --git a/util/charset/wide.cpp b/util/charset/wide.cpp index a287438ddd..ddf898c1a0 100644 --- a/util/charset/wide.cpp +++ b/util/charset/wide.cpp @@ -1,6 +1,6 @@ #include "wide.h" -#include <util/generic/mem_copy.h> +#include <util/generic/mem_copy.h> #include <util/string/strip.h> namespace { diff --git a/util/charset/wide.h b/util/charset/wide.h index 04e6928aab..3de0b14ca7 100644 --- a/util/charset/wide.h +++ b/util/charset/wide.h @@ -3,7 +3,7 @@ #include "recode_result.h" #include "unidata.h" #include "utf8.h" -#include "wide_specific.h" +#include "wide_specific.h" #include <util/generic/algorithm.h> #include <util/generic/string.h> diff --git a/util/charset/wide_ut.cpp b/util/charset/wide_ut.cpp index d8f3233e73..579d75a52d 100644 --- a/util/charset/wide_ut.cpp +++ b/util/charset/wide_ut.cpp @@ -3,8 +3,8 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/string/reverse.h> - +#include <util/string/reverse.h> + #include <algorithm> namespace { @@ -613,9 +613,9 @@ public: s = w; Collapse(s); UNIT_ASSERT(s == w); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.c_str() == w.c_str()); // Collapse() does not change the string at all -#endif +#endif } s = ASCIIToWide(" 123 456 "); Collapse(s); @@ -641,9 +641,9 @@ public: s = w; Collapse(s); UNIT_ASSERT(s == w); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.c_str() == w.c_str()); // Collapse() does not change the string at all -#endif +#endif } s = ASCIIToWide(" "); Collapse(s); @@ -774,21 +774,21 @@ public: s = w; Strip(s); UNIT_ASSERT(s == w); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.c_str() == w.c_str()); // Strip() does not change the string at all -#endif +#endif s = w; StripLeft(s); UNIT_ASSERT(s == w); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.c_str() == w.c_str()); // Strip() does not change the string at all -#endif +#endif s = w; StripRight(s); UNIT_ASSERT(s == w); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.c_str() == w.c_str()); // Strip() does not change the string at all -#endif +#endif } void TestIsSpace() { @@ -865,7 +865,7 @@ public: wchar16 upperCase[n]; std::copy(wideCyrillicAlphabet, wideCyrillicAlphabet + n, upperCase); ToLower(upperCase, n); - UNIT_ASSERT(TWtringBuf(upperCase, n) == TWtringBuf(wideCyrillicAlphabet + n, n)); + UNIT_ASSERT(TWtringBuf(upperCase, n) == TWtringBuf(wideCyrillicAlphabet + n, n)); } void TestToUpper() { @@ -873,7 +873,7 @@ public: wchar16 lowerCase[n]; std::copy(wideCyrillicAlphabet + n, wideCyrillicAlphabet + n * 2, lowerCase); ToUpper(lowerCase, n); - UNIT_ASSERT(TWtringBuf(lowerCase, n) == TWtringBuf(wideCyrillicAlphabet, n)); + UNIT_ASSERT(TWtringBuf(lowerCase, n) == TWtringBuf(wideCyrillicAlphabet, n)); } void TestWideString() { @@ -912,7 +912,7 @@ public: const TUtf16String reversed = UTF32ToWide(buffer.data(), buffer.size()); temp = original; - ReverseInPlace(temp); + ReverseInPlace(temp); UNIT_ASSERT(temp == reversed); } @@ -1099,9 +1099,9 @@ public: UNIT_ASSERT(!ToLower(s)); UNIT_ASSERT(s == lower); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == lower); @@ -1120,9 +1120,9 @@ public: UNIT_ASSERT(!ToLower(s)); UNIT_ASSERT(s == lower); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == lower); @@ -1140,9 +1140,9 @@ public: UNIT_ASSERT(!ToLower(s, 100500)); UNIT_ASSERT(s == lower); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(ToLowerRet(copy, 100500) == lower); UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 100500) == lower); @@ -1154,9 +1154,9 @@ public: UNIT_ASSERT(!ToLower(s, 100500, 1111)); UNIT_ASSERT(s == lower); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(ToLowerRet(copy, 100500, 1111) == lower); UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 100500, 1111) == lower); @@ -1187,9 +1187,9 @@ public: UNIT_ASSERT(!ToLower(s)); UNIT_ASSERT(s == lower); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == lower); @@ -1208,9 +1208,9 @@ public: UNIT_ASSERT(!ToLower(s)); UNIT_ASSERT(s == lower); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToLower(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == lower); @@ -1257,9 +1257,9 @@ public: UNIT_ASSERT(!ToLower(s, 2)); UNIT_ASSERT(s == lower); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(ToLowerRet(copy, 2) == lower); UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 2) == lower); @@ -1282,9 +1282,9 @@ public: UNIT_ASSERT(!ToLower(s, 3, 1)); UNIT_ASSERT(s == copy); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(ToLowerRet(copy, 3, 1) == lower); UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 3, 1) == lower); @@ -1296,9 +1296,9 @@ public: UNIT_ASSERT(!ToLower(s, 3, 100500)); UNIT_ASSERT(s == copy); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(ToLowerRet(copy, 3, 100500) == lower); UNIT_ASSERT(ToLowerRet(TWtringBuf(copy), 3, 100500) == lower); @@ -1314,9 +1314,9 @@ public: UNIT_ASSERT(!ToUpper(s)); UNIT_ASSERT(s == upper); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == upper); @@ -1335,9 +1335,9 @@ public: UNIT_ASSERT(!ToUpper(s)); UNIT_ASSERT(s == upper); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == upper); @@ -1356,9 +1356,9 @@ public: UNIT_ASSERT(!ToUpper(s, 100500)); UNIT_ASSERT(s == upper); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == upper); @@ -1376,9 +1376,9 @@ public: UNIT_ASSERT(!ToUpper(s, 100500, 1111)); UNIT_ASSERT(s == upper); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(ToUpperRet(copy, 100500, 1111) == upper); UNIT_ASSERT(ToUpperRet(TWtringBuf(copy), 100500, 1111) == upper); @@ -1409,9 +1409,9 @@ public: UNIT_ASSERT(!ToUpper(s)); UNIT_ASSERT(s == copy); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToUpper(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == upper); @@ -1531,9 +1531,9 @@ public: UNIT_ASSERT(!ToTitle(s)); UNIT_ASSERT(s == title); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == title); @@ -1552,9 +1552,9 @@ public: UNIT_ASSERT(!ToTitle(s)); UNIT_ASSERT(s == title); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == title); @@ -1572,9 +1572,9 @@ public: UNIT_ASSERT(!ToTitle(s, 100500)); UNIT_ASSERT(s == title); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(ToTitleRet(copy) == title); UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title); @@ -1586,9 +1586,9 @@ public: UNIT_ASSERT(!ToTitle(s, 100500, 1111)); UNIT_ASSERT(s == title); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(ToTitleRet(copy) == title); UNIT_ASSERT(ToTitleRet(TWtringBuf(copy)) == title); @@ -1619,9 +1619,9 @@ public: UNIT_ASSERT(!ToTitle(s)); UNIT_ASSERT(s == title); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == title); @@ -1658,9 +1658,9 @@ public: UNIT_ASSERT(!ToTitle(s)); UNIT_ASSERT(s == title); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(!ToTitle(writableCopy.Detach(), writableCopy.size())); UNIT_ASSERT(writableCopy == title); @@ -1707,9 +1707,9 @@ public: UNIT_ASSERT(!ToTitle(s, 2)); UNIT_ASSERT(s == title); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.data() == copy.data()); -#endif +#endif UNIT_ASSERT(ToTitleRet(copy, 2) == title); UNIT_ASSERT(ToTitleRet(TWtringBuf(copy), 2) == title); diff --git a/util/charset/ya.make b/util/charset/ya.make index 26d38cb10b..de467c7f6a 100644 --- a/util/charset/ya.make +++ b/util/charset/ya.make @@ -5,10 +5,10 @@ SUBSCRIBER(g:util-subscribers) NO_UTIL() -IF (TSTRING_IS_STD_STRING) - CFLAGS(GLOBAL -DTSTRING_IS_STD_STRING) -ENDIF() - +IF (TSTRING_IS_STD_STRING) + CFLAGS(GLOBAL -DTSTRING_IS_STD_STRING) +ENDIF() + JOIN_SRCS( all_charset.cpp generated/unidata.cpp diff --git a/util/draft/holder_vector_ut.cpp b/util/draft/holder_vector_ut.cpp index f64393860a..0926df8312 100644 --- a/util/draft/holder_vector_ut.cpp +++ b/util/draft/holder_vector_ut.cpp @@ -25,8 +25,8 @@ Y_UNIT_TEST_SUITE(THolderVectorTest) { ints.PushBack(new int(1)); UNIT_ASSERT_VALUES_EQUAL(*ints[0], 0); UNIT_ASSERT_VALUES_EQUAL(*ints[1], 1); - ints.Reset(0, MakeHolder<int>(2)); - ints.Reset(1, MakeHolder<int>(3)); + ints.Reset(0, MakeHolder<int>(2)); + ints.Reset(1, MakeHolder<int>(3)); UNIT_ASSERT_VALUES_EQUAL(*ints[0], 2); UNIT_ASSERT_VALUES_EQUAL(*ints[1], 3); } @@ -35,7 +35,7 @@ Y_UNIT_TEST_SUITE(THolderVectorTest) { THolderVector<int> ints; ints.Resize(1); UNIT_ASSERT_EQUAL(ints[0], (int*)nullptr); - ints.Reset(0, MakeHolder<int>(1)); + ints.Reset(0, MakeHolder<int>(1)); UNIT_ASSERT_UNEQUAL(ints[0], (int*)nullptr); UNIT_ASSERT_VALUES_EQUAL(*ints[0], 1); } diff --git a/util/draft/ip.h b/util/draft/ip.h index eb947cd2cd..6647cc6348 100644 --- a/util/draft/ip.h +++ b/util/draft/ip.h @@ -91,7 +91,7 @@ inline void Out<TIp6>(IOutputStream& os, const TIp6& a) { os << Ip6ToString(a); } -using TIp4Or6 = std::variant<TIp4, TIp6>; +using TIp4Or6 = std::variant<TIp4, TIp6>; static inline TIp4Or6 Ip4Or6FromString(const char* ipStr) { const char* c = ipStr; @@ -107,10 +107,10 @@ static inline TIp4Or6 Ip4Or6FromString(const char* ipStr) { } static inline TString Ip4Or6ToString(const TIp4Or6& ip) { - if (std::holds_alternative<TIp6>(ip)) { - return Ip6ToString(std::get<TIp6>(ip)); + if (std::holds_alternative<TIp6>(ip)) { + return Ip6ToString(std::get<TIp6>(ip)); } else { - return IpToString(std::get<TIp4>(ip)); + return IpToString(std::get<TIp4>(ip)); } } diff --git a/util/draft/ya.make b/util/draft/ya.make index e00674b682..4756a982eb 100644 --- a/util/draft/ya.make +++ b/util/draft/ya.make @@ -5,10 +5,10 @@ SUBSCRIBER(g:util-subscribers) NO_UTIL() -IF (TSTRING_IS_STD_STRING) - CFLAGS(GLOBAL -DTSTRING_IS_STD_STRING) -ENDIF() - +IF (TSTRING_IS_STD_STRING) + CFLAGS(GLOBAL -DTSTRING_IS_STD_STRING) +ENDIF() + SRCS( date.cpp datetime.cpp diff --git a/util/folder/dirut.cpp b/util/folder/dirut.cpp index ffc9b09f96..b081c5e0f6 100644 --- a/util/folder/dirut.cpp +++ b/util/folder/dirut.cpp @@ -601,17 +601,17 @@ int ResolvePath(const char* rel, const char* abs, char res[/*MAXPATHLEN*/], bool return 0; } -TString ResolvePath(const char* rel, const char* abs, bool isdir) { +TString ResolvePath(const char* rel, const char* abs, bool isdir) { char buf[PATH_MAX]; - if (ResolvePath(rel, abs, buf, isdir)) - ythrow yexception() << "cannot resolve path: \"" << rel << "\""; + if (ResolvePath(rel, abs, buf, isdir)) + ythrow yexception() << "cannot resolve path: \"" << rel << "\""; return buf; } -TString ResolvePath(const char* path, bool isDir) { - return ResolvePath(path, nullptr, isDir); -} - +TString ResolvePath(const char* path, bool isDir) { + return ResolvePath(path, nullptr, isDir); +} + TString StripFileComponent(const TString& fileName) { TString dir = IsDir(fileName) ? fileName : GetDirName(fileName); if (!dir.empty() && dir.back() != GetDirectorySeparator()) { diff --git a/util/folder/dirut.h b/util/folder/dirut.h index 2537027b12..3e40048362 100644 --- a/util/folder/dirut.h +++ b/util/folder/dirut.h @@ -76,7 +76,7 @@ TString GetSystemTempDir(); int MakeTempDir(char path[/*FILENAME_MAX*/], const char* prefix); int ResolvePath(const char* rel, const char* abs, char res[/*FILENAME_MAX*/], bool isdir = false); -TString ResolvePath(const char* rel, const char* abs, bool isdir = false); +TString ResolvePath(const char* rel, const char* abs, bool isdir = false); TString ResolvePath(const char* path, bool isDir = false); TString ResolveDir(const char* path); diff --git a/util/folder/path.cpp b/util/folder/path.cpp index bfe0c67d68..13df9269cb 100644 --- a/util/folder/path.cpp +++ b/util/folder/path.cpp @@ -3,7 +3,7 @@ #include "pathsplit.h" #include <util/generic/yexception.h> -#include <util/string/cast.h> +#include <util/string/cast.h> #include <util/system/compiler.h> #include <util/system/file.h> #include <util/system/fs.h> diff --git a/util/folder/tempdir.cpp b/util/folder/tempdir.cpp index 6fdf8f753c..cb4a2cc4ba 100644 --- a/util/folder/tempdir.cpp +++ b/util/folder/tempdir.cpp @@ -6,11 +6,11 @@ #include <util/system/maxlen.h> TTempDir::TTempDir() - : TTempDir(nullptr, TCreationToken{}) -{ -} - -TTempDir::TTempDir(const char* prefix, TCreationToken) + : TTempDir(nullptr, TCreationToken{}) +{ +} + +TTempDir::TTempDir(const char* prefix, TCreationToken) : TempDir() , Remove(true) { @@ -29,10 +29,10 @@ TTempDir::TTempDir(const TString& tempDir) MakeDirIfNotExist(TempDir.c_str()); } -TTempDir TTempDir::NewTempDir(const TString& root) { - return {root.c_str(), TCreationToken{}}; -} - +TTempDir TTempDir::NewTempDir(const TString& root) { + return {root.c_str(), TCreationToken{}}; +} + void TTempDir::DoNotRemove() { Remove = false; } diff --git a/util/folder/tempdir.h b/util/folder/tempdir.h index ff458f83b9..6acea134eb 100644 --- a/util/folder/tempdir.h +++ b/util/folder/tempdir.h @@ -6,17 +6,17 @@ class TTempDir { public: - /// Create new directory in system tmp folder. + /// Create new directory in system tmp folder. TTempDir(); - - /// Create new directory with this fixed name. If it already exists, clear it. + + /// Create new directory with this fixed name. If it already exists, clear it. TTempDir(const TString& tempDir); - + ~TTempDir(); - /// Create new directory in given folder. - static TTempDir NewTempDir(const TString& root); - + /// Create new directory in given folder. + static TTempDir NewTempDir(const TString& root); + const TString& operator()() const { return Name(); } @@ -32,12 +32,12 @@ public: void DoNotRemove(); private: - struct TCreationToken {}; - - // Prevent people from confusing this ctor with the public one - // by requiring additional fake argument. - TTempDir(const char* prefix, TCreationToken); - + struct TCreationToken {}; + + // Prevent people from confusing this ctor with the public one + // by requiring additional fake argument. + TTempDir(const char* prefix, TCreationToken); + TFsPath TempDir; bool Remove; }; diff --git a/util/generic/bitops.h b/util/generic/bitops.h index 2db15fc59b..9e31bf18d3 100644 --- a/util/generic/bitops.h +++ b/util/generic/bitops.h @@ -449,11 +449,11 @@ void SetBits(T& value, T bits) { value &= ~(maxValue << Offset); value |= bits << Offset; } - -inline constexpr ui64 NthBit64(int bit) { - return ui64(1) << bit; -} - -inline constexpr ui64 Mask64(int bits) { - return NthBit64(bits) - 1; -} + +inline constexpr ui64 NthBit64(int bit) { + return ui64(1) << bit; +} + +inline constexpr ui64 Mask64(int bits) { + return NthBit64(bits) - 1; +} diff --git a/util/generic/buffer.cpp b/util/generic/buffer.cpp index b92697e1d0..d0ba5fab85 100644 --- a/util/generic/buffer.cpp +++ b/util/generic/buffer.cpp @@ -1,6 +1,6 @@ -#include "buffer.h" -#include "mem_copy.h" -#include "string.h" +#include "buffer.h" +#include "mem_copy.h" +#include "string.h" #include "ymath.h" #include <util/system/sys_alloc.h> diff --git a/util/generic/cast.h b/util/generic/cast.h index 0d4a41f385..10278b6b62 100644 --- a/util/generic/cast.h +++ b/util/generic/cast.h @@ -5,7 +5,7 @@ #include <util/system/compat.h> #include <util/system/type_name.h> -#include <util/system/unaligned_mem.h> +#include <util/system/unaligned_mem.h> #include <util/system/yassert.h> #include <cstdlib> @@ -158,19 +158,19 @@ template <typename T> constexpr std::underlying_type_t<T> ToUnderlying(const T enum_) noexcept { return static_cast<std::underlying_type_t<T>>(enum_); } - -// std::bit_cast from c++20 -template <class TTarget, class TSource> -TTarget BitCast(const TSource& source) { - static_assert(sizeof(TSource) == sizeof(TTarget), "Size mismatch"); - static_assert(std::is_trivially_copyable<TSource>::value, "TSource is not trivially copyable"); - static_assert(std::is_trivial<TTarget>::value, "TTarget is not trivial"); - - // Support volatile qualifiers. - // ReadUnaligned does not work with volatile pointers, so cast away - // volatileness beforehand. - using TNonvolatileSource = std::remove_volatile_t<TSource>; - using TNonvolatileTarget = std::remove_volatile_t<TTarget>; - - return ReadUnaligned<TNonvolatileTarget>(&const_cast<const TNonvolatileSource&>(source)); -} + +// std::bit_cast from c++20 +template <class TTarget, class TSource> +TTarget BitCast(const TSource& source) { + static_assert(sizeof(TSource) == sizeof(TTarget), "Size mismatch"); + static_assert(std::is_trivially_copyable<TSource>::value, "TSource is not trivially copyable"); + static_assert(std::is_trivial<TTarget>::value, "TTarget is not trivial"); + + // Support volatile qualifiers. + // ReadUnaligned does not work with volatile pointers, so cast away + // volatileness beforehand. + using TNonvolatileSource = std::remove_volatile_t<TSource>; + using TNonvolatileTarget = std::remove_volatile_t<TTarget>; + + return ReadUnaligned<TNonvolatileTarget>(&const_cast<const TNonvolatileSource&>(source)); +} diff --git a/util/generic/cast_ut.cpp b/util/generic/cast_ut.cpp index 718a8de79d..1f73066ccd 100644 --- a/util/generic/cast_ut.cpp +++ b/util/generic/cast_ut.cpp @@ -8,7 +8,7 @@ class TGenericCastsTest: public TTestBase { UNIT_TEST(TestIntegralCast) UNIT_TEST(TestEnumCast) UNIT_TEST(TestToUnderlying) - UNIT_TEST(TestBitCast) + UNIT_TEST(TestBitCast) UNIT_TEST_SUITE_END(); private: @@ -81,32 +81,32 @@ private: UNIT_ASSERT_VALUES_EQUAL(static_cast<std::underlying_type_t<B>>(BM1), ToUnderlying(BM1)); UNIT_ASSERT_VALUES_EQUAL(static_cast<std::underlying_type_t<C>>(C::CM1), ToUnderlying(C::CM1)); } - - void TestBitCast() { - // Change sign of float - { + + void TestBitCast() { + // Change sign of float + { const float floatValue = 17.33f; - ui32 ui32Value = BitCast<ui32>(floatValue); - ui32Value ^= (ui32)1 << 31; - UNIT_ASSERT_VALUES_EQUAL(-floatValue, BitCast<float>(ui32Value)); - } - - // Unpack ui64 into a struct - { - const ui64 value = 0x1122334455667788; - struct TStruct { - ui32 a; - ui16 b; - ui8 c; - ui8 d; - }; - auto structValue = BitCast<TStruct>(value); - UNIT_ASSERT_VALUES_EQUAL(structValue.a, 0x55667788); - UNIT_ASSERT_VALUES_EQUAL(structValue.b, 0x3344); - UNIT_ASSERT_VALUES_EQUAL(structValue.c, 0x22); - UNIT_ASSERT_VALUES_EQUAL(structValue.d, 0x11); - } - } + ui32 ui32Value = BitCast<ui32>(floatValue); + ui32Value ^= (ui32)1 << 31; + UNIT_ASSERT_VALUES_EQUAL(-floatValue, BitCast<float>(ui32Value)); + } + + // Unpack ui64 into a struct + { + const ui64 value = 0x1122334455667788; + struct TStruct { + ui32 a; + ui16 b; + ui8 c; + ui8 d; + }; + auto structValue = BitCast<TStruct>(value); + UNIT_ASSERT_VALUES_EQUAL(structValue.a, 0x55667788); + UNIT_ASSERT_VALUES_EQUAL(structValue.b, 0x3344); + UNIT_ASSERT_VALUES_EQUAL(structValue.c, 0x22); + UNIT_ASSERT_VALUES_EQUAL(structValue.d, 0x11); + } + } }; UNIT_TEST_SUITE_REGISTRATION(TGenericCastsTest); diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp index 8b907457bc..c56cfade60 100644 --- a/util/generic/guid.cpp +++ b/util/generic/guid.cpp @@ -42,7 +42,7 @@ TGUID TGUID::Create() { } void CreateGuid(TGUID* res) { - ui64* dw = reinterpret_cast<ui64*>(res->dw); + ui64* dw = reinterpret_cast<ui64*>(res->dw); WriteUnaligned<ui64>(&dw[0], RandomNumber<ui64>()); WriteUnaligned<ui64>(&dw[1], RandomNumber<ui64>()); diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..320691f0c9 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1623,18 +1623,18 @@ public: } template <class TheKey> - bool contains(const TheKey& key) const { - return rep.find(key) != rep.end(); - } - bool contains(const key_type& key) const { - return rep.find(key) != rep.end(); - } - - template <class TheKey> - bool contains(const TheKey& key, insert_ctx& ins) { - return rep.find_i(key, ins) != rep.end(); - } - + bool contains(const TheKey& key) const { + return rep.find(key) != rep.end(); + } + bool contains(const key_type& key) const { + return rep.find(key) != rep.end(); + } + + template <class TheKey> + bool contains(const TheKey& key, insert_ctx& ins) { + return rep.find_i(key, ins) != rep.end(); + } + template <class TKey> T& operator[](const TKey& key) { insert_ctx ctx = nullptr; @@ -1935,10 +1935,10 @@ public: } template <class TheKey> - bool contains(const TheKey& key) const { - return rep.find(key) != rep.end(); - } - + bool contains(const TheKey& key) const { + return rep.find(key) != rep.end(); + } + template <class TKey> size_type count(const TKey& key) const { return rep.count(key); @@ -2021,9 +2021,9 @@ template <class Key, class T, class HF, class EqKey, class Alloc> inline bool operator!=(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm2) { return !(hm1 == hm2); } - -// Cannot name it just 'Hash' because it clashes with too many class members in the code. -template <class T> -size_t ComputeHash(const T& value) { - return THash<T>{}(value); -} + +// Cannot name it just 'Hash' because it clashes with too many class members in the code. +template <class T> +size_t ComputeHash(const T& value) { + return THash<T>{}(value); +} diff --git a/util/generic/hash.pxd b/util/generic/hash.pxd index 385c10d805..828c5e04ef 100644 --- a/util/generic/hash.pxd +++ b/util/generic/hash.pxd @@ -47,7 +47,7 @@ cdef extern from "util/generic/hash.h" nogil: void erase(iterator, iterator) except + size_t erase(T&) iterator find(T&) - bint contains(T&) + bint contains(T&) const_iterator const_find "find"(T&) pair[iterator, bint] insert(pair[T, U]) # XXX pair[T,U]& iterator insert(iterator, pair[T, U]) # XXX pair[T,U]& diff --git a/util/generic/hash_set.h b/util/generic/hash_set.h index e8088cf23b..f7cb6839c8 100644 --- a/util/generic/hash_set.h +++ b/util/generic/hash_set.h @@ -200,14 +200,14 @@ public: } template <class TheKey> - bool contains(const TheKey& key) const { - return rep.find(key) != rep.end(); - } - template <class TheKey> - bool contains(const TheKey& key, insert_ctx& ins) { - return rep.find_i(key, ins) != rep.end(); - } - + bool contains(const TheKey& key) const { + return rep.find(key) != rep.end(); + } + template <class TheKey> + bool contains(const TheKey& key, insert_ctx& ins) { + return rep.find_i(key, ins) != rep.end(); + } + template <class TKey> size_type count(const TKey& key) const { return rep.count(key); @@ -266,7 +266,7 @@ inline bool operator==(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, con return false; } for (const auto& it : hs1) { - if (!hs2.contains(it)) { + if (!hs2.contains(it)) { return false; } } diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 0551d58770..5804a53dca 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -177,9 +177,9 @@ void THashTest::TestHMap1() { m['x'] = "10"; // Correct mistake. UNIT_ASSERT(!strcmp(m['x'].c_str(), "10")); - UNIT_ASSERT(!m.contains('z')); + UNIT_ASSERT(!m.contains('z')); UNIT_ASSERT(!strcmp(m['z'].c_str(), "")); - UNIT_ASSERT(m.contains('z')); + UNIT_ASSERT(m.contains('z')); UNIT_ASSERT(m.count('z') == 1); auto p = m.insert(std::pair<const char, TString>('c', TString("100"))); @@ -377,34 +377,34 @@ void THashTest::TestHSetConstructorsAndAssignments() { UNIT_ASSERT_VALUES_EQUAL(2, c1.size()); UNIT_ASSERT_VALUES_EQUAL(2, c2.size()); - UNIT_ASSERT(c1.contains(100)); - UNIT_ASSERT(c2.contains(200)); + UNIT_ASSERT(c1.contains(100)); + UNIT_ASSERT(c2.contains(200)); container c3(std::move(c1)); UNIT_ASSERT_VALUES_EQUAL(0, c1.size()); UNIT_ASSERT_VALUES_EQUAL(2, c3.size()); - UNIT_ASSERT(c3.contains(100)); + UNIT_ASSERT(c3.contains(100)); c2.insert(300); c3 = c2; UNIT_ASSERT_VALUES_EQUAL(3, c2.size()); UNIT_ASSERT_VALUES_EQUAL(3, c3.size()); - UNIT_ASSERT(c3.contains(300)); + UNIT_ASSERT(c3.contains(300)); c2.insert(400); c3 = std::move(c2); UNIT_ASSERT_VALUES_EQUAL(0, c2.size()); UNIT_ASSERT_VALUES_EQUAL(4, c3.size()); - UNIT_ASSERT(c3.contains(400)); + UNIT_ASSERT(c3.contains(400)); container c4 = {1, 2, 3}; UNIT_ASSERT_VALUES_EQUAL(c4.size(), 3); - UNIT_ASSERT(c4.contains(1)); - UNIT_ASSERT(c4.contains(2)); - UNIT_ASSERT(c4.contains(3)); + UNIT_ASSERT(c4.contains(1)); + UNIT_ASSERT(c4.contains(2)); + UNIT_ASSERT(c4.contains(3)); } void THashTest::TestHSetSize() { @@ -1010,31 +1010,31 @@ void THashTest::TestHMMapEmplaceDirect() { void THashTest::TestHSetEmplace() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; hash_t hash; - UNIT_ASSERT(!hash.contains(0)); + UNIT_ASSERT(!hash.contains(0)); hash.emplace(0); - UNIT_ASSERT(hash.contains(0)); - UNIT_ASSERT(!hash.contains(1)); + UNIT_ASSERT(hash.contains(0)); + UNIT_ASSERT(!hash.contains(1)); } void THashTest::TestHSetEmplaceNoresize() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; hash_t hash; hash.reserve(1); - UNIT_ASSERT(!hash.contains(0)); + UNIT_ASSERT(!hash.contains(0)); hash.emplace_noresize(0); - UNIT_ASSERT(hash.contains(0)); - UNIT_ASSERT(!hash.contains(1)); + UNIT_ASSERT(hash.contains(0)); + UNIT_ASSERT(!hash.contains(1)); } void THashTest::TestHSetEmplaceDirect() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; hash_t hash; - UNIT_ASSERT(!hash.contains(0)); + UNIT_ASSERT(!hash.contains(0)); hash_t::insert_ctx ins; hash.find(0, ins); hash.emplace_direct(ins, 1); - UNIT_ASSERT(hash.contains(0)); - UNIT_ASSERT(!hash.contains(1)); + UNIT_ASSERT(hash.contains(0)); + UNIT_ASSERT(!hash.contains(1)); } void THashTest::TestNonCopyable() { @@ -1100,8 +1100,8 @@ void THashTest::TestReleaseNodes() { set.insert(i); } UNIT_ASSERT_VALUES_EQUAL(counters.Allocations, 7); - UNIT_ASSERT(set.contains(10)); - UNIT_ASSERT(!set.contains(0)); + UNIT_ASSERT(set.contains(10)); + UNIT_ASSERT(!set.contains(0)); set.basic_clear(); UNIT_ASSERT_VALUES_EQUAL(counters.Deallocations, 3); diff --git a/util/generic/hash_ut.pyx b/util/generic/hash_ut.pyx index ecf6dac2e6..3eb50fc950 100644 --- a/util/generic/hash_ut.pyx +++ b/util/generic/hash_ut.pyx @@ -24,8 +24,8 @@ class TestHash(unittest.TestCase): self.assertEqual(2, c1.size()) self.assertEqual(2, c2.size()) self.assertEqual(1, c1.at("one")) - self.assertTrue(c1.contains("two")) - self.assertTrue(c2.contains("one")) + self.assertTrue(c1.contains("two")) + self.assertTrue(c2.contains("one")) self.assertEqual(2, c2.at("two")) c2["three"] = 3 c1 = c2 diff --git a/util/generic/map.h b/util/generic/map.h index b5001b56c0..8a1533755d 100644 --- a/util/generic/map.h +++ b/util/generic/map.h @@ -22,9 +22,9 @@ public: return !this->empty(); } - inline bool contains(const K& key) const { - return this->find(key) != this->end(); - } + inline bool contains(const K& key) const { + return this->find(key) != this->end(); + } }; template <class K, class V, class Less, class A> @@ -38,7 +38,7 @@ public: return !this->empty(); } - inline bool contains(const K& key) const { - return this->find(key) != this->end(); - } + inline bool contains(const K& key) const { + return this->find(key) != this->end(); + } }; diff --git a/util/generic/map_ut.cpp b/util/generic/map_ut.cpp index 79e832b024..3fb0f800f4 100644 --- a/util/generic/map_ut.cpp +++ b/util/generic/map_ut.cpp @@ -468,7 +468,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { {"two", -2}, {"three", 3}, }; - UNIT_ASSERT(mm.contains("two")); + UNIT_ASSERT(mm.contains("two")); TMultiMap<TString, int> expected; expected.emplace("one", 1); expected.emplace("two", 2); @@ -485,12 +485,12 @@ Y_UNIT_TEST_SUITE(TYMapTest) { TMapInPool m(&pool); m.emplace(0, 1); - UNIT_ASSERT(m.contains(0)); + UNIT_ASSERT(m.contains(0)); UNIT_ASSERT_VALUES_EQUAL(1, m[0]); TMapInPool movedM = std::move(m); - UNIT_ASSERT(movedM.contains(0)); + UNIT_ASSERT(movedM.contains(0)); UNIT_ASSERT_VALUES_EQUAL(1, movedM[0]); } } diff --git a/util/generic/overloaded.h b/util/generic/overloaded.h index 96a97e44bc..c531f74fd8 100644 --- a/util/generic/overloaded.h +++ b/util/generic/overloaded.h @@ -3,9 +3,9 @@ /** * Construct an ad-hoc object with an overloaded `operator()`. * - * Typically used with lambdas to construct type-matching visitors for e.g. std::variant: + * Typically used with lambdas to construct type-matching visitors for e.g. std::variant: * ``` - * std::variant<int, void*, TString> var; + * std::variant<int, void*, TString> var; * Visit(TOverloaded{ * [](int val) { Cerr << "int: " << val; }, * [](void* val) { Cerr << "ptr: " << val; }, @@ -22,7 +22,7 @@ * For example, the following code will compile and run by casting all values to * double: * ``` - * std::variant<int, double, char> var; + * std::variant<int, double, char> var; * Visit(TOverloaded{ * [](double val) { Cerr << "dbl: " << val; }, * }, var); @@ -31,7 +31,7 @@ * If cases may be ambigous or specific type-matching logic is required, * a verbose `if constexpr`-based version would be preferred: * ``` - * std::variant<int, double, char> var; + * std::variant<int, double, char> var; * Visit([](auto&& val) { * using T = std::decay_t<decltype(val)>; * if constexpr (std::is_same_v<T, int>) { diff --git a/util/generic/overloaded_ut.cpp b/util/generic/overloaded_ut.cpp index f3d73895ad..57c3f284a6 100644 --- a/util/generic/overloaded_ut.cpp +++ b/util/generic/overloaded_ut.cpp @@ -28,13 +28,13 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) { } Y_UNIT_TEST(VariantTest) { - std::variant<int, double, TType1> v = 5; + std::variant<int, double, TType1> v = 5; int res = 0; - std::visit(TOverloaded{ - [&](int val) { res = val; }, - [&](double) { res = -1; }, - [&](TType1) { res = -1; }}, - v); + std::visit(TOverloaded{ + [&](int val) { res = val; }, + [&](double) { res = -1; }, + [&](TType1) { res = -1; }}, + v); UNIT_ASSERT_VALUES_EQUAL(res, 5); } @@ -52,16 +52,16 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) { } Y_UNIT_TEST(ImplicitConversionsTest) { - using TTestVariant = std::variant<int, double, char>; + using TTestVariant = std::variant<int, double, char>; // Purposefully exhibit inexact overload matched with implicit type // conversions // All cases implicitly cast to int auto matchAsInt = [](TTestVariant var) { - return std::visit(TOverloaded{ - [](int val) { return val; }, - }, var); + return std::visit(TOverloaded{ + [](int val) { return val; }, + }, var); }; UNIT_ASSERT_VALUES_EQUAL(matchAsInt(TTestVariant{17.77}), 17); @@ -70,9 +70,9 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) { // All cases implicitly cast to double auto matchAsDouble = [](TTestVariant var) { - return std::visit(TOverloaded{ - [](double val) { return val; }, - }, var); + return std::visit(TOverloaded{ + [](double val) { return val; }, + }, var); }; UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{17.77}), 17.77); diff --git a/util/generic/ptr.h b/util/generic/ptr.h index 19db0e3ec5..f38a3e44ca 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -12,9 +12,9 @@ #include <util/system/yassert.h> #include <util/system/defaults.h> -template <class T, class U> -using TGuardConversion = typename std::enable_if_t<std::is_convertible<U*, T*>::value>; - +template <class T, class U> +using TGuardConversion = typename std::enable_if_t<std::is_convertible<U*, T*>::value>; + template <class T> inline void AssertTypeComplete() { // If compiler triggers this error from destructor of your class with @@ -242,7 +242,7 @@ public: { } - explicit THolder(T* t) noexcept + explicit THolder(T* t) noexcept : T_(t) { } @@ -252,7 +252,7 @@ public: { } - template <class U, class = TGuardConversion<T, U>> + template <class U, class = TGuardConversion<T, U>> inline THolder(TAutoPtr<U, D> t) noexcept : T_(t.Release()) { @@ -263,7 +263,7 @@ public: { } - template <class U, class = TGuardConversion<T, U>> + template <class U, class = TGuardConversion<T, U>> inline THolder(THolder<U, D>&& that) noexcept : T_(that.Release()) { @@ -346,7 +346,7 @@ private: template <typename T, typename... Args> [[nodiscard]] THolder<T> MakeHolder(Args&&... args) { - return THolder<T>(new T(std::forward<Args>(args)...)); + return THolder<T>(new T(std::forward<Args>(args)...)); } /* @@ -475,12 +475,12 @@ public: template <class T, class Ops> class TIntrusivePtr: public TPointerBase<TIntrusivePtr<T, Ops>, T> { - template <class U, class O> - friend class TIntrusivePtr; - - template <class U, class O> - friend class TIntrusiveConstPtr; + template <class U, class O> + friend class TIntrusivePtr; + template <class U, class O> + friend class TIntrusiveConstPtr; + public: struct TNoIncrement { }; @@ -517,20 +517,20 @@ public: // void Func(TIntrusivePtr<B>); // ... // Func(TIntrusivePtr<A>(new A)); // <--- compiler can't decide which version of Func to use - template <class U, class = TGuardConversion<T, U>> - inline TIntrusivePtr(const TIntrusivePtr<U>& p) noexcept + template <class U, class = TGuardConversion<T, U>> + inline TIntrusivePtr(const TIntrusivePtr<U>& p) noexcept : T_(p.Get()) { Ref(); } - template <class U, class = TGuardConversion<T, U>> - inline TIntrusivePtr(TIntrusivePtr<U>&& p) noexcept - : T_(p.T_) - { - p.T_ = nullptr; - } - + template <class U, class = TGuardConversion<T, U>> + inline TIntrusivePtr(TIntrusivePtr<U>&& p) noexcept + : T_(p.T_) + { + p.T_ = nullptr; + } + inline TIntrusivePtr(TIntrusivePtr&& p) noexcept : T_(nullptr) { @@ -637,26 +637,26 @@ public: Swap(p); } - inline TIntrusiveConstPtr(TIntrusivePtr<T> p) noexcept - : T_(p.T_) + inline TIntrusiveConstPtr(TIntrusivePtr<T> p) noexcept + : T_(p.T_) { - p.T_ = nullptr; + p.T_ = nullptr; } - template <class U, class = TGuardConversion<T, U>> - inline TIntrusiveConstPtr(const TIntrusiveConstPtr<U>& p) noexcept + template <class U, class = TGuardConversion<T, U>> + inline TIntrusiveConstPtr(const TIntrusiveConstPtr<U>& p) noexcept : T_(p.T_) { Ref(); } - template <class U, class = TGuardConversion<T, U>> - inline TIntrusiveConstPtr(TIntrusiveConstPtr<U>&& p) noexcept - : T_(p.T_) - { - p.T_ = nullptr; - } - + template <class U, class = TGuardConversion<T, U>> + inline TIntrusiveConstPtr(TIntrusiveConstPtr<U>&& p) noexcept + : T_(p.T_) + { + p.T_ = nullptr; + } + inline TIntrusiveConstPtr& operator=(TIntrusiveConstPtr p) noexcept { p.Swap(*this); @@ -816,7 +816,7 @@ public: { } - template <class TT, class = TGuardConversion<T, TT>> + template <class TT, class = TGuardConversion<T, TT>> inline TSharedPtr(THolder<TT>&& t) { Init(t); } @@ -839,7 +839,7 @@ public: Swap(t); } - template <class TT, class = TGuardConversion<T, TT>> + template <class TT, class = TGuardConversion<T, TT>> inline TSharedPtr(const TSharedPtr<TT, C, D>& t) noexcept : T_(t.T_) , C_(t.C_) @@ -847,15 +847,15 @@ public: Ref(); } - template <class TT, class = TGuardConversion<T, TT>> - inline TSharedPtr(TSharedPtr<TT, C, D>&& t) noexcept - : T_(t.T_) - , C_(t.C_) - { - t.T_ = nullptr; - t.C_ = nullptr; - } - + template <class TT, class = TGuardConversion<T, TT>> + inline TSharedPtr(TSharedPtr<TT, C, D>&& t) noexcept + : T_(t.T_) + , C_(t.C_) + { + t.T_ = nullptr; + t.C_ = nullptr; + } + inline TSharedPtr& operator=(TSharedPtr t) noexcept { t.Swap(*this); diff --git a/util/generic/serialized_enum.h b/util/generic/serialized_enum.h index 79df2bac22..74228a0609 100644 --- a/util/generic/serialized_enum.h +++ b/util/generic/serialized_enum.h @@ -375,7 +375,7 @@ namespace NEnumSerializationRuntime { } bool contains(const TEnumType key) const { - return Ref.contains(this->CastToRepresentationType(key)); + return Ref.contains(this->CastToRepresentationType(key)); } TIterator find(const TEnumType key) const { diff --git a/util/generic/set.h b/util/generic/set.h index 4c437ca26f..3573ee9f8e 100644 --- a/util/generic/set.h +++ b/util/generic/set.h @@ -20,9 +20,9 @@ public: } template <class TheKey> - inline bool contains(const TheKey& key) const { - return this->find(key) != this->end(); - } + inline bool contains(const TheKey& key) const { + return this->find(key) != this->end(); + } }; template <class K, class L, class A> @@ -34,9 +34,9 @@ public: inline explicit operator bool() const noexcept { return !this->empty(); } - - template <class TheKey> - inline bool contains(const TheKey& key) const { - return this->find(key) != this->end(); - } + + template <class TheKey> + inline bool contains(const TheKey& key) const { + return this->find(key) != this->end(); + } }; diff --git a/util/generic/set_ut.cpp b/util/generic/set_ut.cpp index d2769d327f..3308651a51 100644 --- a/util/generic/set_ut.cpp +++ b/util/generic/set_ut.cpp @@ -73,20 +73,20 @@ Y_UNIT_TEST_SUITE(YSetTest) { Y_UNIT_TEST(TestHas) { TSet<int> s; - UNIT_ASSERT(!s.contains(0)); + UNIT_ASSERT(!s.contains(0)); TSet<int> const& crs = s; - UNIT_ASSERT(!crs.contains(0)); + UNIT_ASSERT(!crs.contains(0)); s.insert(1); s.insert(42); s.insert(100); s.insert(2); - UNIT_ASSERT(s.contains(1)); - UNIT_ASSERT(s.contains(2)); - UNIT_ASSERT(s.contains(42)); - UNIT_ASSERT(s.contains(100)); + UNIT_ASSERT(s.contains(1)); + UNIT_ASSERT(s.contains(2)); + UNIT_ASSERT(s.contains(42)); + UNIT_ASSERT(s.contains(100)); } Y_UNIT_TEST(TestBounds) { @@ -203,28 +203,28 @@ Y_UNIT_TEST_SUITE(YSetTest) { UNIT_ASSERT_VALUES_EQUAL(2, c1.size()); UNIT_ASSERT_VALUES_EQUAL(2, c2.size()); - UNIT_ASSERT(c1.contains(100)); - UNIT_ASSERT(c2.contains(200)); + UNIT_ASSERT(c1.contains(100)); + UNIT_ASSERT(c2.contains(200)); container c3(std::move(c1)); UNIT_ASSERT_VALUES_EQUAL(0, c1.size()); UNIT_ASSERT_VALUES_EQUAL(2, c3.size()); - UNIT_ASSERT(c3.contains(100)); + UNIT_ASSERT(c3.contains(100)); c2.insert(300); c3 = c2; UNIT_ASSERT_VALUES_EQUAL(3, c2.size()); UNIT_ASSERT_VALUES_EQUAL(3, c3.size()); - UNIT_ASSERT(c3.contains(300)); + UNIT_ASSERT(c3.contains(300)); c2.insert(400); c3 = std::move(c2); UNIT_ASSERT_VALUES_EQUAL(0, c2.size()); UNIT_ASSERT_VALUES_EQUAL(4, c3.size()); - UNIT_ASSERT(c3.contains(400)); + UNIT_ASSERT(c3.contains(400)); } { diff --git a/util/generic/strbase.h b/util/generic/strbase.h index ab39fc7537..425755cfbc 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -37,7 +37,7 @@ namespace NStringPrivate { template <typename TDerived, typename TCharType, typename TTraitsType = std::char_traits<TCharType>> class TStringBase { using TStringView = std::basic_string_view<TCharType>; - using TStringViewWithTraits = std::basic_string_view<TCharType, TTraitsType>; + using TStringViewWithTraits = std::basic_string_view<TCharType, TTraitsType>; public: using TChar = TCharType; @@ -115,11 +115,11 @@ public: template <class TCharTraits> inline constexpr operator std::basic_string_view<TCharType, TCharTraits>() const { - return std::basic_string_view<TCharType, TCharTraits>(data(), size()); + return std::basic_string_view<TCharType, TCharTraits>(data(), size()); } template <class TCharTraits, class Allocator> - inline explicit operator std::basic_string<TCharType, TCharTraits, Allocator>() const { + inline explicit operator std::basic_string<TCharType, TCharTraits, Allocator>() const { return std::basic_string<TCharType, TCharTraits, Allocator>(Ptr(), Len()); } @@ -219,17 +219,17 @@ private: public: // ~~~ Comparison ~~~ : FAMILY0(int, compare) static int compare(const TSelf& s1, const TSelf& s2) noexcept { - return s1.AsStringView().compare(s2.AsStringView()); + return s1.AsStringView().compare(s2.AsStringView()); } static int compare(const TCharType* p, const TSelf& s2) noexcept { - TCharType null{0}; - return TStringViewWithTraits(p ? p : &null).compare(s2.AsStringView()); + 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); + TCharType null{0}; + return s1.AsStringView().compare(p ? p : &null); } static int compare(const TStringView s1, const TStringView s2) noexcept { @@ -258,7 +258,7 @@ public: } static bool equal(const TSelf& s1, const TSelf& s2) noexcept { - return s1.AsStringView() == s2.AsStringView(); + return s1.AsStringView() == s2.AsStringView(); } static bool equal(const TSelf& s1, const TCharType* p) noexcept { @@ -266,7 +266,7 @@ public: return s1.Len() == 0; } - return s1.AsStringView() == p; + return s1.AsStringView() == p; } static bool equal(const TCharType* p, const TSelf& s2) noexcept { @@ -274,7 +274,7 @@ public: } static bool equal(const TStringView s1, const TStringView s2) noexcept { - return TStringViewWithTraits{s1.data(), s1.size()} == TStringViewWithTraits{s2.data(), s2.size()}; + return TStringViewWithTraits{s1.data(), s1.size()} == TStringViewWithTraits{s2.data(), s2.size()}; } template <class T> @@ -295,11 +295,11 @@ public: } static inline bool StartsWith(const TCharType* what, size_t whatLen, const TCharType* with, size_t withLen) noexcept { - return withLen <= whatLen && TStringViewWithTraits(what, withLen) == TStringViewWithTraits(with, withLen); + return withLen <= whatLen && TStringViewWithTraits(what, withLen) == TStringViewWithTraits(with, withLen); } static inline bool EndsWith(const TCharType* what, size_t whatLen, const TCharType* with, size_t withLen) noexcept { - return withLen <= whatLen && TStringViewWithTraits(what + whatLen - withLen, withLen) == TStringViewWithTraits(with, withLen); + return withLen <= whatLen && TStringViewWithTraits(what + whatLen - withLen, withLen) == TStringViewWithTraits(with, withLen); } inline bool StartsWith(const TCharType* s, size_t n) const noexcept { @@ -311,7 +311,7 @@ public: } inline bool StartsWith(TCharType ch) const noexcept { - return !empty() && TTraits::eq(*Ptr(), ch); + return !empty() && TTraits::eq(*Ptr(), ch); } inline bool EndsWith(const TCharType* s, size_t n) const noexcept { @@ -323,7 +323,7 @@ public: } inline bool EndsWith(TCharType ch) const noexcept { - return !empty() && TTraits::eq(Ptr()[Len() - 1], ch); + return !empty() && TTraits::eq(Ptr()[Len() - 1], ch); } template <typename TDerived2, typename TTraits2> @@ -449,30 +449,30 @@ public: * @return Position of the substring inside this string, or `npos` if not found. */ inline size_t find(const TStringView s, size_t pos = 0) const noexcept { - return find(s.data(), pos, s.size()); + return find(s.data(), pos, s.size()); } inline size_t find(const TCharType* s, size_t pos, size_t count) const noexcept { - return AsStringView().find(s, pos, count); + return AsStringView().find(s, pos, count); } inline size_t find(TCharType c, size_t pos = 0) const noexcept { - return AsStringView().find(c, pos); + return AsStringView().find(c, pos); } inline size_t rfind(TCharType c) const noexcept { - return AsStringView().rfind(c); + return AsStringView().rfind(c); } inline size_t rfind(TCharType c, size_t pos) const noexcept { - if (pos == 0) { - return npos; + if (pos == 0) { + return npos; } - return AsStringView().rfind(c, pos - 1); + return AsStringView().rfind(c, pos - 1); } inline size_t rfind(const TStringView str, size_t pos = npos) const { - return AsStringView().rfind(str.data(), pos, str.size()); + return AsStringView().rfind(str.data(), pos, str.size()); } //~~~~Contains~~~~ @@ -505,7 +505,7 @@ public: } inline size_t find_first_of(const TStringView set, size_t pos) const noexcept { - return AsStringView().find_first_of(set.data(), pos, set.size()); + return AsStringView().find_first_of(set.data(), pos, set.size()); } inline size_t find_first_not_of(TCharType c) const noexcept { @@ -521,7 +521,7 @@ public: } inline size_t find_first_not_of(const TStringView set, size_t pos) const noexcept { - return AsStringView().find_first_not_of(set.data(), pos, set.size()); + return AsStringView().find_first_not_of(set.data(), pos, set.size()); } inline size_t find_last_of(TCharType c, size_t pos = npos) const noexcept { @@ -533,11 +533,11 @@ public: } inline size_t find_last_of(const TCharType* set, size_t pos, size_t n) const noexcept { - return AsStringView().find_last_of(set, pos, n); + return AsStringView().find_last_of(set, pos, n); } inline size_t find_last_not_of(TCharType c, size_t pos = npos) const noexcept { - return AsStringView().find_last_not_of(c, pos); + return AsStringView().find_last_not_of(c, pos); } inline size_t find_last_not_of(const TStringView set, size_t pos = npos) const noexcept { @@ -545,7 +545,7 @@ public: } inline size_t find_last_not_of(const TCharType* set, size_t pos, size_t n) const noexcept { - return AsStringView().find_last_not_of(set, pos, n); + return AsStringView().find_last_not_of(set, pos, n); } inline size_t copy(TCharType* pc, size_t n, size_t pos) const { @@ -581,8 +581,8 @@ public: private: using GenericFinder = const TCharType* (*)(const TCharType*, size_t, const TCharType*, size_t); - TStringViewWithTraits AsStringView() const { - return static_cast<TStringViewWithTraits>(*this); + TStringViewWithTraits AsStringView() const { + return static_cast<TStringViewWithTraits>(*this); } constexpr inline const TCharType* Ptr() const noexcept { diff --git a/util/generic/string.h b/util/generic/string.h index 8cd8aa6917..e69704a79b 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -18,7 +18,7 @@ #include "singleton.h" #include "strbase.h" #include "strbuf.h" -#include "string_hash.h" +#include "string_hash.h" #if defined(address_sanitizer_enabled) || defined(thread_sanitizer_enabled) #include "hide_ptr.h" @@ -153,7 +153,7 @@ private: TStringType& S_; size_t Pos_; }; -#endif +#endif template <typename TCharType, typename TTraits> class TBasicString: public TStringBase<TBasicString<TCharType, TTraits>, TCharType, TTraits> { @@ -161,14 +161,14 @@ public: // TODO: Move to private section using TBase = TStringBase<TBasicString, TCharType, TTraits>; using TStringType = std::basic_string<TCharType, TTraits>; -#ifdef TSTRING_IS_STD_STRING +#ifdef TSTRING_IS_STD_STRING using TStorage = TStringType; using reference = typename TStorage::reference; -#else +#else using TStdStr = TStdString<TStringType>; using TStorage = TIntrusivePtr<TStdStr, TStringPtrOps<TStdStr>>; using reference = TBasicCharRef<TBasicString>; -#endif +#endif using char_type = TCharType; // TODO: DROP using value_type = TCharType; using traits_type = TTraits; @@ -188,16 +188,16 @@ public: size_t Size; }; - static size_t max_size() noexcept { + static size_t max_size() noexcept { static size_t res = TStringType().max_size(); return res; } protected: -#ifdef TSTRING_IS_STD_STRING - TStorage Storage_; -#else +#ifdef TSTRING_IS_STD_STRING + TStorage Storage_; +#else TStorage S_; template <typename... A> @@ -259,11 +259,11 @@ public: inline reference operator[](size_t pos) noexcept { Y_ASSERT(pos <= length()); -#ifdef TSTRING_IS_STD_STRING - return Storage_[pos]; -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_[pos]; +#else return reference(*this, pos); -#endif +#endif } using TBase::back; @@ -271,15 +271,15 @@ public: inline reference back() noexcept { Y_ASSERT(!this->empty()); -#ifdef TSTRING_IS_STD_STRING - return Storage_.back(); -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_.back(); +#else if (Y_UNLIKELY(this->empty())) { return reference(*this, 0); } return reference(*this, length() - 1); -#endif +#endif } using TBase::front; @@ -287,11 +287,11 @@ public: inline reference front() noexcept { Y_ASSERT(!this->empty()); -#ifdef TSTRING_IS_STD_STRING - return Storage_.front(); -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_.front(); +#else return reference(*this, 0); -#endif +#endif } inline size_t length() const noexcept { @@ -333,80 +333,80 @@ public: using TBase::rend; //!< const_reverse_iterator TStringBase::rend() const inline size_t capacity() const noexcept { -#ifdef TSTRING_IS_STD_STRING - return Storage_.capacity(); -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_.capacity(); +#else if (S_->IsNull()) { return 0; } return S_->capacity(); -#endif +#endif } TCharType* Detach() { -#ifdef TSTRING_IS_STD_STRING - return Storage_.data(); -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_.data(); +#else if (Y_UNLIKELY(!IsDetached())) { Clone(); } return (TCharType*)S_->data(); -#endif +#endif } bool IsDetached() const { -#ifdef TSTRING_IS_STD_STRING - return true; -#else +#ifdef TSTRING_IS_STD_STRING + return true; +#else return 1 == RefCount(); -#endif +#endif } // ~~~ Size and capacity ~~~ TBasicString& resize(size_t n, TCharType c = ' ') { // remove or append MutRef().resize(n, c); - - return *this; + + return *this; } // ~~~ Constructor ~~~ : FAMILY0(,TBasicString) TBasicString() noexcept -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING : S_(Construct()) -#endif +#endif { } inline explicit TBasicString(::NDetail::TReserveTag rt) -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING : S_(Construct()) -#endif +#endif { reserve(rt.Capacity); } inline TBasicString(const TBasicString& s) -#ifdef TSTRING_IS_STD_STRING - : Storage_(s.Storage_) -#else +#ifdef TSTRING_IS_STD_STRING + : Storage_(s.Storage_) +#else : S_(s.S_) -#endif +#endif { } inline TBasicString(TBasicString&& s) noexcept -#ifdef TSTRING_IS_STD_STRING - : Storage_(std::move(s.Storage_)) -#else +#ifdef TSTRING_IS_STD_STRING + : Storage_(std::move(s.Storage_)) +#else : S_(Construct()) -#endif +#endif { #ifdef TSTRING_IS_STD_STRING #else s.swap(*this); -#endif +#endif } template <typename T, typename A> @@ -426,41 +426,41 @@ public: } TBasicString(const TBasicString& s, size_t pos, size_t n) Y_NOEXCEPT -#ifdef TSTRING_IS_STD_STRING - : Storage_(s.Storage_, pos, n) +#ifdef TSTRING_IS_STD_STRING + : Storage_(s.Storage_, pos, n) #else : S_(n ? Construct(s, pos, n) : Construct()) -#endif - { +#endif + { } - TBasicString(const TCharType* pc) + TBasicString(const TCharType* pc) : TBasicString(pc, TBase::StrLen(pc)) - { + { } // TODO thegeorg@: uncomment and fix clients // TBasicString(std::nullptr_t) = delete; - TBasicString(const TCharType* pc, size_t n) -#ifdef TSTRING_IS_STD_STRING - : Storage_(pc, n) + TBasicString(const TCharType* pc, size_t n) +#ifdef TSTRING_IS_STD_STRING + : Storage_(pc, n) #else : S_(n ? Construct(pc, n) : Construct()) -#endif - { +#endif + { } TBasicString(std::nullptr_t, size_t) = delete; - TBasicString(const TCharType* pc, size_t pos, size_t n) + TBasicString(const TCharType* pc, size_t pos, size_t n) : TBasicString(pc + pos, n) - { + { } #ifdef TSTRING_IS_STD_STRING explicit TBasicString(TExplicitType<TCharType> c) { - Storage_.push_back(c); + Storage_.push_back(c); } -#else +#else explicit TBasicString(TExplicitType<TCharType> c) : TBasicString(&c.Value(), 1) { @@ -469,15 +469,15 @@ public: : TBasicString(&c, 1) { } -#endif +#endif - TBasicString(size_t n, TCharType c) -#ifdef TSTRING_IS_STD_STRING - : Storage_(n, c) + TBasicString(size_t n, TCharType c) +#ifdef TSTRING_IS_STD_STRING + : Storage_(n, c) #else : S_(Construct(n, c)) -#endif - { +#endif + { } /** @@ -489,13 +489,13 @@ public: TBasicString(TUninitialized uninitialized) { #if !defined(TSTRING_IS_STD_STRING) S_ = Construct(); -#endif +#endif ReserveAndResize(uninitialized.Size); } - TBasicString(const TCharType* b, const TCharType* e) + TBasicString(const TCharType* b, const TCharType* e) : TBasicString(b, e - b) - { + { } explicit TBasicString(const TBasicStringBuf<TCharType, TTraits> s) @@ -504,14 +504,14 @@ public: } template <typename Traits> - explicit inline TBasicString(const std::basic_string_view<TCharType, Traits>& s) + explicit inline TBasicString(const std::basic_string_view<TCharType, Traits>& s) : TBasicString(s.data(), s.size()) - { + { } /** - * WARN: - * Certain invocations of this method will result in link-time error. + * WARN: + * Certain invocations of this method will result in link-time error. * You are free to implement corresponding methods in string.cpp if you need them. */ static TBasicString FromAscii(const ::TStringBuf& s) { @@ -562,9 +562,9 @@ private: public: inline void clear() noexcept { -#ifdef TSTRING_IS_STD_STRING - Storage_.clear(); -#else +#ifdef TSTRING_IS_STD_STRING + Storage_.clear(); +#else if (IsDetached()) { S_->clear(); @@ -572,7 +572,7 @@ public: } Construct().Swap(S_); -#endif +#endif } template <typename... R> @@ -655,8 +655,8 @@ public: } /** - * WARN: - * Certain invocations of this method will result in link-time error. + * WARN: + * Certain invocations of this method will result in link-time error. * You are free to implement corresponding methods in string.cpp if you need them. */ auto AssignAscii(const ::TStringBuf& s) { @@ -720,20 +720,20 @@ public: inline TBasicString& append(const TBasicString& s) { MutRef().append(s.ConstRef()); - - return *this; + + return *this; } inline TBasicString& append(const TBasicString& s, size_t pos, size_t n) { MutRef().append(s.ConstRef(), pos, n); - - return *this; + + return *this; } inline TBasicString& append(const TCharType* pc) Y_NOEXCEPT { MutRef().append(pc); - - return *this; + + return *this; } inline TBasicString& append(TCharType c) { @@ -744,14 +744,14 @@ public: inline TBasicString& append(const TCharType* first, const TCharType* last) { MutRef().append(first, last); - - return *this; + + return *this; } inline TBasicString& append(const TCharType* pc, size_t len) { MutRef().append(pc, len); - - return *this; + + return *this; } inline void ReserveAndResize(size_t len) { @@ -786,12 +786,12 @@ 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)); + return append(pc + pos, Min(n, pc_len - pos)); } /** - * WARN: - * Certain invocations of this method will result in link-time error. + * WARN: + * Certain invocations of this method will result in link-time error. * You are free to implement corresponding methods in string.cpp if you need them. */ TBasicString& AppendAscii(const ::TStringBuf& s); @@ -836,8 +836,8 @@ public: operator const TStringType&() const noexcept { return this->ConstRef(); - } - + } + operator TStringType&() { return this->MutRef(); } @@ -879,7 +879,7 @@ public: s2.prepend(s1); return std::move(s2); } -#endif +#endif s1 += s2; return std::move(s1); } @@ -948,32 +948,32 @@ public: // ~~~ Prepending ~~~ : FAMILY0(TBasicString&, prepend); TBasicString& prepend(const TBasicString& s) { MutRef().insert(0, s.ConstRef()); - - return *this; + + return *this; } TBasicString& prepend(const TBasicString& s, size_t pos, size_t n) { MutRef().insert(0, s.ConstRef(), pos, n); - - return *this; + + return *this; } TBasicString& prepend(const TCharType* pc) { MutRef().insert(0, pc); - - return *this; + + return *this; } TBasicString& prepend(size_t n, TCharType c) { MutRef().insert(size_t(0), n, c); - - return *this; + + return *this; } TBasicString& prepend(TCharType c) { MutRef().insert(size_t(0), 1, c); - - return *this; + + return *this; } TBasicString& prepend(const TBasicStringBuf<TCharType, TTraits> s, size_t spos = 0, size_t sn = TBase::npos) { @@ -983,42 +983,42 @@ public: // ~~~ Insertion ~~~ : FAMILY1(TBasicString&, insert, size_t pos); TBasicString& insert(size_t pos, const TBasicString& s) { MutRef().insert(pos, s.ConstRef()); - - return *this; + + 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; + + return *this; } TBasicString& insert(size_t pos, const TCharType* pc) { MutRef().insert(pos, pc); - - return *this; + + return *this; } TBasicString& insert(size_t pos, const TCharType* pc, size_t len) { MutRef().insert(pos, pc, len); - - return *this; + + return *this; } TBasicString& insert(const_iterator pos, const_iterator b, const_iterator e) { -#ifdef TSTRING_IS_STD_STRING - Storage_.insert(Storage_.begin() + this->off(pos), b, e); - - return *this; -#else +#ifdef TSTRING_IS_STD_STRING + Storage_.insert(Storage_.begin() + this->off(pos), b, e); + + return *this; +#else return insert(this->off(pos), b, e - b); -#endif +#endif } TBasicString& insert(size_t pos, size_t n, TCharType c) { MutRef().insert(pos, n, c); - - return *this; + + return *this; } TBasicString& insert(const_iterator pos, size_t len, TCharType ch) { @@ -1031,8 +1031,8 @@ public: TBasicString& insert(size_t pos, const TBasicStringBuf<TCharType, TTraits> s, size_t spos = 0, size_t sn = TBase::npos) { MutRef().insert(pos, s, spos, sn); - - return *this; + + return *this; } // ~~~ Removing ~~~ @@ -1040,8 +1040,8 @@ public: if (pos < length()) { MutRef().erase(pos, n); } - - return *this; + + return *this; } TBasicString& remove(size_t pos = 0) Y_NOEXCEPT { @@ -1054,8 +1054,8 @@ public: TBasicString& erase(size_t pos = 0, size_t n = TBase::npos) Y_NOEXCEPT { MutRef().erase(pos, n); - - return *this; + + return *this; } TBasicString& erase(const_iterator b, const_iterator e) Y_NOEXCEPT { @@ -1068,10 +1068,10 @@ public: TBasicString& pop_back() Y_NOEXCEPT { Y_ASSERT(!this->empty()); - + MutRef().pop_back(); - return *this; + return *this; } // ~~~ replacement ~~~ : FAMILY2(TBasicString&, replace, size_t pos, size_t n); @@ -1118,11 +1118,11 @@ public: } void swap(TBasicString& s) noexcept { -#ifdef TSTRING_IS_STD_STRING - std::swap(Storage_, s.Storage_); -#else +#ifdef TSTRING_IS_STD_STRING + std::swap(Storage_, s.Storage_); +#else S_.Swap(s.S_); -#endif +#endif } /** @@ -1166,15 +1166,15 @@ public: bool changed = false; for (size_t i = pos; i != pos + n; ++i) { -#ifdef TSTRING_IS_STD_STRING - auto c = f(i, Storage_[i]); - - if (c != Storage_[i]) { - changed = true; - - Storage_[i] = c; - } -#else +#ifdef TSTRING_IS_STD_STRING + auto c = f(i, Storage_[i]); + + if (c != Storage_[i]) { + changed = true; + + Storage_[i] = c; + } +#else auto c = f(i, data()[i]); if (c != data()[i]) { if (!changed) { @@ -1184,7 +1184,7 @@ public: begin()[i] = c; } -#endif +#endif } return changed; @@ -1221,7 +1221,7 @@ namespace std { using argument_type = TString; using result_type = size_t; inline result_type operator()(argument_type const& s) const noexcept { - return NHashPrivate::ComputeStringHash(s.data(), s.size()); + return NHashPrivate::ComputeStringHash(s.data(), s.size()); } }; } diff --git a/util/generic/string_hash.h b/util/generic/string_hash.h index b949c7a2d9..23f1798c68 100644 --- a/util/generic/string_hash.h +++ b/util/generic/string_hash.h @@ -1,21 +1,21 @@ -#pragma once - -#include <cstddef> - -// reduce code bloat and cycled includes, declare functions here -#if defined(_64_) && !defined(NO_CITYHASH) -ui64 CityHash64(const char* buf, size_t len) noexcept; -#else -size_t MurmurHashSizeT(const char* buf, size_t len) noexcept; -#endif - -namespace NHashPrivate { - template <typename C> - size_t ComputeStringHash(const C* ptr, size_t size) noexcept { -#if defined(_64_) && !defined(NO_CITYHASH) +#pragma once + +#include <cstddef> + +// reduce code bloat and cycled includes, declare functions here +#if defined(_64_) && !defined(NO_CITYHASH) +ui64 CityHash64(const char* buf, size_t len) noexcept; +#else +size_t MurmurHashSizeT(const char* buf, size_t len) noexcept; +#endif + +namespace NHashPrivate { + template <typename C> + size_t ComputeStringHash(const C* ptr, size_t size) noexcept { +#if defined(_64_) && !defined(NO_CITYHASH) return CityHash64((const char*)ptr, size * sizeof(C)); -#else +#else return MurmurHashSizeT((const char*)ptr, size * sizeof(C)); -#endif - } -} +#endif + } +} diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp index ac82e9091d..c5f3531fa6 100644 --- a/util/generic/string_ut.cpp +++ b/util/generic/string_ut.cpp @@ -1,24 +1,24 @@ #include "deque.h" -#include "strbuf.h" -#include "string_ut.h" +#include "strbuf.h" +#include "string_ut.h" #include "vector.h" #include "yexception.h" #include <util/charset/wide.h> #include <util/str_stl.h> -#include <util/stream/output.h> -#include <util/string/subst.h> +#include <util/stream/output.h> +#include <util/string/subst.h> #include <string> #include <sstream> #include <algorithm> #include <stdexcept> -#ifdef TSTRING_IS_STD_STRING -static_assert(sizeof(TString) == sizeof(std::string), "expect sizeof(TString) == sizeof(std::string)"); -#else +#ifdef TSTRING_IS_STD_STRING +static_assert(sizeof(TString) == sizeof(std::string), "expect sizeof(TString) == sizeof(std::string)"); +#else static_assert(sizeof(TString) == sizeof(const char*), "expect sizeof(TString) == sizeof(const char*)"); -#endif +#endif class TStringTestZero: public TTestBase { UNIT_TEST_SUITE(TStringTestZero); @@ -50,7 +50,7 @@ public: TString copy = s; copy.replace(copy.size() - 1, 1, "z"); UNIT_ASSERT(s != copy); - copy.replace(copy.size() - 1, 1, "\0", 0, 1); + copy.replace(copy.size() - 1, 1, "\0", 0, 1); UNIT_ASSERT(s == copy); TString prefix(data, 5); @@ -70,9 +70,9 @@ UNIT_TEST_SUITE_REGISTRATION(TStringTestZero); template <typename TStringType, typename TTestData> class TStringStdTestImpl { - using TChar = typename TStringType::char_type; - using TTraits = typename TStringType::traits_type; - using TView = std::basic_string_view<TChar, TTraits>; + using TChar = typename TStringType::char_type; + using TTraits = typename TStringType::traits_type; + using TView = std::basic_string_view<TChar, TTraits>; TTestData Data_; @@ -121,7 +121,7 @@ protected: s.reserve(10); #ifdef TSTRING_IS_STD_STRING - UNIT_ASSERT(s.capacity() >= 64); + UNIT_ASSERT(s.capacity() >= 64); #else UNIT_ASSERT(s.capacity() >= 256 && s.data() == data); #endif @@ -147,7 +147,7 @@ protected: UNIT_ASSERT(s.capacity() >= 64 && s.capacity() < 128 && s.data() != data); UNIT_ASSERT(s.IsDetached()); #endif -#endif +#endif } void short_string() { @@ -511,7 +511,7 @@ protected: void copy() { TStringType s(Data_.foo()); - TChar dest[4]; + TChar dest[4]; dest[0] = dest[1] = dest[2] = dest[3] = 1; s.copy(dest, 4); int pos = 0; @@ -712,7 +712,7 @@ protected: UNIT_ASSERT(str == Data.This_This_is_test_StringT_for_StringT_calls()); #if !defined(STLPORT) || defined(_STLP_MEMBER_TEMPLATES) - deque<TChar> cdeque; + deque<TChar> cdeque; cdeque.push_back(*Data.I()); str.replace(str.begin(), str.begin() + 11, cdeque.begin(), cdeque.end()); UNIT_ASSERT(str == Data.Is_test_StringT_for_StringT_calls()); @@ -727,9 +727,9 @@ public: UNIT_TEST(TestMaxSize); UNIT_TEST(TestConstructors); UNIT_TEST(TestReplace); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestRefCount); -#endif +#endif UNIT_TEST(TestFind); UNIT_TEST(TestContains); UNIT_TEST(TestOperators); @@ -741,9 +741,9 @@ public: UNIT_TEST(TestCopy); UNIT_TEST(TestStrCpy); UNIT_TEST(TestPrefixSuffix); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestCharRef); -#endif +#endif UNIT_TEST(TestBack) UNIT_TEST(TestFront) UNIT_TEST(TestIterators); @@ -788,9 +788,9 @@ public: UNIT_TEST_SUITE(TWideStringTest); UNIT_TEST(TestConstructors); UNIT_TEST(TestReplace); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestRefCount); -#endif +#endif UNIT_TEST(TestFind); UNIT_TEST(TestContains); UNIT_TEST(TestOperators); @@ -803,9 +803,9 @@ public: UNIT_TEST(TestCopy); UNIT_TEST(TestStrCpy); UNIT_TEST(TestPrefixSuffix); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestCharRef); -#endif +#endif UNIT_TEST(TestBack); UNIT_TEST(TestFront) UNIT_TEST(TestDecodingMethods); @@ -912,9 +912,9 @@ public: UNIT_TEST_SUITE(TUtf32StringTest); UNIT_TEST(TestConstructors); UNIT_TEST(TestReplace); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestRefCount); -#endif +#endif UNIT_TEST(TestFind); UNIT_TEST(TestContains); UNIT_TEST(TestOperators); @@ -927,9 +927,9 @@ public: UNIT_TEST(TestCopy); UNIT_TEST(TestStrCpy); UNIT_TEST(TestPrefixSuffix); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestCharRef); -#endif +#endif UNIT_TEST(TestBack); UNIT_TEST(TestFront) UNIT_TEST(TestDecodingMethods); diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index 44bb10bdeb..1f5255d4fe 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -1,513 +1,513 @@ -#pragma once - +#pragma once + #include "string.h" #include <library/cpp/testing/unittest/registar.h> -#include <util/string/reverse.h> - -template <typename CharT, size_t N> -struct TCharBuffer { - CharT Data[N]; - //! copies characters from string to the internal buffer without any conversion - //! @param s a string that must contain only characters less than 0x7F - explicit TCharBuffer(const char* s) { - // copy all symbols including null terminated symbol - for (size_t i = 0; i < N; ++i) { - Data[i] = s[i]; - } - } - const CharT* GetData() const { - return Data; - } -}; - -template <> -struct TCharBuffer<char, 0> { - const char* Data; - //! stores pointer to string - explicit TCharBuffer(const char* s) - : Data(s) - { - } - const char* GetData() const { - return Data; - } -}; - -#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 { - // words - const CharT* str1() { - DECLARE_AND_RETURN_BUFFER("str1"); - } - const CharT* str2() { - DECLARE_AND_RETURN_BUFFER("str2"); - } - const CharT* str__________________________________________________1() { - DECLARE_AND_RETURN_BUFFER("str 1"); - } - const CharT* str__________________________________________________2() { - DECLARE_AND_RETURN_BUFFER("str 2"); - } - const CharT* one() { - DECLARE_AND_RETURN_BUFFER("one"); - } - const CharT* two() { - DECLARE_AND_RETURN_BUFFER("two"); - } - const CharT* three() { - DECLARE_AND_RETURN_BUFFER("three"); - } - const CharT* thrii() { - DECLARE_AND_RETURN_BUFFER("thrii"); - } - const CharT* four() { - DECLARE_AND_RETURN_BUFFER("four"); - } - const CharT* enotw_() { - DECLARE_AND_RETURN_BUFFER("enotw "); - } - const CharT* foo() { - DECLARE_AND_RETURN_BUFFER("foo"); - } - const CharT* abcdef() { - DECLARE_AND_RETURN_BUFFER("abcdef"); - } - const CharT* abcdefg() { - DECLARE_AND_RETURN_BUFFER("abcdefg"); - } - const CharT* aba() { - DECLARE_AND_RETURN_BUFFER("aba"); - } - const CharT* hr() { - DECLARE_AND_RETURN_BUFFER("hr"); - } - const CharT* hrt() { - DECLARE_AND_RETURN_BUFFER("hrt"); - } - const CharT* thr() { - DECLARE_AND_RETURN_BUFFER("thr"); - } - const CharT* tw() { - DECLARE_AND_RETURN_BUFFER("tw"); - } - const CharT* ow() { - DECLARE_AND_RETURN_BUFFER("ow"); - } - const CharT* opq() { - DECLARE_AND_RETURN_BUFFER("opq"); - } - const CharT* xyz() { - DECLARE_AND_RETURN_BUFFER("xyz"); - } - const CharT* abc() { - DECLARE_AND_RETURN_BUFFER("abc"); - } - const CharT* abcd() { - DECLARE_AND_RETURN_BUFFER("abcd"); - } - const CharT* abcde() { - DECLARE_AND_RETURN_BUFFER("abcde"); - } - const CharT* abcc() { - DECLARE_AND_RETURN_BUFFER("abcc"); - } - const CharT* abce() { - DECLARE_AND_RETURN_BUFFER("abce"); - } - const CharT* qwe() { - DECLARE_AND_RETURN_BUFFER("qwe"); - } - const CharT* cd() { - DECLARE_AND_RETURN_BUFFER("cd"); - } - const CharT* cde() { - DECLARE_AND_RETURN_BUFFER("cde"); - } - const CharT* cdef() { - DECLARE_AND_RETURN_BUFFER("cdef"); - } - const CharT* cdefgh() { - DECLARE_AND_RETURN_BUFFER("cdefgh"); - } - const CharT* ehortw_() { - DECLARE_AND_RETURN_BUFFER("ehortw "); - } - const CharT* fg() { - DECLARE_AND_RETURN_BUFFER("fg"); - } - const CharT* abcdefgh() { - DECLARE_AND_RETURN_BUFFER("abcdefgh"); - } - - // phrases - const CharT* Hello_World() { - DECLARE_AND_RETURN_BUFFER("Hello World"); - } - const CharT* This_is_test_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("This is test string for string calls"); - } - const CharT* This_is_teis_test_string_st_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("This is teis test string st string for string calls"); - } - const CharT* This_is_test_stis_test_string_for_stringring_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("This is test stis test string for stringring for string calls"); - } - const CharT* allsThis_is_test_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("allsThis is test string for string calls"); - } - const CharT* ng_for_string_callsThis_is_test_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("ng for string callsThis is test string for string calls"); - } - const CharT* one_two_three_one_two_three() { - DECLARE_AND_RETURN_BUFFER("one two three one two three"); - } - const CharT* test_string_for_assign() { - DECLARE_AND_RETURN_BUFFER("test string for assign"); - } - const CharT* other_test_string() { - DECLARE_AND_RETURN_BUFFER("other test string"); - } - const CharT* This_This_is_tefor_string_calls() { - DECLARE_AND_RETURN_BUFFER("This This is tefor string calls"); - } - const CharT* This_This_is_test_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("This This is test string for string calls"); - } - - const CharT* _0123456x() { - DECLARE_AND_RETURN_BUFFER("0123456x"); - } - const CharT* _0123456xy() { - DECLARE_AND_RETURN_BUFFER("0123456xy"); - } - const CharT* _0123456xyz() { - DECLARE_AND_RETURN_BUFFER("0123456xyz"); - } - const CharT* _0123456xyzZ() { - DECLARE_AND_RETURN_BUFFER("0123456xyzZ"); - } - const CharT* _0123456xyzZ0() { - DECLARE_AND_RETURN_BUFFER("0123456xyzZ0"); - } - const CharT* abc0123456xyz() { - DECLARE_AND_RETURN_BUFFER("abc0123456xyz"); - } - const CharT* BCabc0123456xyz() { - DECLARE_AND_RETURN_BUFFER("BCabc0123456xyz"); - } - const CharT* qweBCabc0123456xyz() { - DECLARE_AND_RETURN_BUFFER("qweBCabc0123456xyz"); - } - const CharT* _1qweBCabc0123456xyz() { - DECLARE_AND_RETURN_BUFFER("1qweBCabc0123456xyz"); - } - const CharT* _01abc23456() { - DECLARE_AND_RETURN_BUFFER("01abc23456"); - } - const CharT* _01ABCabc23456() { - DECLARE_AND_RETURN_BUFFER("01ABCabc23456"); - } - const CharT* ABC() { - DECLARE_AND_RETURN_BUFFER("ABC"); - } - const CharT* ABCD() { - DECLARE_AND_RETURN_BUFFER("ABCD"); - } - const CharT* QWE() { - DECLARE_AND_RETURN_BUFFER("QWE"); - } - const CharT* XYZ() { - DECLARE_AND_RETURN_BUFFER("XYZ"); - } - const CharT* W01ABCabc23456() { - DECLARE_AND_RETURN_BUFFER("W01ABCabc23456"); - } - const CharT* abcd456() { - DECLARE_AND_RETURN_BUFFER("abcd456"); - } - const CharT* abcdABCD() { - DECLARE_AND_RETURN_BUFFER("abcdABCD"); - } - const CharT* abcdABC123() { - DECLARE_AND_RETURN_BUFFER("abcdABC123"); - } - const CharT* z123z123() { - DECLARE_AND_RETURN_BUFFER("z123z123"); - } - const CharT* ASDF1234QWER() { - DECLARE_AND_RETURN_BUFFER("ASDF1234QWER"); - } - const CharT* asdf1234qwer() { - DECLARE_AND_RETURN_BUFFER("asdf1234qwer"); - } - const CharT* asDF1234qWEr() { - DECLARE_AND_RETURN_BUFFER("asDF1234qWEr"); - } - const CharT* AsDF1234qWEr() { - DECLARE_AND_RETURN_BUFFER("AsDF1234qWEr"); - } - const CharT* Asdf1234qwer() { - DECLARE_AND_RETURN_BUFFER("Asdf1234qwer"); - } - const CharT* Asdf1234qwerWWWW() { - DECLARE_AND_RETURN_BUFFER("Asdf1234qwerWWWW"); - } - const CharT* Asdf() { - DECLARE_AND_RETURN_BUFFER("Asdf"); - } - const CharT* orig() { - DECLARE_AND_RETURN_BUFFER("orig"); - } - const CharT* fdfdsfds() { - DECLARE_AND_RETURN_BUFFER("fdfdsfds"); - } - - // numbers - const CharT* _0() { - DECLARE_AND_RETURN_BUFFER("0"); - } - const CharT* _00() { - DECLARE_AND_RETURN_BUFFER("00"); - } - const CharT* _0000000000() { - DECLARE_AND_RETURN_BUFFER("0000000000"); - } - const CharT* _00000() { - DECLARE_AND_RETURN_BUFFER("00000"); - } - const CharT* _0123() { - DECLARE_AND_RETURN_BUFFER("0123"); - } - const CharT* _01230123() { - DECLARE_AND_RETURN_BUFFER("01230123"); - } - const CharT* _01234() { - DECLARE_AND_RETURN_BUFFER("01234"); - } - const CharT* _0123401234() { - DECLARE_AND_RETURN_BUFFER("0123401234"); - } - const CharT* _012345() { - DECLARE_AND_RETURN_BUFFER("012345"); - } - const CharT* _0123456() { - DECLARE_AND_RETURN_BUFFER("0123456"); - } - const CharT* _1() { - DECLARE_AND_RETURN_BUFFER("1"); - } - const CharT* _11() { - DECLARE_AND_RETURN_BUFFER("11"); - } - const CharT* _1100000() { - DECLARE_AND_RETURN_BUFFER("1100000"); - } - const CharT* _110000034() { - DECLARE_AND_RETURN_BUFFER("110000034"); - } - const CharT* _12() { - DECLARE_AND_RETURN_BUFFER("12"); - } - const CharT* _123() { - DECLARE_AND_RETURN_BUFFER("123"); - } - const CharT* _1233321() { - DECLARE_AND_RETURN_BUFFER("1233321"); - } - const CharT* _1221() { - DECLARE_AND_RETURN_BUFFER("1221"); - } - const CharT* _1234123456() { - DECLARE_AND_RETURN_BUFFER("1234123456"); - } - const CharT* _12334444321() { - DECLARE_AND_RETURN_BUFFER("12334444321"); - } - const CharT* _123344544321() { - DECLARE_AND_RETURN_BUFFER("123344544321"); - } - const CharT* _1234567890123456789012345678901234567890() { - DECLARE_AND_RETURN_BUFFER("1234567890123456789012345678901234567890"); - } - const CharT* _1234() { - DECLARE_AND_RETURN_BUFFER("1234"); - } - const CharT* _12345() { - DECLARE_AND_RETURN_BUFFER("12345"); - } - const CharT* _123456() { - DECLARE_AND_RETURN_BUFFER("123456"); - } - const CharT* _1234567() { - DECLARE_AND_RETURN_BUFFER("1234567"); - } - const CharT* _1234561234() { - DECLARE_AND_RETURN_BUFFER("1234561234"); - } - const CharT* _12356() { - DECLARE_AND_RETURN_BUFFER("12356"); - } - const CharT* _1345656() { - DECLARE_AND_RETURN_BUFFER("1345656"); - } - const CharT* _15656() { - DECLARE_AND_RETURN_BUFFER("15656"); - } - const CharT* _17856() { - DECLARE_AND_RETURN_BUFFER("17856"); - } - const CharT* _1783456() { - DECLARE_AND_RETURN_BUFFER("1783456"); - } - const CharT* _2() { - DECLARE_AND_RETURN_BUFFER("2"); - } - const CharT* _2123456() { - DECLARE_AND_RETURN_BUFFER("2123456"); - } - const CharT* _23() { - DECLARE_AND_RETURN_BUFFER("23"); - } - const CharT* _2345() { - DECLARE_AND_RETURN_BUFFER("2345"); - } - const CharT* _3() { - DECLARE_AND_RETURN_BUFFER("3"); - } - const CharT* _345() { - DECLARE_AND_RETURN_BUFFER("345"); - } - const CharT* _3456() { - DECLARE_AND_RETURN_BUFFER("3456"); - } - const CharT* _333333() { - DECLARE_AND_RETURN_BUFFER("333333"); - } - const CharT* _389() { - DECLARE_AND_RETURN_BUFFER("389"); - } - const CharT* _4294967295() { - DECLARE_AND_RETURN_BUFFER("4294967295"); - } - const CharT* _4444() { - DECLARE_AND_RETURN_BUFFER("4444"); - } - const CharT* _5() { - DECLARE_AND_RETURN_BUFFER("5"); - } - const CharT* _6() { - DECLARE_AND_RETURN_BUFFER("6"); - } - const CharT* _6543210() { - DECLARE_AND_RETURN_BUFFER("6543210"); - } - const CharT* _7() { - DECLARE_AND_RETURN_BUFFER("7"); - } - const CharT* _78() { - DECLARE_AND_RETURN_BUFFER("78"); - } - const CharT* _2004_01_01() { - DECLARE_AND_RETURN_BUFFER("2004-01-01"); - } - const CharT* _1234562004_01_01() { - DECLARE_AND_RETURN_BUFFER("1234562004-01-01"); - } - const CharT* _0123456_12345() { - DECLARE_AND_RETURN_BUFFER("0123456_12345"); - } - - // letters - const CharT* a() { - DECLARE_AND_RETURN_BUFFER("a"); - } - const CharT* b() { - DECLARE_AND_RETURN_BUFFER("b"); - } - const CharT* c() { - DECLARE_AND_RETURN_BUFFER("c"); - } - const CharT* d() { - DECLARE_AND_RETURN_BUFFER("d"); - } - const CharT* e() { - DECLARE_AND_RETURN_BUFFER("e"); - } - const CharT* f() { - DECLARE_AND_RETURN_BUFFER("f"); - } - const CharT* h() { - DECLARE_AND_RETURN_BUFFER("h"); - } - const CharT* o() { - DECLARE_AND_RETURN_BUFFER("o"); - } - const CharT* p() { - DECLARE_AND_RETURN_BUFFER("p"); - } - const CharT* q() { - DECLARE_AND_RETURN_BUFFER("q"); - } - const CharT* r() { - DECLARE_AND_RETURN_BUFFER("r"); - } - const CharT* s() { - DECLARE_AND_RETURN_BUFFER("s"); - } - const CharT* t() { - DECLARE_AND_RETURN_BUFFER("t"); - } - const CharT* w() { - DECLARE_AND_RETURN_BUFFER("w"); - } - const CharT* x() { - DECLARE_AND_RETURN_BUFFER("x"); - } - const CharT* y() { - DECLARE_AND_RETURN_BUFFER("y"); - } - const CharT* z() { - DECLARE_AND_RETURN_BUFFER("z"); - } - const CharT* H() { - DECLARE_AND_RETURN_BUFFER("H"); - } - const CharT* I() { - DECLARE_AND_RETURN_BUFFER("I"); - } - const CharT* W() { - DECLARE_AND_RETURN_BUFFER("W"); - } - - const CharT* Space() { - DECLARE_AND_RETURN_BUFFER(" "); - } - const CharT* Empty() { - DECLARE_AND_RETURN_BUFFER(""); - } - - size_t HashOf_0123456() { - return 0; - } -}; - -template <> -size_t TTestData<char>::HashOf_0123456() { - return 1229863857ul; -} - -template <> -size_t TTestData<wchar16>::HashOf_0123456() { - return 2775195331ul; -} - +#include <util/string/reverse.h> + +template <typename CharT, size_t N> +struct TCharBuffer { + CharT Data[N]; + //! copies characters from string to the internal buffer without any conversion + //! @param s a string that must contain only characters less than 0x7F + explicit TCharBuffer(const char* s) { + // copy all symbols including null terminated symbol + for (size_t i = 0; i < N; ++i) { + Data[i] = s[i]; + } + } + const CharT* GetData() const { + return Data; + } +}; + +template <> +struct TCharBuffer<char, 0> { + const char* Data; + //! stores pointer to string + explicit TCharBuffer(const char* s) + : Data(s) + { + } + const char* GetData() const { + return Data; + } +}; + +#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 { + // words + const CharT* str1() { + DECLARE_AND_RETURN_BUFFER("str1"); + } + const CharT* str2() { + DECLARE_AND_RETURN_BUFFER("str2"); + } + const CharT* str__________________________________________________1() { + DECLARE_AND_RETURN_BUFFER("str 1"); + } + const CharT* str__________________________________________________2() { + DECLARE_AND_RETURN_BUFFER("str 2"); + } + const CharT* one() { + DECLARE_AND_RETURN_BUFFER("one"); + } + const CharT* two() { + DECLARE_AND_RETURN_BUFFER("two"); + } + const CharT* three() { + DECLARE_AND_RETURN_BUFFER("three"); + } + const CharT* thrii() { + DECLARE_AND_RETURN_BUFFER("thrii"); + } + const CharT* four() { + DECLARE_AND_RETURN_BUFFER("four"); + } + const CharT* enotw_() { + DECLARE_AND_RETURN_BUFFER("enotw "); + } + const CharT* foo() { + DECLARE_AND_RETURN_BUFFER("foo"); + } + const CharT* abcdef() { + DECLARE_AND_RETURN_BUFFER("abcdef"); + } + const CharT* abcdefg() { + DECLARE_AND_RETURN_BUFFER("abcdefg"); + } + const CharT* aba() { + DECLARE_AND_RETURN_BUFFER("aba"); + } + const CharT* hr() { + DECLARE_AND_RETURN_BUFFER("hr"); + } + const CharT* hrt() { + DECLARE_AND_RETURN_BUFFER("hrt"); + } + const CharT* thr() { + DECLARE_AND_RETURN_BUFFER("thr"); + } + const CharT* tw() { + DECLARE_AND_RETURN_BUFFER("tw"); + } + const CharT* ow() { + DECLARE_AND_RETURN_BUFFER("ow"); + } + const CharT* opq() { + DECLARE_AND_RETURN_BUFFER("opq"); + } + const CharT* xyz() { + DECLARE_AND_RETURN_BUFFER("xyz"); + } + const CharT* abc() { + DECLARE_AND_RETURN_BUFFER("abc"); + } + const CharT* abcd() { + DECLARE_AND_RETURN_BUFFER("abcd"); + } + const CharT* abcde() { + DECLARE_AND_RETURN_BUFFER("abcde"); + } + const CharT* abcc() { + DECLARE_AND_RETURN_BUFFER("abcc"); + } + const CharT* abce() { + DECLARE_AND_RETURN_BUFFER("abce"); + } + const CharT* qwe() { + DECLARE_AND_RETURN_BUFFER("qwe"); + } + const CharT* cd() { + DECLARE_AND_RETURN_BUFFER("cd"); + } + const CharT* cde() { + DECLARE_AND_RETURN_BUFFER("cde"); + } + const CharT* cdef() { + DECLARE_AND_RETURN_BUFFER("cdef"); + } + const CharT* cdefgh() { + DECLARE_AND_RETURN_BUFFER("cdefgh"); + } + const CharT* ehortw_() { + DECLARE_AND_RETURN_BUFFER("ehortw "); + } + const CharT* fg() { + DECLARE_AND_RETURN_BUFFER("fg"); + } + const CharT* abcdefgh() { + DECLARE_AND_RETURN_BUFFER("abcdefgh"); + } + + // phrases + const CharT* Hello_World() { + DECLARE_AND_RETURN_BUFFER("Hello World"); + } + const CharT* This_is_test_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("This is test string for string calls"); + } + const CharT* This_is_teis_test_string_st_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("This is teis test string st string for string calls"); + } + const CharT* This_is_test_stis_test_string_for_stringring_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("This is test stis test string for stringring for string calls"); + } + const CharT* allsThis_is_test_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("allsThis is test string for string calls"); + } + const CharT* ng_for_string_callsThis_is_test_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("ng for string callsThis is test string for string calls"); + } + const CharT* one_two_three_one_two_three() { + DECLARE_AND_RETURN_BUFFER("one two three one two three"); + } + const CharT* test_string_for_assign() { + DECLARE_AND_RETURN_BUFFER("test string for assign"); + } + const CharT* other_test_string() { + DECLARE_AND_RETURN_BUFFER("other test string"); + } + const CharT* This_This_is_tefor_string_calls() { + DECLARE_AND_RETURN_BUFFER("This This is tefor string calls"); + } + const CharT* This_This_is_test_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("This This is test string for string calls"); + } + + const CharT* _0123456x() { + DECLARE_AND_RETURN_BUFFER("0123456x"); + } + const CharT* _0123456xy() { + DECLARE_AND_RETURN_BUFFER("0123456xy"); + } + const CharT* _0123456xyz() { + DECLARE_AND_RETURN_BUFFER("0123456xyz"); + } + const CharT* _0123456xyzZ() { + DECLARE_AND_RETURN_BUFFER("0123456xyzZ"); + } + const CharT* _0123456xyzZ0() { + DECLARE_AND_RETURN_BUFFER("0123456xyzZ0"); + } + const CharT* abc0123456xyz() { + DECLARE_AND_RETURN_BUFFER("abc0123456xyz"); + } + const CharT* BCabc0123456xyz() { + DECLARE_AND_RETURN_BUFFER("BCabc0123456xyz"); + } + const CharT* qweBCabc0123456xyz() { + DECLARE_AND_RETURN_BUFFER("qweBCabc0123456xyz"); + } + const CharT* _1qweBCabc0123456xyz() { + DECLARE_AND_RETURN_BUFFER("1qweBCabc0123456xyz"); + } + const CharT* _01abc23456() { + DECLARE_AND_RETURN_BUFFER("01abc23456"); + } + const CharT* _01ABCabc23456() { + DECLARE_AND_RETURN_BUFFER("01ABCabc23456"); + } + const CharT* ABC() { + DECLARE_AND_RETURN_BUFFER("ABC"); + } + const CharT* ABCD() { + DECLARE_AND_RETURN_BUFFER("ABCD"); + } + const CharT* QWE() { + DECLARE_AND_RETURN_BUFFER("QWE"); + } + const CharT* XYZ() { + DECLARE_AND_RETURN_BUFFER("XYZ"); + } + const CharT* W01ABCabc23456() { + DECLARE_AND_RETURN_BUFFER("W01ABCabc23456"); + } + const CharT* abcd456() { + DECLARE_AND_RETURN_BUFFER("abcd456"); + } + const CharT* abcdABCD() { + DECLARE_AND_RETURN_BUFFER("abcdABCD"); + } + const CharT* abcdABC123() { + DECLARE_AND_RETURN_BUFFER("abcdABC123"); + } + const CharT* z123z123() { + DECLARE_AND_RETURN_BUFFER("z123z123"); + } + const CharT* ASDF1234QWER() { + DECLARE_AND_RETURN_BUFFER("ASDF1234QWER"); + } + const CharT* asdf1234qwer() { + DECLARE_AND_RETURN_BUFFER("asdf1234qwer"); + } + const CharT* asDF1234qWEr() { + DECLARE_AND_RETURN_BUFFER("asDF1234qWEr"); + } + const CharT* AsDF1234qWEr() { + DECLARE_AND_RETURN_BUFFER("AsDF1234qWEr"); + } + const CharT* Asdf1234qwer() { + DECLARE_AND_RETURN_BUFFER("Asdf1234qwer"); + } + const CharT* Asdf1234qwerWWWW() { + DECLARE_AND_RETURN_BUFFER("Asdf1234qwerWWWW"); + } + const CharT* Asdf() { + DECLARE_AND_RETURN_BUFFER("Asdf"); + } + const CharT* orig() { + DECLARE_AND_RETURN_BUFFER("orig"); + } + const CharT* fdfdsfds() { + DECLARE_AND_RETURN_BUFFER("fdfdsfds"); + } + + // numbers + const CharT* _0() { + DECLARE_AND_RETURN_BUFFER("0"); + } + const CharT* _00() { + DECLARE_AND_RETURN_BUFFER("00"); + } + const CharT* _0000000000() { + DECLARE_AND_RETURN_BUFFER("0000000000"); + } + const CharT* _00000() { + DECLARE_AND_RETURN_BUFFER("00000"); + } + const CharT* _0123() { + DECLARE_AND_RETURN_BUFFER("0123"); + } + const CharT* _01230123() { + DECLARE_AND_RETURN_BUFFER("01230123"); + } + const CharT* _01234() { + DECLARE_AND_RETURN_BUFFER("01234"); + } + const CharT* _0123401234() { + DECLARE_AND_RETURN_BUFFER("0123401234"); + } + const CharT* _012345() { + DECLARE_AND_RETURN_BUFFER("012345"); + } + const CharT* _0123456() { + DECLARE_AND_RETURN_BUFFER("0123456"); + } + const CharT* _1() { + DECLARE_AND_RETURN_BUFFER("1"); + } + const CharT* _11() { + DECLARE_AND_RETURN_BUFFER("11"); + } + const CharT* _1100000() { + DECLARE_AND_RETURN_BUFFER("1100000"); + } + const CharT* _110000034() { + DECLARE_AND_RETURN_BUFFER("110000034"); + } + const CharT* _12() { + DECLARE_AND_RETURN_BUFFER("12"); + } + const CharT* _123() { + DECLARE_AND_RETURN_BUFFER("123"); + } + const CharT* _1233321() { + DECLARE_AND_RETURN_BUFFER("1233321"); + } + const CharT* _1221() { + DECLARE_AND_RETURN_BUFFER("1221"); + } + const CharT* _1234123456() { + DECLARE_AND_RETURN_BUFFER("1234123456"); + } + const CharT* _12334444321() { + DECLARE_AND_RETURN_BUFFER("12334444321"); + } + const CharT* _123344544321() { + DECLARE_AND_RETURN_BUFFER("123344544321"); + } + const CharT* _1234567890123456789012345678901234567890() { + DECLARE_AND_RETURN_BUFFER("1234567890123456789012345678901234567890"); + } + const CharT* _1234() { + DECLARE_AND_RETURN_BUFFER("1234"); + } + const CharT* _12345() { + DECLARE_AND_RETURN_BUFFER("12345"); + } + const CharT* _123456() { + DECLARE_AND_RETURN_BUFFER("123456"); + } + const CharT* _1234567() { + DECLARE_AND_RETURN_BUFFER("1234567"); + } + const CharT* _1234561234() { + DECLARE_AND_RETURN_BUFFER("1234561234"); + } + const CharT* _12356() { + DECLARE_AND_RETURN_BUFFER("12356"); + } + const CharT* _1345656() { + DECLARE_AND_RETURN_BUFFER("1345656"); + } + const CharT* _15656() { + DECLARE_AND_RETURN_BUFFER("15656"); + } + const CharT* _17856() { + DECLARE_AND_RETURN_BUFFER("17856"); + } + const CharT* _1783456() { + DECLARE_AND_RETURN_BUFFER("1783456"); + } + const CharT* _2() { + DECLARE_AND_RETURN_BUFFER("2"); + } + const CharT* _2123456() { + DECLARE_AND_RETURN_BUFFER("2123456"); + } + const CharT* _23() { + DECLARE_AND_RETURN_BUFFER("23"); + } + const CharT* _2345() { + DECLARE_AND_RETURN_BUFFER("2345"); + } + const CharT* _3() { + DECLARE_AND_RETURN_BUFFER("3"); + } + const CharT* _345() { + DECLARE_AND_RETURN_BUFFER("345"); + } + const CharT* _3456() { + DECLARE_AND_RETURN_BUFFER("3456"); + } + const CharT* _333333() { + DECLARE_AND_RETURN_BUFFER("333333"); + } + const CharT* _389() { + DECLARE_AND_RETURN_BUFFER("389"); + } + const CharT* _4294967295() { + DECLARE_AND_RETURN_BUFFER("4294967295"); + } + const CharT* _4444() { + DECLARE_AND_RETURN_BUFFER("4444"); + } + const CharT* _5() { + DECLARE_AND_RETURN_BUFFER("5"); + } + const CharT* _6() { + DECLARE_AND_RETURN_BUFFER("6"); + } + const CharT* _6543210() { + DECLARE_AND_RETURN_BUFFER("6543210"); + } + const CharT* _7() { + DECLARE_AND_RETURN_BUFFER("7"); + } + const CharT* _78() { + DECLARE_AND_RETURN_BUFFER("78"); + } + const CharT* _2004_01_01() { + DECLARE_AND_RETURN_BUFFER("2004-01-01"); + } + const CharT* _1234562004_01_01() { + DECLARE_AND_RETURN_BUFFER("1234562004-01-01"); + } + const CharT* _0123456_12345() { + DECLARE_AND_RETURN_BUFFER("0123456_12345"); + } + + // letters + const CharT* a() { + DECLARE_AND_RETURN_BUFFER("a"); + } + const CharT* b() { + DECLARE_AND_RETURN_BUFFER("b"); + } + const CharT* c() { + DECLARE_AND_RETURN_BUFFER("c"); + } + const CharT* d() { + DECLARE_AND_RETURN_BUFFER("d"); + } + const CharT* e() { + DECLARE_AND_RETURN_BUFFER("e"); + } + const CharT* f() { + DECLARE_AND_RETURN_BUFFER("f"); + } + const CharT* h() { + DECLARE_AND_RETURN_BUFFER("h"); + } + const CharT* o() { + DECLARE_AND_RETURN_BUFFER("o"); + } + const CharT* p() { + DECLARE_AND_RETURN_BUFFER("p"); + } + const CharT* q() { + DECLARE_AND_RETURN_BUFFER("q"); + } + const CharT* r() { + DECLARE_AND_RETURN_BUFFER("r"); + } + const CharT* s() { + DECLARE_AND_RETURN_BUFFER("s"); + } + const CharT* t() { + DECLARE_AND_RETURN_BUFFER("t"); + } + const CharT* w() { + DECLARE_AND_RETURN_BUFFER("w"); + } + const CharT* x() { + DECLARE_AND_RETURN_BUFFER("x"); + } + const CharT* y() { + DECLARE_AND_RETURN_BUFFER("y"); + } + const CharT* z() { + DECLARE_AND_RETURN_BUFFER("z"); + } + const CharT* H() { + DECLARE_AND_RETURN_BUFFER("H"); + } + const CharT* I() { + DECLARE_AND_RETURN_BUFFER("I"); + } + const CharT* W() { + DECLARE_AND_RETURN_BUFFER("W"); + } + + const CharT* Space() { + DECLARE_AND_RETURN_BUFFER(" "); + } + const CharT* Empty() { + DECLARE_AND_RETURN_BUFFER(""); + } + + size_t HashOf_0123456() { + return 0; + } +}; + +template <> +size_t TTestData<char>::HashOf_0123456() { + return 1229863857ul; +} + +template <> +size_t TTestData<wchar16>::HashOf_0123456() { + return 2775195331ul; +} + template <class TStringType, typename TTestData> class TStringTestImpl { protected: @@ -518,7 +518,7 @@ protected: public: void TestMaxSize() { - const size_t badMaxVal = TStringType{}.max_size() + 1; + const size_t badMaxVal = TStringType{}.max_size() + 1; TStringType s; UNIT_CHECK_GENERATED_EXCEPTION(s.reserve(badMaxVal), std::length_error); @@ -541,10 +541,10 @@ public: UNIT_ASSERT_VALUES_EQUAL(fromChar.size(), 1u); UNIT_ASSERT_VALUES_EQUAL(fromChar[0], char_type('a')); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING TStringType s3 = TStringType::Uninitialized(10); UNIT_ASSERT(s3.size() == 10); -#endif +#endif TStringType s4(Data._0123456(), 1, 3); UNIT_ASSERT(s4 == Data._123()); @@ -556,9 +556,9 @@ public: UNIT_ASSERT(s6 == Data._0123456()); TStringType s7(s6); UNIT_ASSERT(s7 == s6); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s7.c_str() == s6.c_str()); -#endif +#endif TStringType s8(s7, 1, 3); UNIT_ASSERT(s8 == Data._123()); @@ -568,7 +568,7 @@ public: TStringType s10(Reserve(100)); UNIT_ASSERT(s10.empty()); - UNIT_ASSERT(s10.capacity() >= 100); + UNIT_ASSERT(s10.capacity() >= 100); } void TestReplace() { @@ -579,11 +579,11 @@ public: s.append(Data.x()); UNIT_ASSERT(s == Data._0123456x()); -#ifdef TSTRING_IS_STD_STRING - s.append(Data.xyz() + 1, 1); -#else +#ifdef TSTRING_IS_STD_STRING + s.append(Data.xyz() + 1, 1); +#else s.append(Data.xyz(), 1, 1); -#endif +#endif UNIT_ASSERT(s == Data._0123456xy()); s.append(TStringType(Data.z())); @@ -650,7 +650,7 @@ public: UNIT_ASSERT(s[s.size()] == 0); } -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING void TestRefCount() { using TStr = TStringType; @@ -672,7 +672,7 @@ public: UNIT_ASSERT_EQUAL(s2.RefCount() == 1, true); UNIT_ASSERT_EQUAL(s1.c_str() == s2.c_str(), false); } -#endif +#endif // Find family @@ -797,11 +797,11 @@ public: UNIT_ASSERT(s > Data.abc0123456xyz()); UNIT_ASSERT(s == Data.abcd()); - using TCIStringBuf = TBasicStringBuf<char_type, traits_type>; - - UNIT_ASSERT(s > TCIStringBuf(Data.abc0123456xyz())); - UNIT_ASSERT(TCIStringBuf(Data.abc0123456xyz()) < s); - UNIT_ASSERT(s == TCIStringBuf(Data.abcd())); + using TCIStringBuf = TBasicStringBuf<char_type, traits_type>; + + UNIT_ASSERT(s > TCIStringBuf(Data.abc0123456xyz())); + UNIT_ASSERT(TCIStringBuf(Data.abc0123456xyz()) < s); + UNIT_ASSERT(s == TCIStringBuf(Data.abcd())); } void TestMulOperators() { @@ -836,7 +836,7 @@ public: UNIT_ASSERT(s2 == s); // reverse() - ReverseInPlace(s2); + ReverseInPlace(s2); UNIT_ASSERT(s2 == Data._6543210()); // to_upper() @@ -894,7 +894,7 @@ public: // hash() TStringType sS = s2; // type 'TStringType' is used as is - ComputeHash(sS); /*size_t hash_val = sS.hash(); + ComputeHash(sS); /*size_t hash_val = sS.hash(); try { //UNIT_ASSERT(hash_val == Data.HashOf_0123456()); @@ -998,7 +998,7 @@ public: UNIT_ASSERT_EQUAL(str.EndsWith(emptyStr), true); } -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING void TestCharRef() { const char_type abc[] = {'a', 'b', 'c', 0}; const char_type bbc[] = {'b', 'b', 'c', 0}; @@ -1045,7 +1045,7 @@ public: UNIT_ASSERT_VALUES_EQUAL(s1, red_eared); } } -#endif +#endif void TestBack() { const char_type chars[] = {'f', 'o', 'o', 0}; diff --git a/util/generic/variant.h b/util/generic/variant.h index 749fc75090..080f0a6e7e 100644 --- a/util/generic/variant.h +++ b/util/generic/variant.h @@ -1,23 +1,23 @@ #pragma once -#include "hash.h" +#include "hash.h" -#include <variant> +#include <variant> template <class... Ts> -struct THash<std::variant<Ts...>> { +struct THash<std::variant<Ts...>> { public: - size_t operator()(const std::variant<Ts...>& v) const noexcept { - return CombineHashes( - IntHash(v.index()), - v.valueless_by_exception() ? 0 : std::visit([](const auto& value) { return ComputeHash(value); }, v)); + size_t operator()(const std::variant<Ts...>& v) const noexcept { + return CombineHashes( + IntHash(v.index()), + v.valueless_by_exception() ? 0 : std::visit([](const auto& value) { return ComputeHash(value); }, v)); } }; template <> -struct THash<std::monostate> { +struct THash<std::monostate> { public: - constexpr size_t operator()(std::monostate) const noexcept { + constexpr size_t operator()(std::monostate) const noexcept { return 1; } }; diff --git a/util/memory/pool_ut.cpp b/util/memory/pool_ut.cpp index 1158a8ca42..568bd0708a 100644 --- a/util/memory/pool_ut.cpp +++ b/util/memory/pool_ut.cpp @@ -158,9 +158,9 @@ private: { TMemoryPool pool(123, TMemoryPool::TExpGrow::Instance(), &alloc); - THolder<TConstructorTest, TDestructor> data1{pool.New<TConstructorTest>()}; - THolder<TConstructorTest, TDestructor> data2{pool.New<TConstructorTest>(42)}; - THolder<TConstructorTest, TDestructor> data3{pool.New<TConstructorTest>("hello", "world")}; + THolder<TConstructorTest, TDestructor> data1{pool.New<TConstructorTest>()}; + THolder<TConstructorTest, TDestructor> data2{pool.New<TConstructorTest>(42)}; + THolder<TConstructorTest, TDestructor> data3{pool.New<TConstructorTest>("hello", "world")}; UNIT_ASSERT_VALUES_EQUAL(data1->ConstructorType, 1); UNIT_ASSERT_VALUES_EQUAL(data2->ConstructorType, 2); UNIT_ASSERT_VALUES_EQUAL(data3->ConstructorType, 4); diff --git a/util/network/ip_ut.cpp b/util/network/ip_ut.cpp index 6716c6a699..5641029a13 100644 --- a/util/network/ip_ut.cpp +++ b/util/network/ip_ut.cpp @@ -58,6 +58,6 @@ void TSysIpTest::TestIpToString() { const char* ipStr[] = {"192.168.0.1", "87.255.18.167", "255.255.0.31", "188.225.124.255"}; for (size_t i = 0; i < Y_ARRAY_SIZE(ipStr); ++i) { - UNIT_ASSERT(IpToString(*reinterpret_cast<TIpHost*>(&(ipArr[i]))) == ipStr[i]); + UNIT_ASSERT(IpToString(*reinterpret_cast<TIpHost*>(&(ipArr[i]))) == ipStr[i]); } } diff --git a/util/network/nonblock.cpp b/util/network/nonblock.cpp index e515c27cc5..ee2a9474ef 100644 --- a/util/network/nonblock.cpp +++ b/util/network/nonblock.cpp @@ -22,7 +22,7 @@ namespace { { #if defined(_unix_) && defined(SOCK_NONBLOCK) { - Accept4 = reinterpret_cast<TAccept4>(dlsym(RTLD_DEFAULT, "accept4")); + Accept4 = reinterpret_cast<TAccept4>(dlsym(RTLD_DEFAULT, "accept4")); #if defined(_musl_) //musl always statically linked diff --git a/util/str_stl.h b/util/str_stl.h index f1e137181d..9ca29e658e 100644 --- a/util/str_stl.h +++ b/util/str_stl.h @@ -3,7 +3,7 @@ #include <util/memory/alloc.h> #include <util/digest/numeric.h> #include <util/generic/string.h> -#include <util/generic/string_hash.h> +#include <util/generic/string_hash.h> #include <util/generic/strbuf.h> #include <util/generic/typetraits.h> @@ -52,7 +52,7 @@ namespace NHashPrivate { using is_transparent = void; inline size_t operator()(const TBasicStringBuf<C> s) const noexcept { - return NHashPrivate::ComputeStringHash(s.data(), s.size()); + return NHashPrivate::ComputeStringHash(s.data(), s.size()); } }; } diff --git a/util/stream/output.cpp b/util/stream/output.cpp index db81b81b70..48853c84c8 100644 --- a/util/stream/output.cpp +++ b/util/stream/output.cpp @@ -209,7 +209,7 @@ void Out<typename std::vector<bool>::reference>(IOutputStream& o, const std::vec } #endif -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING template <> void Out<TBasicCharRef<TString>>(IOutputStream& o, const TBasicCharRef<TString>& c) { o << static_cast<char>(c); @@ -224,7 +224,7 @@ template <> void Out<TBasicCharRef<TUtf32String>>(IOutputStream& o, const TBasicCharRef<TUtf32String>& c) { o << static_cast<wchar32>(c); } -#endif +#endif template <> void Out<const void*>(IOutputStream& o, const void* t) { diff --git a/util/string/ascii.h b/util/string/ascii.h index 10344384d3..68c3a963f9 100644 --- a/util/string/ascii.h +++ b/util/string/ascii.h @@ -31,12 +31,12 @@ namespace NPrivate { using type = T; }; -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING template <class String> struct TDereference<TBasicCharRef<String>> { using type = typename String::value_type; }; -#endif +#endif template <class T> using TDereferenced = typename TDereference<T>::type; @@ -52,12 +52,12 @@ namespace NPrivate { return c >= static_cast<T>(0) && c <= static_cast<T>(127); } -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING template <class String> bool RangeOk(const TBasicCharRef<String>& c) { return RangeOk(static_cast<typename String::value_type>(c)); } -#endif +#endif } constexpr bool IsAscii(const int c) noexcept { diff --git a/util/string/cast.h b/util/string/cast.h index 90e925c194..d4f6a876d8 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -343,15 +343,15 @@ template <class TInt, int base, class TStringType> inline TInt IntFromString(const TStringType& str) { return IntFromString<TInt, base>(str.data(), str.size()); } - -static inline TString ToString(const TStringBuf str) { - return TString(str); -} - -static inline TUtf16String ToWtring(const TWtringBuf wtr) { - return TUtf16String(wtr); -} - -static inline TUtf32String ToUtf32String(const TUtf32StringBuf wtr) { - return TUtf32String(wtr); -} + +static inline TString ToString(const TStringBuf str) { + return TString(str); +} + +static inline TUtf16String ToWtring(const TWtringBuf wtr) { + return TUtf16String(wtr); +} + +static inline TUtf32String ToUtf32String(const TUtf32StringBuf wtr) { + return TUtf32String(wtr); +} diff --git a/util/string/escape.cpp b/util/string/escape.cpp index cd09a7dbd0..ea35b5fb15 100644 --- a/util/string/escape.cpp +++ b/util/string/escape.cpp @@ -283,12 +283,12 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) { } case 'U': - if (CountHex<8>(p + 1, pe) != 8) { + if (CountHex<8>(p + 1, pe) != 8) { res.append(*p); - } else { + } else { AppendUnicode(res, IntFromString<ui32, 16>(p + 1, 8)); - p += 8; - } + p += 8; + } break; case 'x': if (ui32 v = CountHex<2>(p + 1, pe)) { @@ -319,8 +319,8 @@ static TStr& DoUnescapeC(const TChar* p, size_t sz, TStr& res) { ++p; } else { - const auto r = std::basic_string_view<TChar>(p, pe - p).find('\\'); - const auto n = r != std::string::npos ? p + r : pe; + const auto r = std::basic_string_view<TChar>(p, pe - p).find('\\'); + const auto n = r != std::string::npos ? p + r : pe; res.append(p, n); p = n; @@ -338,17 +338,17 @@ TBasicString<TChar>& UnescapeCImpl(const TChar* p, size_t sz, TBasicString<TChar template <class TChar> TChar* UnescapeC(const TChar* str, size_t len, TChar* buf) { struct TUnboundedString { - void append(TChar ch) noexcept { + void append(TChar ch) noexcept { *P++ = ch; } - void append(const TChar* b, const TChar* e) noexcept { + void append(const TChar* b, const TChar* e) noexcept { while (b != e) { append(*b++); } } - void AppendNoAlias(const TChar* s, size_t l) noexcept { + void AppendNoAlias(const TChar* s, size_t l) noexcept { append(s, s + l); } diff --git a/util/string/escape_ut.cpp b/util/string/escape_ut.cpp index cd38ecffd3..c79c2833a8 100644 --- a/util/string/escape_ut.cpp +++ b/util/string/escape_ut.cpp @@ -140,9 +140,9 @@ Y_UNIT_TEST_SUITE(TEscapeCTest) { UNIT_ASSERT_VALUES_EQUAL(x.Source, TStringBuf(buf, end)); } } - - Y_UNIT_TEST(TestCapitalUEscapes) { - UNIT_ASSERT_VALUES_EQUAL(UnescapeC("\\U00000020"), " "); - UNIT_ASSERT_VALUES_EQUAL(UnescapeC("\\Uxxx"), "Uxxx"); - } + + Y_UNIT_TEST(TestCapitalUEscapes) { + UNIT_ASSERT_VALUES_EQUAL(UnescapeC("\\U00000020"), " "); + UNIT_ASSERT_VALUES_EQUAL(UnescapeC("\\Uxxx"), "Uxxx"); + } } diff --git a/util/string/fuzzing/collapse/main.cpp b/util/string/fuzzing/collapse/main.cpp index e7b09f0f55..e26ec54f79 100644 --- a/util/string/fuzzing/collapse/main.cpp +++ b/util/string/fuzzing/collapse/main.cpp @@ -6,7 +6,7 @@ extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) { Collapse(w); TString s((const char*)data, size); - CollapseInPlace(s); + CollapseInPlace(s); return 0; // Non-zero return values are reserved for future use. } diff --git a/util/string/join.h b/util/string/join.h index b166fad1f3..b848bea1d3 100644 --- a/util/string/join.h +++ b/util/string/join.h @@ -2,7 +2,7 @@ #include <util/generic/string.h> #include <util/generic/typetraits.h> -#include <util/string/cast.h> +#include <util/string/cast.h> #include "cast.h" /* diff --git a/util/string/reverse.cpp b/util/string/reverse.cpp index 167cd11f49..3d67e95b04 100644 --- a/util/string/reverse.cpp +++ b/util/string/reverse.cpp @@ -1,33 +1,33 @@ -#include "reverse.h" - -#include <util/generic/string.h> -#include <util/generic/vector.h> -#include <util/charset/wide_specific.h> - -#include <algorithm> - -void ReverseInPlace(TString& string) { - auto* begin = string.begin(); - std::reverse(begin, begin + string.size()); -} - -void ReverseInPlace(TUtf16String& string) { - auto* begin = string.begin(); - const auto len = string.size(); - auto* end = begin + string.size(); - - TVector<wchar16> buffer(len); - wchar16* rbegin = buffer.data() + len; - for (wchar16* p = begin; p < end;) { - const size_t symbolSize = W16SymbolSize(p, end); - rbegin -= symbolSize; - std::copy(p, p + symbolSize, rbegin); - p += symbolSize; - } - std::copy(buffer.begin(), buffer.end(), begin); -} - -void ReverseInPlace(TUtf32String& string) { - auto* begin = string.begin(); - std::reverse(begin, begin + string.size()); -} +#include "reverse.h" + +#include <util/generic/string.h> +#include <util/generic/vector.h> +#include <util/charset/wide_specific.h> + +#include <algorithm> + +void ReverseInPlace(TString& string) { + auto* begin = string.begin(); + std::reverse(begin, begin + string.size()); +} + +void ReverseInPlace(TUtf16String& string) { + auto* begin = string.begin(); + const auto len = string.size(); + auto* end = begin + string.size(); + + TVector<wchar16> buffer(len); + wchar16* rbegin = buffer.data() + len; + for (wchar16* p = begin; p < end;) { + const size_t symbolSize = W16SymbolSize(p, end); + rbegin -= symbolSize; + std::copy(p, p + symbolSize, rbegin); + p += symbolSize; + } + std::copy(buffer.begin(), buffer.end(), begin); +} + +void ReverseInPlace(TUtf32String& string) { + auto* begin = string.begin(); + std::reverse(begin, begin + string.size()); +} diff --git a/util/string/reverse.h b/util/string/reverse.h index 80f8b00887..6adf17f08b 100644 --- a/util/string/reverse.h +++ b/util/string/reverse.h @@ -1,16 +1,16 @@ -#pragma once - -#include <util/generic/fwd.h> - -void ReverseInPlace(TString& string); - -/** NB. UTF-16 is variable-length encoding because of the surrogate pairs. - * This function takes this into account and treats a surrogate pair as a single symbol. - * Ex. if [C D] is a surrogate pair, - * A B [C D] E - * will become - * E [C D] B A - */ -void ReverseInPlace(TUtf16String& string); - -void ReverseInPlace(TUtf32String& string); +#pragma once + +#include <util/generic/fwd.h> + +void ReverseInPlace(TString& string); + +/** NB. UTF-16 is variable-length encoding because of the surrogate pairs. + * This function takes this into account and treats a surrogate pair as a single symbol. + * Ex. if [C D] is a surrogate pair, + * A B [C D] E + * will become + * E [C D] B A + */ +void ReverseInPlace(TUtf16String& string); + +void ReverseInPlace(TUtf32String& string); diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..951b3cc7d4 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -21,7 +21,7 @@ // NOTE: Check StringSplitter below to get more convenient split string interface. -namespace NStringSplitPrivate { +namespace NStringSplitPrivate { template <class T, class I, class = void> struct TIsConsumer: std::false_type {}; @@ -36,21 +36,21 @@ namespace NStringSplitPrivate { template <class T, class I> constexpr bool TIsConsumerV = TIsConsumer<T, I>::value; - template <class T> - T* Find(T* str, std::common_type_t<T> ch) { - for (; *str; ++str) { - if (*str == ch) { - return str; - } - } - - return nullptr; - } - + template <class T> + T* Find(T* str, std::common_type_t<T> ch) { + for (; *str; ++str) { + if (*str == ch) { + return str; + } + } + + return nullptr; + } + } template <class I, class TDelim, class TConsumer> -std::enable_if_t<::NStringSplitPrivate::TIsConsumerV<TConsumer, I>> +std::enable_if_t<::NStringSplitPrivate::TIsConsumerV<TConsumer, I>> SplitString(I b, I e, const TDelim& d, TConsumer&& c) { I l, i; @@ -61,7 +61,7 @@ SplitString(I b, I e, const TDelim& d, TConsumer&& c) { } template <class I, class TDelim, class TConsumer> -std::enable_if_t<::NStringSplitPrivate::TIsConsumerV<TConsumer, I>> +std::enable_if_t<::NStringSplitPrivate::TIsConsumerV<TConsumer, I>> SplitString(I b, const TDelim& d, TConsumer&& c) { I l, i; @@ -73,7 +73,7 @@ SplitString(I b, const TDelim& d, TConsumer&& c) { template <class I1, class I2> static inline I1* FastStrChr(I1* str, I2 f) noexcept { - I1* ret = NStringSplitPrivate::Find(str, f); + I1* ret = NStringSplitPrivate::Find(str, f); if (!ret) { ret = str + std::char_traits<I1>::length(str); @@ -84,21 +84,21 @@ static inline I1* FastStrChr(I1* str, I2 f) noexcept { template <class I> static inline I* FastStrStr(I* str, I* f, size_t l) noexcept { - std::basic_string_view<I> strView(str); - const auto ret = strView.find(*f); - - if (ret != std::string::npos) { - std::basic_string_view<I> fView(f, l); - strView = strView.substr(ret); - for (; strView.size() >= l; strView = strView.substr(1)) { - if (strView.substr(0, l) == fView) { - break; - } - } - - return strView.size() >= l ? strView.data() : strView.data() + strView.size(); - } else { - return strView.data() + strView.size(); + std::basic_string_view<I> strView(str); + const auto ret = strView.find(*f); + + if (ret != std::string::npos) { + std::basic_string_view<I> fView(f, l); + strView = strView.substr(ret); + for (; strView.size() >= l; strView = strView.substr(1)) { + if (strView.substr(0, l) == fView) { + break; + } + } + + return strView.size() >= l ? strView.data() : strView.data() + strView.size(); + } else { + return strView.data() + strView.size(); } } @@ -117,12 +117,12 @@ struct TStringDelimiter { } inline Char* Find(Char*& b, Char* e) const noexcept { - const auto ret = std::basic_string_view<Char>(b, e - b).find(Delim, 0, Len); + const auto ret = std::basic_string_view<Char>(b, e - b).find(Delim, 0, Len); - if (ret != std::string::npos) { - const auto result = b + ret; - b = result + Len; - return result; + if (ret != std::string::npos) { + const auto result = b + ret; + b = result + Len; + return result; } return (b = e); @@ -131,7 +131,7 @@ struct TStringDelimiter { inline Char* Find(Char*& b) const noexcept { Char* ret = FastStrStr(b, Delim, Len); - b = *ret ? ret + Len : ret; + b = *ret ? ret + Len : ret; return ret; } @@ -148,12 +148,12 @@ struct TCharDelimiter { } inline Char* Find(Char*& b, Char* e) const noexcept { - const auto ret = std::basic_string_view<Char>(b, e - b).find(Ch); + const auto ret = std::basic_string_view<Char>(b, e - b).find(Ch); - if (ret != std::string::npos) { - const auto result = b + ret; - b = result + 1; - return result; + if (ret != std::string::npos) { + const auto result = b + ret; + b = result + 1; + return result; } return (b = e); @@ -205,16 +205,16 @@ struct TFindFirstOf { inline Char* FindFirstOf(Char* b, Char* e) const noexcept { Char* ret = b; for (; ret != e; ++ret) { - if (NStringSplitPrivate::Find(Set, *ret)) + if (NStringSplitPrivate::Find(Set, *ret)) break; } return ret; } inline Char* FindFirstOf(Char* b) const noexcept { - const std::basic_string_view<Char> bView(b); - const auto ret = bView.find_first_of(Set); - return ret != std::string::npos ? b + ret : b + bView.size(); + const std::basic_string_view<Char> bView(b); + const auto ret = bView.find_first_of(Set); + return ret != std::string::npos ? b + ret : b + bView.size(); } Char* Set; @@ -489,7 +489,7 @@ void Split(TStringBuf s, D delim, P1& p1, P2& p2, Other&... other) { * \endcode */ -namespace NStringSplitPrivate { +namespace NStringSplitPrivate { Y_HAS_MEMBER(push_back, PushBack); Y_HAS_MEMBER(insert, Insert); Y_HAS_MEMBER(data, Data); @@ -1042,30 +1042,30 @@ namespace NStringSplitPrivate { template <class Iterator> auto StringSplitter(Iterator begin, Iterator end) { - return ::NStringSplitPrivate::MakeStringSplitter(TIteratorRange<Iterator>(begin, end)); + return ::NStringSplitPrivate::MakeStringSplitter(TIteratorRange<Iterator>(begin, end)); } template <class Char> auto StringSplitter(const Char* begin, const Char* end) { - return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, end)); + return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, end)); } template <class Char> auto StringSplitter(const Char* begin, size_t len) { - return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, len)); + return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(begin, len)); } template <class Char> auto StringSplitter(const Char* str) { - return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(str)); + return ::NStringSplitPrivate::MakeStringSplitter(TBasicStringBuf<Char>(str)); } template <class String, std::enable_if_t<!std::is_pointer<std::remove_reference_t<String>>::value, int> = 0> auto StringSplitter(String& s) { - return ::NStringSplitPrivate::MakeStringSplitter(::NStringSplitPrivate::TStringBufOf<String>(s.data(), s.size())); + return ::NStringSplitPrivate::MakeStringSplitter(::NStringSplitPrivate::TStringBufOf<String>(s.data(), s.size())); } template <class String, std::enable_if_t<!std::is_pointer<std::remove_reference_t<String>>::value, int> = 0> auto StringSplitter(String&& s) { - return ::NStringSplitPrivate::MakeStringSplitter(std::move(s)); + return ::NStringSplitPrivate::MakeStringSplitter(std::move(s)); } diff --git a/util/string/strip.cpp b/util/string/strip.cpp index c921571cf0..0b942ca06f 100644 --- a/util/string/strip.cpp +++ b/util/string/strip.cpp @@ -1,23 +1,23 @@ #include "strip.h" #include "ascii.h" -#include <util/string/reverse.h> - +#include <util/string/reverse.h> + bool Collapse(const TString& from, TString& to, size_t maxLen) { return CollapseImpl<TString, bool (*)(unsigned char)>(from, to, maxLen, IsAsciiSpace); } void CollapseText(const TString& from, TString& to, size_t maxLen) { Collapse(from, to, maxLen); - StripInPlace(to); + StripInPlace(to); if (to.size() >= maxLen) { to.remove(maxLen - 5); // " ..." - ReverseInPlace(to); + ReverseInPlace(to); size_t pos = to.find_first_of(" .,;"); if (pos != TString::npos && pos < 32) { to.remove(0, pos + 1); } - ReverseInPlace(to); + ReverseInPlace(to); to.append(" ..."); } } diff --git a/util/string/strip.h b/util/string/strip.h index d5ef6da96d..81b97add83 100644 --- a/util/string/strip.h +++ b/util/string/strip.h @@ -183,7 +183,7 @@ static inline bool Strip(const TString& from, TString& to) { } /// Removes leading and trailing spaces from the string. -inline TString& StripInPlace(TString& s) { +inline TString& StripInPlace(TString& s) { Strip(s, s); return s; } @@ -233,14 +233,14 @@ bool CollapseImpl(const TStringType& from, TStringType& to, size_t maxLen, const bool Collapse(const TString& from, TString& to, size_t maxLen = 0); /// Replaces several consequtive space symbols with one (processing is limited to maxLen bytes) -inline TString& CollapseInPlace(TString& s, size_t maxLen = 0) { +inline TString& CollapseInPlace(TString& s, size_t maxLen = 0) { Collapse(s, s, maxLen); return s; } - + /// Replaces several consequtive space symbols with one (processing is limited to maxLen bytes) -inline TString Collapse(const TString& s, size_t maxLen = 0) Y_WARN_UNUSED_RESULT; -inline TString Collapse(const TString& s, size_t maxLen) { +inline TString Collapse(const TString& s, size_t maxLen = 0) Y_WARN_UNUSED_RESULT; +inline TString Collapse(const TString& s, size_t maxLen) { TString ret; Collapse(s, ret, maxLen); return ret; diff --git a/util/string/strip_ut.cpp b/util/string/strip_ut.cpp index d1029d1498..2118e583d8 100644 --- a/util/string/strip_ut.cpp +++ b/util/string/strip_ut.cpp @@ -116,12 +116,12 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { s = TString(" a b c "); TString s2 = s; - CollapseInPlace(s2); + CollapseInPlace(s2); UNIT_ASSERT(s == s2); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s.c_str() == s2.c_str()); // Collapse() does not change the string at all -#endif +#endif } Y_UNIT_TEST(TestCollapseText) { diff --git a/util/string/vector.h b/util/string/vector.h index e36c348bbe..0c9f4d39ac 100644 --- a/util/string/vector.h +++ b/util/string/vector.h @@ -7,7 +7,7 @@ #include <util/generic/strbuf.h> #include <util/generic/string.h> #include <util/generic/vector.h> -#include <util/string/cast.h> +#include <util/string/cast.h> #include <util/system/yassert.h> #define KEEP_EMPTY_TOKENS 0x01 diff --git a/util/system/atexit.cpp b/util/system/atexit.cpp index 74fb10b6b1..45bde32638 100644 --- a/util/system/atexit.cpp +++ b/util/system/atexit.cpp @@ -124,13 +124,13 @@ void AtExit(TAtExitFunc func, void* ctx) { } static void TraditionalCloser(void* ctx) { - reinterpret_cast<TTraditionalAtExitFunc>(ctx)(); + reinterpret_cast<TTraditionalAtExitFunc>(ctx)(); } void AtExit(TTraditionalAtExitFunc func) { - AtExit(TraditionalCloser, reinterpret_cast<void*>(func)); + AtExit(TraditionalCloser, reinterpret_cast<void*>(func)); } void AtExit(TTraditionalAtExitFunc func, size_t priority) { - AtExit(TraditionalCloser, reinterpret_cast<void*>(func), priority); + AtExit(TraditionalCloser, reinterpret_cast<void*>(func), priority); } diff --git a/util/system/atexit_ut.cpp b/util/system/atexit_ut.cpp index 953f432811..fdf0413e0e 100644 --- a/util/system/atexit_ut.cpp +++ b/util/system/atexit_ut.cpp @@ -28,7 +28,7 @@ struct TAtExitParams { }; void MyAtExitFunc(void* ptr) { - THolder<TAtExitParams> params{static_cast<TAtExitParams*>(ptr)}; + THolder<TAtExitParams> params{static_cast<TAtExitParams*>(ptr)}; if (write(params->fd, params->str, strlen(params->str)) < 0) { abort(); } diff --git a/util/system/backtrace.cpp b/util/system/backtrace.cpp index b77fe58fb1..1aa745c0cc 100644 --- a/util/system/backtrace.cpp +++ b/util/system/backtrace.cpp @@ -243,7 +243,7 @@ void FormatBackTrace(IOutputStream* out, void* const* backtrace, size_t backtrac } } -TFormatBackTraceFn FormatBackTraceFn = FormatBackTrace; +TFormatBackTraceFn FormatBackTraceFn = FormatBackTrace; TFormatBackTraceFn SetFormatBackTraceFn(TFormatBackTraceFn f) { TFormatBackTraceFn prevFn = FormatBackTraceFn; @@ -251,12 +251,12 @@ TFormatBackTraceFn SetFormatBackTraceFn(TFormatBackTraceFn f) { return prevFn; } -void FormatBackTrace(IOutputStream* out) { - void* array[300]; - const size_t s = BackTrace(array, Y_ARRAY_SIZE(array)); - FormatBackTraceFn(out, array, s); -} - +void FormatBackTrace(IOutputStream* out) { + void* array[300]; + const size_t s = BackTrace(array, Y_ARRAY_SIZE(array)); + FormatBackTraceFn(out, array, s); +} + TFormatBackTraceFn GetFormatBackTraceFn() { return FormatBackTraceFn; } @@ -275,7 +275,7 @@ void TBackTrace::Capture() { } void TBackTrace::PrintTo(IOutputStream& out) const { - FormatBackTraceFn(&out, Data, Size); + FormatBackTraceFn(&out, Data, Size); } TString TBackTrace::PrintToString() const { @@ -283,7 +283,7 @@ TString TBackTrace::PrintToString() const { PrintTo(ss); return ss.Str(); } - + size_t TBackTrace::size() const { return Size; } @@ -296,12 +296,12 @@ TBackTrace::operator TBackTraceView() const { return TBackTraceView(Data, Size); } -TBackTrace TBackTrace::FromCurrentException() { -#ifdef _YNDX_LIBUNWIND_EXCEPTION_BACKTRACE_SIZE - TBackTrace result; - result.Size = __cxxabiv1::__cxa_collect_current_exception_backtrace(result.Data, CAPACITY); - return result; -#else - return TBackTrace(); -#endif -} +TBackTrace TBackTrace::FromCurrentException() { +#ifdef _YNDX_LIBUNWIND_EXCEPTION_BACKTRACE_SIZE + TBackTrace result; + result.Size = __cxxabiv1::__cxa_collect_current_exception_backtrace(result.Data, CAPACITY); + return result; +#else + return TBackTrace(); +#endif +} diff --git a/util/system/backtrace.h b/util/system/backtrace.h index 2fce7585c3..4271597f57 100644 --- a/util/system/backtrace.h +++ b/util/system/backtrace.h @@ -18,7 +18,7 @@ void FormatBackTrace(IOutputStream* out, void* const* backtrace, size_t backtrac void FormatBackTrace(IOutputStream* out); void PrintBackTrace(); -using TFormatBackTraceFn = void (*)(IOutputStream*, void* const* backtrace, size_t backtraceSize); +using TFormatBackTraceFn = void (*)(IOutputStream*, void* const* backtrace, size_t backtraceSize); TFormatBackTraceFn SetFormatBackTraceFn(TFormatBackTraceFn f); TFormatBackTraceFn GetFormatBackTraceFn(); @@ -27,7 +27,7 @@ using TBackTraceView = TArrayRef<void* const>; class TBackTrace { private: - static constexpr size_t CAPACITY = 300; + static constexpr size_t CAPACITY = 300; void* Data[CAPACITY]; size_t Size; @@ -39,6 +39,6 @@ public: size_t size() const; const void* const* data() const; operator TBackTraceView() const; - - static TBackTrace FromCurrentException(); + + static TBackTrace FromCurrentException(); }; diff --git a/util/system/condvar_ut.cpp b/util/system/condvar_ut.cpp index 5130a18d32..a0c5b86576 100644 --- a/util/system/condvar_ut.cpp +++ b/util/system/condvar_ut.cpp @@ -6,7 +6,7 @@ #include <util/system/atomic.h> #include <util/system/atomic_ops.h> -#include <util/thread/pool.h> +#include <util/thread/pool.h> class TCondVarTest: public TTestBase { UNIT_TEST_SUITE(TCondVarTest); @@ -194,7 +194,7 @@ private: } #undef RUN_CYCLE TSharedData Data_; - TThreadPool Q_; + TThreadPool Q_; }; UNIT_TEST_SUITE_REGISTRATION(TCondVarTest); diff --git a/util/system/context.cpp b/util/system/context.cpp index ad99309088..1edc6a9b7a 100644 --- a/util/system/context.cpp +++ b/util/system/context.cpp @@ -189,7 +189,7 @@ TContMachineContext::TContMachineContext(const TContClosure& c) __mysetjmp(Buf_); - JmpBufProgrReg(Buf_) = reinterpret_cast<void*>(ContextTrampoLine); + JmpBufProgrReg(Buf_) = reinterpret_cast<void*>(ContextTrampoLine); JmpBufStackReg(Buf_) = stack.StackPtr(); JmpBufFrameReg(Buf_) = nullptr; } diff --git a/util/system/cpu_id.cpp b/util/system/cpu_id.cpp index 598c71f4d9..67eabee3be 100644 --- a/util/system/cpu_id.cpp +++ b/util/system/cpu_id.cpp @@ -162,10 +162,10 @@ bool NX86::HaveBMI1() noexcept { return (TX86CpuInfo(0x7, 0).EBX >> 3) & 1u; } -bool NX86::HaveBMI2() noexcept { - return (TX86CpuInfo(0x7, 0).EBX >> 8) & 1u; -} - +bool NX86::HaveBMI2() noexcept { + return (TX86CpuInfo(0x7, 0).EBX >> 8) & 1u; +} + bool NX86::HaveAVX512F() noexcept { #if defined(_x86_) // https://software.intel.com/en-us/articles/how-to-detect-knl-instruction-support diff --git a/util/system/cpu_id.h b/util/system/cpu_id.h index 3c49e728a7..dc300cdbff 100644 --- a/util/system/cpu_id.h +++ b/util/system/cpu_id.h @@ -14,7 +14,7 @@ F(F16C) \ F(POPCNT) \ F(BMI1) \ - F(BMI2) \ + F(BMI2) \ F(PCLMUL) \ F(AES) \ F(AVX) \ diff --git a/util/system/cpu_id_ut.cpp b/util/system/cpu_id_ut.cpp index 68f1f8aac7..9e0898ea89 100644 --- a/util/system/cpu_id_ut.cpp +++ b/util/system/cpu_id_ut.cpp @@ -23,7 +23,7 @@ static void ExecuteAVXInstruction(); static void ExecuteAVX2Instruction(); static void ExecutePOPCNTInstruction(); static void ExecuteBMI1Instruction(); -static void ExecuteBMI2Instruction(); +static void ExecuteBMI2Instruction(); static void ExecutePCLMULInstruction(); static void ExecuteAESInstruction(); static void ExecuteAVXInstruction(); @@ -169,13 +169,13 @@ void ExecuteBMI1Instruction() { : "eax"); } -void ExecuteBMI2Instruction() { - __asm__ __volatile__("pdep %%rax, %%rdi, %%rax\n" - : - : - : "rax"); -} - +void ExecuteBMI2Instruction() { + __asm__ __volatile__("pdep %%rax, %%rdi, %%rax\n" + : + : + : "rax"); +} + void ExecutePCLMULInstruction() { __asm__ __volatile__("pclmullqlqdq %%xmm0, %%xmm0\n" : @@ -291,9 +291,9 @@ void ExecutePOPCNTInstruction() { void ExecuteBMI1Instruction() { } -void ExecuteBMI2Instruction() { -} - +void ExecuteBMI2Instruction() { +} + void ExecutePCLMULInstruction() { } @@ -388,9 +388,9 @@ void ExecutePOPCNTInstruction() { void ExecuteBMI1Instruction() { } -void ExecuteBMI2Instruction() { -} - +void ExecuteBMI2Instruction() { +} + void ExecutePCLMULInstruction() { } diff --git a/util/system/event_ut.cpp b/util/system/event_ut.cpp index 2506cb7a91..5e94a0890f 100644 --- a/util/system/event_ut.cpp +++ b/util/system/event_ut.cpp @@ -3,7 +3,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/thread/pool.h> +#include <util/thread/pool.h> namespace { struct TSharedData { @@ -85,7 +85,7 @@ namespace { Y_UNIT_TEST_SUITE(EventTest) { Y_UNIT_TEST(WaitAndSignalTest) { TSharedData data; - TThreadPool queue; + TThreadPool queue; queue.Start(5); for (size_t i = 0; i < 5; ++i) { UNIT_ASSERT(queue.Add(new TThreadTask(data, i))); @@ -99,7 +99,7 @@ Y_UNIT_TEST_SUITE(EventTest) { // test for problem detected by thread-sanitizer (signal/wait race) SEARCH-2113 const size_t limit = 200; TManualEvent event[limit]; - TThreadPool queue; + TThreadPool queue; queue.Start(limit); TVector<THolder<IObjectInQueue>> tasks; for (size_t i = 0; i < limit; ++i) { @@ -122,7 +122,7 @@ Y_UNIT_TEST_SUITE(EventTest) { tasks.emplace_back(std::move(owner)); } - TThreadPool queue; + TThreadPool queue; queue.Start(4); for (auto& task : tasks) { UNIT_ASSERT(queue.Add(task.Get())); diff --git a/util/system/execpath.cpp b/util/system/execpath.cpp index 33198af58b..1b8d1ad4e4 100644 --- a/util/system/execpath.cpp +++ b/util/system/execpath.cpp @@ -159,13 +159,13 @@ static bool GetPersistentExecPathImpl(TString& to) { #if defined(_solaris_) to = TString("/proc/self/object/a.out"); return true; -#elif defined(_linux_) || defined(_cygwin_) +#elif defined(_linux_) || defined(_cygwin_) to = TString("/proc/self/exe"); return true; #elif defined(_freebsd_) to = TString("/proc/curproc/file"); return true; -#else // defined(_win_) || defined(_darwin_) or unknown +#else // defined(_win_) || defined(_darwin_) or unknown Y_UNUSED(to); return false; #endif diff --git a/util/system/fasttime.cpp b/util/system/fasttime.cpp index 057a814f0a..8a93e76137 100644 --- a/util/system/fasttime.cpp +++ b/util/system/fasttime.cpp @@ -34,16 +34,16 @@ namespace { : Func(nullptr) { // not DEFAULT, cause library/cpp/gettimeofday - Func = reinterpret_cast<TFunc>(dlsym(RTLD_NEXT, "gettimeofday")); + Func = reinterpret_cast<TFunc>(dlsym(RTLD_NEXT, "gettimeofday")); #if defined(_musl_) if (!Func) { - Func = reinterpret_cast<TFunc>(NVdso::Function("__vdso_gettimeofday", "LINUX_2.6")); + Func = reinterpret_cast<TFunc>(NVdso::Function("__vdso_gettimeofday", "LINUX_2.6")); } #endif if (!Func) { - Func = reinterpret_cast<TFunc>(Libc()->Sym("gettimeofday")); + Func = reinterpret_cast<TFunc>(Libc()->Sym("gettimeofday")); } } diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 7454a4cb94..40bf8cfea1 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -1,7 +1,7 @@ #include "info.h" #include "madvise.h" #include "defaults.h" -#include "hi_lo.h" +#include "hi_lo.h" #include <util/generic/buffer.h> #include <util/generic/yexception.h> @@ -239,7 +239,7 @@ public: result.Ptr = MapViewOfFile(Mapping_, (Mode_ & oAccessMask) == oRdOnly ? FILE_MAP_READ : (Mode_ & oAccessMask) == oCopyOnWr ? FILE_MAP_COPY : FILE_MAP_WRITE, - Hi32(base), Lo32(base), size); + Hi32(base), Lo32(base), size); #else #if defined(_unix_) if (Mode_ & oNotGreedy) { diff --git a/util/system/guard_ut.cpp b/util/system/guard_ut.cpp index 404ede99ab..14edb97f45 100644 --- a/util/system/guard_ut.cpp +++ b/util/system/guard_ut.cpp @@ -3,7 +3,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/thread/pool.h> +#include <util/thread/pool.h> struct TTestGuard: public TTestBase { UNIT_TEST_SUITE(TTestGuard); diff --git a/util/system/hi_lo.cpp b/util/system/hi_lo.cpp index 97c3eba8be..2950bc6096 100644 --- a/util/system/hi_lo.cpp +++ b/util/system/hi_lo.cpp @@ -1 +1 @@ -#include "hi_lo.h" +#include "hi_lo.h" diff --git a/util/system/hi_lo.h b/util/system/hi_lo.h index f86870534f..3dad401140 100644 --- a/util/system/hi_lo.h +++ b/util/system/hi_lo.h @@ -1,149 +1,149 @@ -#pragma once - -#include "unaligned_mem.h" - +#pragma once + +#include "unaligned_mem.h" + #include <utility> -#ifndef _little_endian_ +#ifndef _little_endian_ #error "Not implemented" -#endif - -namespace NHiLoPrivate { - template <class TRepr> - class TConstIntRef { - public: - explicit TConstIntRef(const char* ptr) - : Ptr(ptr) - { - } - +#endif + +namespace NHiLoPrivate { + template <class TRepr> + class TConstIntRef { + public: + explicit TConstIntRef(const char* ptr) + : Ptr(ptr) + { + } + TRepr Get() const { return ReadUnaligned<TRepr>(Ptr); } operator TRepr() const { return Get(); } - + const char* GetPtr() const { return Ptr; } - - protected: - const char* Ptr; - }; - - template <class TRepr> + + protected: + const char* Ptr; + }; + + template <class TRepr> class TIntRef: public TConstIntRef<TRepr> { - public: - explicit TIntRef(char* ptr) - : TConstIntRef<TRepr>(ptr) - { - } - - TIntRef& operator=(TRepr value) { + public: + explicit TIntRef(char* ptr) + : TConstIntRef<TRepr>(ptr) + { + } + + TIntRef& operator=(TRepr value) { WriteUnaligned<TRepr>(GetPtr(), value); - return *this; - } - + return *this; + } + char* GetPtr() const { return const_cast<char*>(this->Ptr); } - }; - - template <class T> - struct TReferenceType { - using TType = T; - }; - - template <class T> - struct TReferenceType<TConstIntRef<T>> { - using TType = T; - }; - - template <class T> - struct TReferenceType<TIntRef<T>> { - using TType = T; - }; - - template <class TRepr> - auto MakeIntRef(const char* ptr) { - return TConstIntRef<TRepr>(ptr); - } - - template <class TRepr> - auto MakeIntRef(char* ptr) { - return TIntRef<TRepr>(ptr); - } - - template <class T> - const char* CharPtrOf(const T& value) { + }; + + template <class T> + struct TReferenceType { + using TType = T; + }; + + template <class T> + struct TReferenceType<TConstIntRef<T>> { + using TType = T; + }; + + template <class T> + struct TReferenceType<TIntRef<T>> { + using TType = T; + }; + + template <class TRepr> + auto MakeIntRef(const char* ptr) { + return TConstIntRef<TRepr>(ptr); + } + + template <class TRepr> + auto MakeIntRef(char* ptr) { + return TIntRef<TRepr>(ptr); + } + + template <class T> + const char* CharPtrOf(const T& value) { return reinterpret_cast<const char*>(&value); - } - - template <class T> - char* CharPtrOf(T& value) { + } + + template <class T> + char* CharPtrOf(T& value) { return reinterpret_cast<char*>(&value); - } - - template <class T> - const char* CharPtrOf(TConstIntRef<T> value) { - return value.GetPtr(); - } - - template <class T> - char* CharPtrOf(TIntRef<T> value) { - return value.GetPtr(); - } - - template <bool IsLow, class TRepr, class T> - auto MakeIntRef(T&& value) { - using TRef = typename TReferenceType<typename std::decay<T>::type>::TType; - static_assert( + } + + template <class T> + const char* CharPtrOf(TConstIntRef<T> value) { + return value.GetPtr(); + } + + template <class T> + char* CharPtrOf(TIntRef<T> value) { + return value.GetPtr(); + } + + template <bool IsLow, class TRepr, class T> + auto MakeIntRef(T&& value) { + using TRef = typename TReferenceType<typename std::decay<T>::type>::TType; + static_assert( std::is_scalar<TRef>::value, "Hi* and Lo* functions can be applied only to scalar values"); - static_assert(sizeof(TRef) >= sizeof(TRepr), "Requested bit range is not within provided value"); - constexpr size_t offset = IsLow ? 0 : sizeof(TRef) - sizeof(TRepr); - - return MakeIntRef<TRepr>(CharPtrOf(std::forward<T>(value)) + offset); - } -} - -/** - * Return manipulator object that allows to get and set lower or higher bits of the value. - * - * @param value Must be a scalar value of sufficient size or a manipulator object obtained by - * calling any of the other Hi/Lo functions. - * - * @{ - */ -template <class T> -auto Lo32(T&& value) { - return NHiLoPrivate::MakeIntRef<true, ui32>(std::forward<T>(value)); -} - -template <class T> -auto Hi32(T&& value) { - return NHiLoPrivate::MakeIntRef<false, ui32>(std::forward<T>(value)); -} - -template <class T> -auto Lo16(T&& value) { - return NHiLoPrivate::MakeIntRef<true, ui16>(std::forward<T>(value)); -} - -template <class T> -auto Hi16(T&& value) { - return NHiLoPrivate::MakeIntRef<false, ui16>(std::forward<T>(value)); -} - -template <class T> -auto Lo8(T&& value) { - return NHiLoPrivate::MakeIntRef<true, ui8>(std::forward<T>(value)); -} - -template <class T> -auto Hi8(T&& value) { - return NHiLoPrivate::MakeIntRef<false, ui8>(std::forward<T>(value)); -} - -/** @} */ + static_assert(sizeof(TRef) >= sizeof(TRepr), "Requested bit range is not within provided value"); + constexpr size_t offset = IsLow ? 0 : sizeof(TRef) - sizeof(TRepr); + + return MakeIntRef<TRepr>(CharPtrOf(std::forward<T>(value)) + offset); + } +} + +/** + * Return manipulator object that allows to get and set lower or higher bits of the value. + * + * @param value Must be a scalar value of sufficient size or a manipulator object obtained by + * calling any of the other Hi/Lo functions. + * + * @{ + */ +template <class T> +auto Lo32(T&& value) { + return NHiLoPrivate::MakeIntRef<true, ui32>(std::forward<T>(value)); +} + +template <class T> +auto Hi32(T&& value) { + return NHiLoPrivate::MakeIntRef<false, ui32>(std::forward<T>(value)); +} + +template <class T> +auto Lo16(T&& value) { + return NHiLoPrivate::MakeIntRef<true, ui16>(std::forward<T>(value)); +} + +template <class T> +auto Hi16(T&& value) { + return NHiLoPrivate::MakeIntRef<false, ui16>(std::forward<T>(value)); +} + +template <class T> +auto Lo8(T&& value) { + return NHiLoPrivate::MakeIntRef<true, ui8>(std::forward<T>(value)); +} + +template <class T> +auto Hi8(T&& value) { + return NHiLoPrivate::MakeIntRef<false, ui8>(std::forward<T>(value)); +} + +/** @} */ diff --git a/util/system/hi_lo_ut.cpp b/util/system/hi_lo_ut.cpp index 850c12327d..c19e7bbb02 100644 --- a/util/system/hi_lo_ut.cpp +++ b/util/system/hi_lo_ut.cpp @@ -1,62 +1,62 @@ -#include <util/system/hi_lo.h> - +#include <util/system/hi_lo.h> + #include <library/cpp/testing/unittest/registar.h> - -#include "defaults.h" - -Y_UNIT_TEST_SUITE(HiLo) { + +#include "defaults.h" + +Y_UNIT_TEST_SUITE(HiLo) { Y_UNIT_TEST(HiLo32) { ui64 x = 0; Lo32(x) = 18; UNIT_ASSERT_VALUES_EQUAL(x, 18); - + Hi32(x) = 33; UNIT_ASSERT_VALUES_EQUAL(x, 141733920786); - + const ui64 y = 0x33c06196e94c03ab; UNIT_ASSERT_VALUES_EQUAL(Lo32(y).Get(), 0xe94c03ab); UNIT_ASSERT_VALUES_EQUAL(Hi32(y).Get(), 0x33c06196); } - + Y_UNIT_TEST(HiLo16) { ui32 x = 0; Lo16(x) = 18; UNIT_ASSERT_VALUES_EQUAL(x, 18); - + Hi16(x) = 33; UNIT_ASSERT_VALUES_EQUAL(x, 2162706); - + const ui32 y = 0xe94c03ab; UNIT_ASSERT_VALUES_EQUAL(Lo16(y).Get(), 0x03ab); UNIT_ASSERT_VALUES_EQUAL(Hi16(y).Get(), 0xe94c); } - + Y_UNIT_TEST(HiLo8) { ui16 x = 0; Lo8(x) = 18; UNIT_ASSERT_VALUES_EQUAL(x, 18); - + Hi8(x) = 33; UNIT_ASSERT_VALUES_EQUAL(x, 8466); - + const ui16 y = 0x03ab; UNIT_ASSERT_VALUES_EQUAL(Lo8(y).Get(), 0xab); UNIT_ASSERT_VALUES_EQUAL(Hi8(y).Get(), 0x03); } - + Y_UNIT_TEST(Combined) { ui32 x = 0; Lo8(Lo16(x)) = 18; UNIT_ASSERT_VALUES_EQUAL(x, 18); - + Hi8(Lo16(x)) = 33; UNIT_ASSERT_VALUES_EQUAL(x, 8466); - + const ui32 y = 0xe94c03ab; UNIT_ASSERT_VALUES_EQUAL(Lo8(Lo16(y)).Get(), 0xab); UNIT_ASSERT_VALUES_EQUAL(Hi8(Lo16(y)).Get(), 0x03); } - + Y_UNIT_TEST(NarrowFromWide) { const ui64 x = 0x1122334455667788ull; UNIT_ASSERT_VALUES_EQUAL(Lo8(x).Get(), 0x88); @@ -66,4 +66,4 @@ Y_UNIT_TEST_SUITE(HiLo) { UNIT_ASSERT_VALUES_EQUAL(Lo32(x).Get(), 0x55667788); UNIT_ASSERT_VALUES_EQUAL(Hi32(x).Get(), 0x11223344); } -} +} diff --git a/util/system/mutex_ut.cpp b/util/system/mutex_ut.cpp index c8d7caafa1..1dba4eb0bd 100644 --- a/util/system/mutex_ut.cpp +++ b/util/system/mutex_ut.cpp @@ -3,7 +3,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/thread/pool.h> +#include <util/thread/pool.h> #include <util/random/random.h> class TMutexTest: public TTestBase { @@ -123,7 +123,7 @@ private: private: TSharedData Data_; - TThreadPool Q_; + TThreadPool Q_; }; UNIT_TEST_SUITE_REGISTRATION(TMutexTest) diff --git a/util/system/rwlock_ut.cpp b/util/system/rwlock_ut.cpp index 2b384c05b3..235d28a363 100644 --- a/util/system/rwlock_ut.cpp +++ b/util/system/rwlock_ut.cpp @@ -3,7 +3,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/thread/pool.h> +#include <util/thread/pool.h> #include <util/random/random.h> class TRWMutexTest: public TTestBase { @@ -118,7 +118,7 @@ private: #undef RUN_CYCLE private: TSharedData Data_; - TThreadPool Q_; + TThreadPool Q_; }; UNIT_TEST_SUITE_REGISTRATION(TRWMutexTest) diff --git a/util/system/shellcommand.cpp b/util/system/shellcommand.cpp index b1989b5c8c..0ba5b81ac0 100644 --- a/util/system/shellcommand.cpp +++ b/util/system/shellcommand.cpp @@ -13,7 +13,7 @@ #include <util/network/socket.h> #include <util/stream/pipe.h> #include <util/stream/str.h> -#include <util/string/cast.h> +#include <util/string/cast.h> #include <util/system/info.h> #include <errno.h> diff --git a/util/system/thread.cpp b/util/system/thread.cpp index 6236746c2d..d471cfa0f2 100644 --- a/util/system/thread.cpp +++ b/util/system/thread.cpp @@ -44,7 +44,7 @@ namespace { inline void SetThrName(const TParams& p) { try { if (p.Name) { - TThread::SetCurrentThreadName(p.Name.data()); + TThread::SetCurrentThreadName(p.Name.data()); } } catch (...) { // ¯\_(ツ)_/¯ @@ -445,7 +445,7 @@ namespace { } #endif // _win_ -void TThread::SetCurrentThreadName(const char* name) { +void TThread::SetCurrentThreadName(const char* name) { (void)name; #if defined(_freebsd_) @@ -469,7 +469,7 @@ void TThread::SetCurrentThreadName(const char* name) { #endif // OS } -TString TThread::CurrentThreadName() { +TString TThread::CurrentThreadName() { #if defined(_freebsd_) // TODO: check pthread_get_name_np API availability #elif defined(_linux_) diff --git a/util/system/thread.h b/util/system/thread.h index a6e8abdb5b..2a666fb9c2 100644 --- a/util/system/thread.h +++ b/util/system/thread.h @@ -1,8 +1,8 @@ #pragma once /// This code should not be used directly unless you really understand what you do. -/// If you need threads, use thread pool functionality in <util/thread/factory.h> -/// @see SystemThreadFactory() +/// If you need threads, use thread pool functionality in <util/thread/factory.h> +/// @see SystemThreadFactory() #include <util/generic/ptr.h> #include <util/generic/string.h> @@ -26,7 +26,7 @@ public: void* Data; size_t StackSize; void* StackPointer; - // See comments for `SetCurrentThreadName` + // See comments for `SetCurrentThreadName` TString Name = GetProgramName(); inline TParams() @@ -114,12 +114,12 @@ public: // // NOTE: On Linux thread name is limited to 15 symbols which is probably the smallest one among // all platforms. If you provide a name longer than 15 symbols it will be cut. So if you expect - // `CurrentThreadName` to return the same name as `name` make sure it's not longer than 15 + // `CurrentThreadName` to return the same name as `name` make sure it's not longer than 15 // symbols. - static void SetCurrentThreadName(const char* name); + static void SetCurrentThreadName(const char* name); // NOTE: Will return empty string where CanGetCurrentThreadName() returns false. - static TString CurrentThreadName(); + static TString CurrentThreadName(); // NOTE: Depends on a platform version. // Will return true for Darwin, Linux or fresh Windows 10. diff --git a/util/system/thread_ut.cpp b/util/system/thread_ut.cpp index d820898fd5..a2a4aab4cb 100644 --- a/util/system/thread_ut.cpp +++ b/util/system/thread_ut.cpp @@ -47,7 +47,7 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) { } void* ThreadProc(void*) { - TThread::SetCurrentThreadName("CurrentThreadSetNameTest"); + TThread::SetCurrentThreadName("CurrentThreadSetNameTest"); return nullptr; } @@ -56,16 +56,16 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) { } void* ThreadProc3(void*) { - const auto name = TThread::CurrentThreadName(); + const auto name = TThread::CurrentThreadName(); Y_FAKE_READ(name); return nullptr; } void* ThreadProc4(void*) { const TString setName = "ThreadName"; - TThread::SetCurrentThreadName(setName.data()); + TThread::SetCurrentThreadName(setName.data()); - const auto getName = TThread::CurrentThreadName(); + const auto getName = TThread::CurrentThreadName(); if (TThread::CanGetCurrentThreadName()) { UNIT_ASSERT_VALUES_EQUAL(setName, getName); } else { @@ -75,7 +75,7 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) { } void* ThreadProcChild(void*) { - const auto name = TThread::CurrentThreadName(); + const auto name = TThread::CurrentThreadName(); const auto defaultName = GetProgramName(); (void)name; @@ -89,14 +89,14 @@ Y_UNIT_TEST_SUITE(TSysThreadTest) { void* ThreadProcParent(void*) { const TString setName = "Parent"; - TThread::SetCurrentThreadName(setName.data()); + TThread::SetCurrentThreadName(setName.data()); TThread thread(&ThreadProcChild, nullptr); thread.Start(); thread.Join(); - const auto getName = TThread::CurrentThreadName(); + const auto getName = TThread::CurrentThreadName(); if (TThread::CanGetCurrentThreadName()) { UNIT_ASSERT_VALUES_EQUAL(setName, getName); } else { diff --git a/util/system/ut/ya.make b/util/system/ut/ya.make index 127e7c261e..99d468ef35 100644 --- a/util/system/ut/ya.make +++ b/util/system/ut/ya.make @@ -48,7 +48,7 @@ SRCS( system/fstat_ut.cpp system/getpid_ut.cpp system/guard_ut.cpp - system/hi_lo_ut.cpp + system/hi_lo_ut.cpp system/hostname_ut.cpp system/info_ut.cpp system/interrupt_signals_ut.cpp diff --git a/util/thread/factory.cpp b/util/thread/factory.cpp index 48e898f32d..afe2d20760 100644 --- a/util/thread/factory.cpp +++ b/util/thread/factory.cpp @@ -1,12 +1,12 @@ -#include "factory.h" +#include "factory.h" #include <util/system/thread.h> #include <util/generic/singleton.h> -using IThread = IThreadFactory::IThread; +using IThread = IThreadFactory::IThread; namespace { - class TSystemThreadFactory: public IThreadFactory { + class TSystemThreadFactory: public IThreadFactory { public: class TPoolThread: public IThread { public: @@ -42,7 +42,7 @@ namespace { THolder<TThread> Thr_; }; - inline TSystemThreadFactory() noexcept { + inline TSystemThreadFactory() noexcept { } IThread* DoCreate() override { @@ -50,14 +50,14 @@ namespace { } }; - class TThreadFactoryFuncObj: public IThreadFactory::IThreadAble { + class TThreadFactoryFuncObj: public IThreadFactory::IThreadAble { public: - TThreadFactoryFuncObj(const std::function<void()>& func) + TThreadFactoryFuncObj(const std::function<void()>& func) : Func(func) { } void DoExecute() override { - THolder<TThreadFactoryFuncObj> self(this); + THolder<TThreadFactoryFuncObj> self(this); Func(); } @@ -69,18 +69,18 @@ namespace { THolder<IThread> IThreadFactory::Run(std::function<void()> func) { THolder<IThread> ret(DoCreate()); - ret->Run(new ::TThreadFactoryFuncObj(func)); + ret->Run(new ::TThreadFactoryFuncObj(func)); return ret; } -static IThreadFactory* SystemThreadPoolImpl() { - return Singleton<TSystemThreadFactory>(); +static IThreadFactory* SystemThreadPoolImpl() { + return Singleton<TSystemThreadFactory>(); } -static IThreadFactory* systemPool = nullptr; +static IThreadFactory* systemPool = nullptr; -IThreadFactory* SystemThreadFactory() { +IThreadFactory* SystemThreadFactory() { if (systemPool) { return systemPool; } @@ -88,6 +88,6 @@ IThreadFactory* SystemThreadFactory() { return SystemThreadPoolImpl(); } -void SetSystemThreadFactory(IThreadFactory* pool) { +void SetSystemThreadFactory(IThreadFactory* pool) { systemPool = pool; } diff --git a/util/thread/factory.h b/util/thread/factory.h index 561fcbac88..f60a8ba56d 100644 --- a/util/thread/factory.h +++ b/util/thread/factory.h @@ -3,7 +3,7 @@ #include <util/generic/ptr.h> #include <functional> -class IThreadFactory { +class IThreadFactory { public: class IThreadAble { public: @@ -20,7 +20,7 @@ public: }; class IThread { - friend class IThreadFactory; + friend class IThreadFactory; public: inline IThread() noexcept = default; @@ -42,9 +42,9 @@ public: virtual void DoJoin() noexcept = 0; }; - inline IThreadFactory() noexcept = default; + inline IThreadFactory() noexcept = default; - virtual ~IThreadFactory() = default; + virtual ~IThreadFactory() = default; // XXX: rename to Start inline THolder<IThread> Run(IThreadAble* func) { @@ -61,5 +61,5 @@ private: virtual IThread* DoCreate() = 0; }; -IThreadFactory* SystemThreadFactory(); -void SetSystemThreadFactory(IThreadFactory* pool); +IThreadFactory* SystemThreadFactory(); +void SetSystemThreadFactory(IThreadFactory* pool); diff --git a/util/thread/factory_ut.cpp b/util/thread/factory_ut.cpp index 647d96c901..d366467787 100644 --- a/util/thread/factory_ut.cpp +++ b/util/thread/factory_ut.cpp @@ -1,5 +1,5 @@ -#include "factory.h" -#include "pool.h" +#include "factory.h" +#include "pool.h" #include <library/cpp/testing/unittest/registar.h> @@ -9,7 +9,7 @@ class TThrPoolTest: public TTestBase { UNIT_TEST(TestAdaptivePool) UNIT_TEST_SUITE_END(); - struct TRunAble: public IThreadFactory::IThreadAble { + struct TRunAble: public IThreadFactory::IThreadAble { inline TRunAble() : done(false) { @@ -41,7 +41,7 @@ private: TRunAble r; { - TAdaptiveThreadPool pool; + TAdaptiveThreadPool pool; pool.Start(0); diff --git a/util/thread/fwd.h b/util/thread/fwd.h index 6f1caed21c..f55d566b62 100644 --- a/util/thread/fwd.h +++ b/util/thread/fwd.h @@ -13,18 +13,18 @@ class TAutoLockFreeQueue; template <class T> class TLockFreeStack; -class IThreadFactory; +class IThreadFactory; struct IObjectInQueue; -class TThreadFactoryHolder; +class TThreadFactoryHolder; using TThreadFunction = std::function<void()>; -class IThreadPool; -class TFakeThreadPool; -class TThreadPool; -class TAdaptiveThreadPool; -class TSimpleThreadPool; +class IThreadPool; +class TFakeThreadPool; +class TThreadPool; +class TAdaptiveThreadPool; +class TSimpleThreadPool; template <class TQueueType, class TSlave> -class TThreadPoolBinder; +class TThreadPoolBinder; diff --git a/util/thread/pool.cpp b/util/thread/pool.cpp index 05fad02e9b..3564449f74 100644 --- a/util/thread/pool.cpp +++ b/util/thread/pool.cpp @@ -24,8 +24,8 @@ #include <util/datetime/base.h> -#include "factory.h" -#include "pool.h" +#include "factory.h" +#include "pool.h" namespace { class TThreadNamer { @@ -60,13 +60,13 @@ namespace { }; } -TThreadFactoryHolder::TThreadFactoryHolder() noexcept - : Pool_(SystemThreadFactory()) +TThreadFactoryHolder::TThreadFactoryHolder() noexcept + : Pool_(SystemThreadFactory()) { } -class TThreadPool::TImpl: public TIntrusiveListItem<TImpl>, public IThreadFactory::IThreadAble { - using TTsr = IThreadPool::TTsr; +class TThreadPool::TImpl: public TIntrusiveListItem<TImpl>, public IThreadFactory::IThreadAble { + using TTsr = IThreadPool::TTsr; using TJobQueue = TFastQueue<IObjectInQueue*>; using TThreadRef = THolder<IThreadFactory::IThread>; @@ -253,7 +253,7 @@ private: } private: - TThreadPool* Parent_; + TThreadPool* Parent_; const bool Blocking; const bool Catching; TThreadNamer Namer; @@ -315,9 +315,9 @@ private: }; }; -TThreadPool::~TThreadPool() = default; +TThreadPool::~TThreadPool() = default; -size_t TThreadPool::Size() const noexcept { +size_t TThreadPool::Size() const noexcept { if (!Impl_.Get()) { return 0; } @@ -325,7 +325,7 @@ size_t TThreadPool::Size() const noexcept { return Impl_->Size(); } -size_t TThreadPool::GetThreadCountExpected() const noexcept { +size_t TThreadPool::GetThreadCountExpected() const noexcept { if (!Impl_.Get()) { return 0; } @@ -333,7 +333,7 @@ size_t TThreadPool::GetThreadCountExpected() const noexcept { return Impl_->GetThreadCountExpected(); } -size_t TThreadPool::GetThreadCountReal() const noexcept { +size_t TThreadPool::GetThreadCountReal() const noexcept { if (!Impl_.Get()) { return 0; } @@ -341,7 +341,7 @@ size_t TThreadPool::GetThreadCountReal() const noexcept { return Impl_->GetThreadCountReal(); } -size_t TThreadPool::GetMaxQueueSize() const noexcept { +size_t TThreadPool::GetMaxQueueSize() const noexcept { if (!Impl_.Get()) { return 0; } @@ -349,7 +349,7 @@ size_t TThreadPool::GetMaxQueueSize() const noexcept { return Impl_->GetMaxQueueSize(); } -bool TThreadPool::Add(IObjectInQueue* obj) { +bool TThreadPool::Add(IObjectInQueue* obj) { Y_ENSURE_EX(Impl_.Get(), TThreadPoolException() << TStringBuf("mtp queue not started")); if (Impl_->NeedRestart()) { @@ -359,19 +359,19 @@ bool TThreadPool::Add(IObjectInQueue* obj) { return Impl_->Add(obj); } -void TThreadPool::Start(size_t thrnum, size_t maxque) { +void TThreadPool::Start(size_t thrnum, size_t maxque) { Impl_.Reset(new TImpl(this, thrnum, maxque, Params)); } -void TThreadPool::Stop() noexcept { +void TThreadPool::Stop() noexcept { Impl_.Destroy(); } static TAtomic mtp_queue_counter = 0; -class TAdaptiveThreadPool::TImpl { +class TAdaptiveThreadPool::TImpl { public: - class TThread: public IThreadFactory::IThreadAble { + class TThread: public IThreadFactory::IThreadAble { public: inline TThread(TImpl* parent) : Impl_(parent) @@ -533,7 +533,7 @@ private: } private: - TAdaptiveThreadPool* Parent_; + TAdaptiveThreadPool* Parent_; const bool Catching; TThreadNamer Namer; TAtomic ThrCount_; @@ -563,9 +563,9 @@ DEFINE_THREAD_POOL_CTORS(TThreadPool) DEFINE_THREAD_POOL_CTORS(TAdaptiveThreadPool) DEFINE_THREAD_POOL_CTORS(TSimpleThreadPool) -TAdaptiveThreadPool::~TAdaptiveThreadPool() = default; +TAdaptiveThreadPool::~TAdaptiveThreadPool() = default; -bool TAdaptiveThreadPool::Add(IObjectInQueue* obj) { +bool TAdaptiveThreadPool::Add(IObjectInQueue* obj) { Y_ENSURE_EX(Impl_.Get(), TThreadPoolException() << TStringBuf("mtp queue not started")); Impl_->Add(obj); @@ -573,15 +573,15 @@ bool TAdaptiveThreadPool::Add(IObjectInQueue* obj) { return true; } -void TAdaptiveThreadPool::Start(size_t, size_t) { +void TAdaptiveThreadPool::Start(size_t, size_t) { Impl_.Reset(new TImpl(this, Params)); } -void TAdaptiveThreadPool::Stop() noexcept { +void TAdaptiveThreadPool::Stop() noexcept { Impl_.Destroy(); } -size_t TAdaptiveThreadPool::Size() const noexcept { +size_t TAdaptiveThreadPool::Size() const noexcept { if (Impl_.Get()) { return Impl_->Size(); } @@ -589,13 +589,13 @@ size_t TAdaptiveThreadPool::Size() const noexcept { return 0; } -void TAdaptiveThreadPool::SetMaxIdleTime(TDuration interval) { +void TAdaptiveThreadPool::SetMaxIdleTime(TDuration interval) { Y_ENSURE_EX(Impl_.Get(), TThreadPoolException() << TStringBuf("mtp queue not started")); Impl_->SetMaxIdleTime(interval); } -TSimpleThreadPool::~TSimpleThreadPool() { +TSimpleThreadPool::~TSimpleThreadPool() { try { Stop(); } catch (...) { @@ -603,15 +603,15 @@ TSimpleThreadPool::~TSimpleThreadPool() { } } -bool TSimpleThreadPool::Add(IObjectInQueue* obj) { +bool TSimpleThreadPool::Add(IObjectInQueue* obj) { Y_ENSURE_EX(Slave_.Get(), TThreadPoolException() << TStringBuf("mtp queue not started")); return Slave_->Add(obj); } -void TSimpleThreadPool::Start(size_t thrnum, size_t maxque) { - THolder<IThreadPool> tmp; - TAdaptiveThreadPool* adaptive(nullptr); +void TSimpleThreadPool::Start(size_t thrnum, size_t maxque) { + THolder<IThreadPool> tmp; + TAdaptiveThreadPool* adaptive(nullptr); if (thrnum) { tmp.Reset(new TThreadPoolBinder<TThreadPool, TSimpleThreadPool>(this, Params)); @@ -629,11 +629,11 @@ void TSimpleThreadPool::Start(size_t thrnum, size_t maxque) { Slave_.Swap(tmp); } -void TSimpleThreadPool::Stop() noexcept { +void TSimpleThreadPool::Stop() noexcept { Slave_.Destroy(); } -size_t TSimpleThreadPool::Size() const noexcept { +size_t TSimpleThreadPool::Size() const noexcept { if (Slave_.Get()) { return Slave_->Size(); } @@ -659,7 +659,7 @@ namespace { }; } -void IThreadPool::SafeAdd(IObjectInQueue* obj) { +void IThreadPool::SafeAdd(IObjectInQueue* obj) { Y_ENSURE_EX(Add(obj), TThreadPoolException() << TStringBuf("can not add object to queue")); } @@ -676,8 +676,8 @@ bool IThreadPool::AddAndOwn(THolder<IObjectInQueue> obj) { return added; } -using IThread = IThreadFactory::IThread; -using IThreadAble = IThreadFactory::IThreadAble; +using IThread = IThreadFactory::IThread; +using IThreadAble = IThreadFactory::IThreadAble; namespace { class TPoolThread: public IThread { @@ -724,7 +724,7 @@ namespace { using TThreadImplRef = TIntrusivePtr<TThreadImpl>; public: - inline TPoolThread(IThreadPool* parent) + inline TPoolThread(IThreadPool* parent) : Parent_(parent) { } @@ -751,21 +751,21 @@ namespace { } private: - IThreadPool* Parent_; + IThreadPool* Parent_; TThreadImplRef Impl_; }; } -IThread* IThreadPool::DoCreate() { +IThread* IThreadPool::DoCreate() { return new TPoolThread(this); } THolder<IThreadPool> CreateThreadPool(size_t threadsCount, size_t queueSizeLimit, const TThreadPoolParams& params) { - THolder<IThreadPool> queue; + THolder<IThreadPool> queue; if (threadsCount > 1) { queue.Reset(new TThreadPool(params)); } else { - queue.Reset(new TFakeThreadPool()); + queue.Reset(new TFakeThreadPool()); } queue->Start(threadsCount, queueSizeLimit); return queue; diff --git a/util/thread/pool.h b/util/thread/pool.h index d1ea3a67cb..9876cfc0c0 100644 --- a/util/thread/pool.h +++ b/util/thread/pool.h @@ -1,7 +1,7 @@ #pragma once #include "fwd.h" -#include "factory.h" +#include "factory.h" #include <util/system/yassert.h> #include <util/system/defaults.h> @@ -20,8 +20,8 @@ struct IObjectInQueue { * in multiple threads. * * @param threadSpecificResource is nullptr by default. But if you override - * IThreadPool::CreateThreadSpecificResource, then result of - * IThreadPool::CreateThreadSpecificResource is passed as threadSpecificResource + * IThreadPool::CreateThreadSpecificResource, then result of + * IThreadPool::CreateThreadSpecificResource is passed as threadSpecificResource * parameter. */ virtual void Process(void* threadSpecificResource) = 0; @@ -31,26 +31,26 @@ struct IObjectInQueue { * Mighty class to add 'Pool' method to derived classes. * Useful only for creators of new queue classes. */ -class TThreadFactoryHolder { +class TThreadFactoryHolder { public: - TThreadFactoryHolder() noexcept; + TThreadFactoryHolder() noexcept; - inline TThreadFactoryHolder(IThreadFactory* pool) noexcept + inline TThreadFactoryHolder(IThreadFactory* pool) noexcept : Pool_(pool) { } - inline ~TThreadFactoryHolder() = default; + inline ~TThreadFactoryHolder() = default; - inline IThreadFactory* Pool() const noexcept { + inline IThreadFactory* Pool() const noexcept { return Pool_; } private: - IThreadFactory* Pool_; + IThreadFactory* Pool_; }; -class TThreadPoolException: public yexception { +class TThreadPoolException: public yexception { }; template <class T> @@ -136,11 +136,11 @@ struct TThreadPoolParams { /** * A queue processed simultaneously by several threads */ -class IThreadPool: public IThreadFactory, public TNonCopyable { +class IThreadPool: public IThreadFactory, public TNonCopyable { public: using TParams = TThreadPoolParams; - ~IThreadPool() override = default; + ~IThreadPool() override = default; /** * Safe versions of Add*() functions. Behave exactly like as non-safe @@ -183,11 +183,11 @@ public: public: /** * RAII wrapper for Create/DestroyThreadSpecificResource. - * Useful only for implementers of new IThreadPool queues. + * Useful only for implementers of new IThreadPool queues. */ class TTsr { public: - inline TTsr(IThreadPool* q) + inline TTsr(IThreadPool* q) : Q_(q) , Data_(Q_->CreateThreadSpecificResource()) { @@ -206,14 +206,14 @@ public: } private: - IThreadPool* Q_; + IThreadPool* Q_; void* Data_; }; /** * CreateThreadSpecificResource and DestroyThreadSpecificResource - * called from internals of (TAdaptiveThreadPool, TThreadPool, ...) implementation, - * not by user of IThreadPool interface. + * called from internals of (TAdaptiveThreadPool, TThreadPool, ...) implementation, + * not by user of IThreadPool interface. * Created resource is passed to IObjectInQueue::Proccess function. */ virtual void* CreateThreadSpecificResource() { @@ -231,11 +231,11 @@ private: }; /** - * Single-threaded implementation of IThreadPool, process tasks in same thread when + * Single-threaded implementation of IThreadPool, process tasks in same thread when * added. * Can be used to remove multithreading. */ -class TFakeThreadPool: public IThreadPool { +class TFakeThreadPool: public IThreadPool { public: bool Add(IObjectInQueue* pObj) override Y_WARN_UNUSED_RESULT { TTsr tsr(this); @@ -267,7 +267,7 @@ protected: class TThreadPool: public TThreadPoolBase { public: TThreadPool(const TParams& params = {}); - ~TThreadPool() override; + ~TThreadPool() override; bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; /** @@ -293,7 +293,7 @@ private: class TAdaptiveThreadPool: public TThreadPoolBase { public: TAdaptiveThreadPool(const TParams& params = {}); - ~TAdaptiveThreadPool() override; + ~TAdaptiveThreadPool() override; /** * If working thread waits task too long (more then interval parameter), @@ -313,34 +313,34 @@ private: THolder<TImpl> Impl_; }; -/** Behave like TThreadPool or TAdaptiveThreadPool, choosen by thrnum parameter of Start() */ +/** Behave like TThreadPool or TAdaptiveThreadPool, choosen by thrnum parameter of Start() */ class TSimpleThreadPool: public TThreadPoolBase { public: TSimpleThreadPool(const TParams& params = {}); - ~TSimpleThreadPool() override; + ~TSimpleThreadPool() override; bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; /** - * @parameter thrnum. If thrnum is 0, use TAdaptiveThreadPool with small - * SetMaxIdleTime interval parameter. if thrnum is not 0, use non-blocking TThreadPool + * @parameter thrnum. If thrnum is 0, use TAdaptiveThreadPool with small + * SetMaxIdleTime interval parameter. if thrnum is not 0, use non-blocking TThreadPool */ void Start(size_t thrnum, size_t maxque = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; private: - THolder<IThreadPool> Slave_; + THolder<IThreadPool> Slave_; }; /** * Helper to override virtual functions Create/DestroyThreadSpecificResource - * from IThreadPool and implement them using functions with same name from + * from IThreadPool and implement them using functions with same name from * pointer to TSlave. */ template <class TQueueType, class TSlave> -class TThreadPoolBinder: public TQueueType { +class TThreadPoolBinder: public TQueueType { public: - inline TThreadPoolBinder(TSlave* slave) + inline TThreadPoolBinder(TSlave* slave) : Slave_(slave) { } @@ -352,12 +352,12 @@ public: { } - inline TThreadPoolBinder(TSlave& slave) + inline TThreadPoolBinder(TSlave& slave) : Slave_(&slave) { } - ~TThreadPoolBinder() override { + ~TThreadPoolBinder() override { try { this->Stop(); } catch (...) { @@ -384,7 +384,7 @@ inline void Delete(THolder<IThreadPool> q) { } /** - * Creates and starts TThreadPool if threadsCount > 1, or TFakeThreadPool otherwise - * You could specify blocking and catching modes for TThreadPool only + * Creates and starts TThreadPool if threadsCount > 1, or TFakeThreadPool otherwise + * You could specify blocking and catching modes for TThreadPool only */ THolder<IThreadPool> CreateThreadPool(size_t threadCount, size_t queueSizeLimit = 0, const IThreadPool::TParams& params = {}); diff --git a/util/thread/pool_ut.cpp b/util/thread/pool_ut.cpp index 893770d0c4..f11851ead3 100644 --- a/util/thread/pool_ut.cpp +++ b/util/thread/pool_ut.cpp @@ -1,4 +1,4 @@ -#include "pool.h" +#include "pool.h" #include <library/cpp/testing/unittest/registar.h> @@ -9,15 +9,15 @@ #include <util/system/mutex.h> #include <util/system/condvar.h> -struct TThreadPoolTest { +struct TThreadPoolTest { TSpinLock Lock; long R = -1; struct TTask: public IObjectInQueue { - TThreadPoolTest* Test = nullptr; + TThreadPoolTest* Test = nullptr; long Value = 0; - TTask(TThreadPoolTest* test, int value) + TTask(TThreadPoolTest* test, int value) : Test(test) , Value(value) { @@ -50,7 +50,7 @@ struct TThreadPoolTest { } }; - inline void TestAnyQueue(IThreadPool* queue, size_t queueSize = 1000) { + inline void TestAnyQueue(IThreadPool* queue, size_t queueSize = 1000) { TReallyFastRng32 rand(17); const size_t cnt = 1000; @@ -73,7 +73,7 @@ struct TThreadPoolTest { } }; -class TFailAddQueue: public IThreadPool { +class TFailAddQueue: public IThreadPool { public: bool Add(IObjectInQueue* /*obj*/) override Y_WARN_UNUSED_RESULT { return false; @@ -90,35 +90,35 @@ public: } }; -Y_UNIT_TEST_SUITE(TThreadPoolTest) { - Y_UNIT_TEST(TestTThreadPool) { - TThreadPoolTest t; - TThreadPool q; +Y_UNIT_TEST_SUITE(TThreadPoolTest) { + Y_UNIT_TEST(TestTThreadPool) { + TThreadPoolTest t; + TThreadPool q; t.TestAnyQueue(&q); } - Y_UNIT_TEST(TestTThreadPoolBlocking) { - TThreadPoolTest t; + Y_UNIT_TEST(TestTThreadPoolBlocking) { + TThreadPoolTest t; TThreadPool q(TThreadPool::TParams().SetBlocking(true)); t.TestAnyQueue(&q, 100); } // disabled by pg@ long time ago due to test flaps // Tried to enable: REVIEW:78772 - Y_UNIT_TEST(TestTAdaptiveThreadPool) { + Y_UNIT_TEST(TestTAdaptiveThreadPool) { if (false) { - TThreadPoolTest t; - TAdaptiveThreadPool q; + TThreadPoolTest t; + TAdaptiveThreadPool q; t.TestAnyQueue(&q); } } Y_UNIT_TEST(TestAddAndOwn) { - TThreadPool q; + TThreadPool q; q.Start(2); bool processed = false; bool destructed = false; - q.SafeAddAndOwn(MakeHolder<TThreadPoolTest::TOwnedTask>(processed, destructed)); + q.SafeAddAndOwn(MakeHolder<TThreadPoolTest::TOwnedTask>(processed, destructed)); q.Stop(); UNIT_ASSERT_C(processed, "Not processed"); @@ -135,7 +135,7 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) { Y_UNIT_TEST(TestSafeAddFuncThrows) { TFailAddQueue queue; - UNIT_CHECK_GENERATED_EXCEPTION(queue.SafeAddFunc([] {}), TThreadPoolException); + UNIT_CHECK_GENERATED_EXCEPTION(queue.SafeAddFunc([] {}), TThreadPoolException); } Y_UNIT_TEST(TestFunctionNotCopied) { @@ -147,7 +147,7 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) { } TFailOnCopy(const TFailOnCopy&) { - UNIT_FAIL("Don't copy std::function inside TThreadPool"); + UNIT_FAIL("Don't copy std::function inside TThreadPool"); } }; @@ -160,7 +160,7 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest) { } Y_UNIT_TEST(TestInfoGetters) { - TThreadPool queue; + TThreadPool queue; queue.Start(2, 7); diff --git a/util/thread/ut/ya.make b/util/thread/ut/ya.make index 93198bfaf1..af50ab2452 100644 --- a/util/thread/ut/ya.make +++ b/util/thread/ut/ya.make @@ -4,15 +4,15 @@ OWNER(g:util) SUBSCRIBER(g:util-subscribers) SRCS( - thread/factory_ut.cpp + thread/factory_ut.cpp thread/lfqueue_ut.cpp thread/lfstack_ut.cpp - thread/pool_ut.cpp + thread/pool_ut.cpp thread/singleton_ut.cpp ) -PEERDIR( - library/cpp/threading/future -) - +PEERDIR( + library/cpp/threading/future +) + END() diff --git a/util/ya.make b/util/ya.make index 6ebe7e40cf..a1e8f84534 100644 --- a/util/ya.make +++ b/util/ya.make @@ -228,7 +228,7 @@ JOIN_SRCS( string/hex.cpp string/join.cpp string/printf.cpp - string/reverse.cpp + string/reverse.cpp string/split.cpp string/strip.cpp string/strspn.cpp @@ -242,10 +242,10 @@ IF (ARCH_ARM) CFLAGS(-D_FORTIFY_SOURCE=0) ENDIF() -IF (TSTRING_IS_STD_STRING) - CFLAGS(GLOBAL -DTSTRING_IS_STD_STRING) -ENDIF() - +IF (TSTRING_IS_STD_STRING) + CFLAGS(GLOBAL -DTSTRING_IS_STD_STRING) +ENDIF() + JOIN_SRCS( all_system_1.cpp system/atexit.cpp @@ -270,7 +270,7 @@ JOIN_SRCS( system/fs.cpp system/fstat.cpp system/getpid.cpp - system/hi_lo.cpp + system/hi_lo.cpp system/hostname.cpp system/hp_timer.cpp system/info.cpp @@ -372,11 +372,11 @@ ENDIF() # thread JOIN_SRCS( all_thread.cpp - thread/factory.cpp + thread/factory.cpp thread/fwd.cpp thread/lfqueue.cpp thread/lfstack.cpp - thread/pool.cpp + thread/pool.cpp thread/singleton.cpp ) diff --git a/util/ysaveload.h b/util/ysaveload.h index 02efb4049b..17279b1f17 100644 --- a/util/ysaveload.h +++ b/util/ysaveload.h @@ -370,10 +370,10 @@ template <> class TSerializer<TUtf16String>: public TVectorSerializer<TUtf16String> { }; -template <class TChar> -class TSerializer<std::basic_string<TChar>>: public TVectorSerializer<std::basic_string<TChar>> { -}; - +template <class TChar> +class TSerializer<std::basic_string<TChar>>: public TVectorSerializer<std::basic_string<TChar>> { +}; + template <class T, class A> class TSerializer<TDeque<T, A>>: public TVectorSerializer<TDeque<T, A>> { }; @@ -640,7 +640,7 @@ public: }; #ifndef __NVCC__ - + namespace NPrivate { template <class Variant, class T, size_t I> void LoadVariantAlternative(IInputStream* is, Variant& v) { @@ -651,14 +651,14 @@ namespace NPrivate { } template <typename... Args> -struct TSerializer<std::variant<Args...>> { - using TVar = std::variant<Args...>; +struct TSerializer<std::variant<Args...>> { + using TVar = std::variant<Args...>; static_assert(sizeof...(Args) < 256, "We use ui8 to store tag"); static void Save(IOutputStream* os, const TVar& v) { - ::Save<ui8>(os, v.index()); - std::visit([os](const auto& data) { + ::Save<ui8>(os, v.index()); + std::visit([os](const auto& data) { ::Save(os, data); }, v); } @@ -681,8 +681,8 @@ private: } }; -#endif - +#endif + template <class T> static inline void SaveLoad(IOutputStream* out, const T& t) { Save(out, t); @@ -711,15 +711,15 @@ static inline void LoadMany(S* s, Ts&... t) { inline void Load(IInputStream* s) { \ ::LoadMany(s, __VA_ARGS__); \ } - -#define Y_SAVELOAD_DEFINE_OVERRIDE(...) \ - void Save(IOutputStream* s) const override { \ - ::SaveMany(s, __VA_ARGS__); \ - } \ - \ - void Load(IInputStream* s) override { \ - ::LoadMany(s, __VA_ARGS__); \ - } + +#define Y_SAVELOAD_DEFINE_OVERRIDE(...) \ + void Save(IOutputStream* s) const override { \ + ::SaveMany(s, __VA_ARGS__); \ + } \ + \ + void Load(IInputStream* s) override { \ + ::LoadMany(s, __VA_ARGS__); \ + } template <class T> struct TNonVirtualSaver { diff --git a/util/ysaveload_ut.cpp b/util/ysaveload_ut.cpp index 723c68f391..3f6c9d8bd1 100644 --- a/util/ysaveload_ut.cpp +++ b/util/ysaveload_ut.cpp @@ -284,9 +284,9 @@ private: } UNIT_ASSERT_EQUAL(values.size(), 3); - UNIT_ASSERT_EQUAL(values.contains(3), true); - UNIT_ASSERT_EQUAL(values.contains(4), true); - UNIT_ASSERT_EQUAL(values.contains(5), true); + UNIT_ASSERT_EQUAL(values.contains(3), true); + UNIT_ASSERT_EQUAL(values.contains(4), true); + UNIT_ASSERT_EQUAL(values.contains(5), true); } { @@ -413,11 +413,11 @@ private: TBufferStream s; ::Save(&s, v); ::Load(&s, v); - UNIT_ASSERT_VALUES_EQUAL(std::get<T>(v), expected); + UNIT_ASSERT_VALUES_EQUAL(std::get<T>(v), expected); } void TestVariant() { - std::variant<int, bool, TString, TVector<char>> v(1); + std::variant<int, bool, TString, TVector<char>> v(1); TestVariantImpl(v, 42); TestVariantImpl(v, true); TestVariantImpl(v, TString("foo")); @@ -427,7 +427,7 @@ private: TBufferStream s; ::Save(&s, v); - std::variant<char, bool> v2 = false; + std::variant<char, bool> v2 = false; UNIT_ASSERT_EXCEPTION(::Load(&s, v2), TLoadEOF); } |