diff options
author | swarmer <swarmer@yandex-team.ru> | 2022-02-10 16:46:31 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:31 +0300 |
commit | 317da38588b7898a99fd9168571408123350012b (patch) | |
tree | 25eebc31526019ad39a6c1b13f492963d97ba439 | |
parent | 3b2241461d41d41ba1a706b0750c4f0f55c344f6 (diff) | |
download | ydb-317da38588b7898a99fd9168571408123350012b.tar.gz |
Restoring authorship annotation for <swarmer@yandex-team.ru>. Commit 1 of 2.
183 files changed, 2350 insertions, 2350 deletions
diff --git a/build/ymake.core.conf b/build/ymake.core.conf index 081833998b..b1edbf045c 100644 --- a/build/ymake.core.conf +++ b/build/ymake.core.conf @@ -6812,7 +6812,7 @@ RELEV_FML_CODEGEN_INCLS=${output_include;hide:"kernel/relevfml/relev_fml.h"} ${o macro GENERATE_ENUM_SERIALIZATION(File) { .CMD=$ENUM_PARSER_TOOL ${input:File} --include-path ${input;rootrel:File} --output ${output;chksum;suf=_serialized.cpp:File} ${output_include;hide:File} ${output_include;hide:"util/generic/serialized_enum.h"} ${kv;hide:"p EN"} ${kv;hide:"pc yellow"} .SEM=generate_enum_serilization ${input:File} ${output;hide;suf=_serialized.o:File} INCLUDE_HEADERS ${input;rootrel:File} ${tool;hide:"tools/enum_parser/enum_parser/bin"} - PEERDIR(tools/enum_parser/enum_serialization_runtime) + PEERDIR(tools/enum_parser/enum_serialization_runtime) } ### @usage: GENERATE_ENUM_SERIALIZATION_WITH_HEADER(File.h) @@ -6824,7 +6824,7 @@ macro GENERATE_ENUM_SERIALIZATION(File) { macro GENERATE_ENUM_SERIALIZATION_WITH_HEADER(File) { .CMD=$ENUM_PARSER_TOOL ${input:File} --include-path ${input;rootrel:File} --output ${output;chksum;suf=_serialized.cpp:File} --header ${output;chksum;suf=_serialized.h:File} ${output_include;hide:File} ${kv;hide:"p EN"} ${kv;hide:"pc yellow"} .SEM=generate_enum_serilization ${input:File} ${output;hide;suf=_serialized.o:File} GEN_HEADER ${output;suf=_serialized.h:File} INCLUDE_HEADERS ${input;rootrel:File} ${tool;hide:"tools/enum_parser/enum_parser/bin"} - PEERDIR(tools/enum_parser/enum_serialization_runtime) + PEERDIR(tools/enum_parser/enum_serialization_runtime) } ### @usage: DEB_VERSION(File) diff --git a/contrib/libs/pire/pire/run.h b/contrib/libs/pire/pire/run.h index f6e1ff734d..8b8bd9d37d 100644 --- a/contrib/libs/pire/pire/run.h +++ b/contrib/libs/pire/pire/run.h @@ -193,7 +193,7 @@ namespace Impl { const size_t* head = reinterpret_cast<const size_t*>((reinterpret_cast<uintptr_t>(str.begin())) & ~(sizeof(size_t)-1)); const size_t* tail = reinterpret_cast<const size_t*>((reinterpret_cast<uintptr_t>(str.end())) & ~(sizeof(size_t)-1)); - size_t headSize = (sizeof(size_t) - (str.begin() - (const char*)head)); // The distance from @p begin to the end of the word containing @p begin + size_t headSize = (sizeof(size_t) - (str.begin() - (const char*)head)); // The distance from @p begin to the end of the word containing @p begin size_t tailSize = str.end() - (const char*) tail; // The distance from the beginning of the word containing @p end to the @p end Y_ASSERT(headSize >= 1 && headSize <= sizeof(size_t)); diff --git a/contrib/libs/xz/common/ya.make b/contrib/libs/xz/common/ya.make index ce25e6a230..d814bbc9db 100644 --- a/contrib/libs/xz/common/ya.make +++ b/contrib/libs/xz/common/ya.make @@ -17,11 +17,11 @@ VERSION(5.2.4) CFLAGS(-DTUKLIB_SYMBOL_PREFIX=lzma_) -ADDINCL( - contrib/libs/xz +ADDINCL( + contrib/libs/xz contrib/libs/xz/common -) - +) + SRCS( tuklib_cpucores.c ) diff --git a/contrib/libs/xz/liblzma/ya.make b/contrib/libs/xz/liblzma/ya.make index d548283a2b..318f5d4c11 100644 --- a/contrib/libs/xz/liblzma/ya.make +++ b/contrib/libs/xz/liblzma/ya.make @@ -31,7 +31,7 @@ PEERDIR( ADDINCL( GLOBAL contrib/libs/xz/liblzma/api - contrib/libs/xz + contrib/libs/xz contrib/libs/xz/liblzma/check contrib/libs/xz/liblzma/common contrib/libs/xz/liblzma/delta diff --git a/library/cpp/blockcodecs/core/codecs.cpp b/library/cpp/blockcodecs/core/codecs.cpp index 21506e812b..3000c1f333 100644 --- a/library/cpp/blockcodecs/core/codecs.cpp +++ b/library/cpp/blockcodecs/core/codecs.cpp @@ -11,7 +11,7 @@ #include <util/system/unaligned_mem.h> #include <util/generic/hash.h> #include <util/generic/cast.h> -#include <util/generic/deque.h> +#include <util/generic/deque.h> #include <util/generic/buffer.h> #include <util/generic/array_ref.h> #include <util/generic/singleton.h> @@ -59,7 +59,7 @@ namespace { Registry[Tmp.back()] = Registry[to]; } - TDeque<TString> Tmp; + TDeque<TString> Tmp; TNullCodec Null; TVector<TCodecPtr> Codecs; typedef THashMap<TStringBuf, ICodec*> TRegistry; diff --git a/library/cpp/containers/bitseq/traits.h b/library/cpp/containers/bitseq/traits.h index 2330b1b4f2..a852ea8d40 100644 --- a/library/cpp/containers/bitseq/traits.h +++ b/library/cpp/containers/bitseq/traits.h @@ -6,9 +6,9 @@ template <typename TWord> struct TBitSeqTraits { - static constexpr ui8 NumBits = CHAR_BIT * sizeof(TWord); - static constexpr TWord ModMask = static_cast<TWord>(NumBits - 1); - static constexpr TWord DivShift = MostSignificantBitCT(NumBits); + static constexpr ui8 NumBits = CHAR_BIT * sizeof(TWord); + static constexpr TWord ModMask = static_cast<TWord>(NumBits - 1); + static constexpr TWord DivShift = MostSignificantBitCT(NumBits); static inline TWord ElemMask(ui8 count) { // NOTE: Shifting by the type's length is UB, so we need this workaround. diff --git a/library/cpp/containers/stack_vector/stack_vec.h b/library/cpp/containers/stack_vector/stack_vec.h index fcc5d9a2a5..42e46e23f2 100644 --- a/library/cpp/containers/stack_vector/stack_vec.h +++ b/library/cpp/containers/stack_vector/stack_vec.h @@ -76,18 +76,18 @@ namespace NPrivate { Y_VERIFY(IsStorageUsed); IsStorageUsed = false; } else { - FallbackAllocator().deallocate(p, n); + FallbackAllocator().deallocate(p, n); } } private: std::aligned_storage_t<sizeof(T), alignof(T)> StackBasedStorage[CountOnStack]; bool IsStorageUsed = false; - - private: - Alloc& FallbackAllocator() noexcept { - return static_cast<Alloc&>(*this); - } + + private: + Alloc& FallbackAllocator() noexcept { + return static_cast<Alloc&>(*this); + } }; } diff --git a/library/cpp/containers/stack_vector/stack_vec_ut.cpp b/library/cpp/containers/stack_vector/stack_vec_ut.cpp index 19f9677781..bdb66f8c4f 100644 --- a/library/cpp/containers/stack_vector/stack_vec_ut.cpp +++ b/library/cpp/containers/stack_vector/stack_vec_ut.cpp @@ -9,16 +9,16 @@ namespace { static_assert(std::is_copy_constructible_v<TNotCopyAssignable>); static_assert(!std::is_copy_assignable_v<TNotCopyAssignable>); - - template <class T, size_t JunkPayloadSize> - struct TThickAlloc: public std::allocator<T> { - template <class U> - struct rebind { - using other = TThickAlloc<U, JunkPayloadSize>; - }; - - char Junk[JunkPayloadSize]{sizeof(T)}; - }; + + template <class T, size_t JunkPayloadSize> + struct TThickAlloc: public std::allocator<T> { + template <class U> + struct rebind { + using other = TThickAlloc<U, JunkPayloadSize>; + }; + + char Junk[JunkPayloadSize]{sizeof(T)}; + }; template <class T> struct TStatefulAlloc: public std::allocator<T> { @@ -126,12 +126,12 @@ Y_UNIT_TEST_SUITE(TStackBasedVectorTest) { } // Just verify that the program did not crash. } - - Y_UNIT_TEST(TestCustomAllocSize) { - constexpr size_t n = 16384; - using TVec = TStackVec<size_t, 1, true, TThickAlloc<size_t, n>>; - UNIT_ASSERT_LT(sizeof(TVec), 1.5 * n); - } + + Y_UNIT_TEST(TestCustomAllocSize) { + constexpr size_t n = 16384; + using TVec = TStackVec<size_t, 1, true, TThickAlloc<size_t, n>>; + UNIT_ASSERT_LT(sizeof(TVec), 1.5 * n); + } Y_UNIT_TEST(TestStatefulAlloc) { size_t count = 0; diff --git a/library/cpp/diff/diff.h b/library/cpp/diff/diff.h index 94fb00cd0b..1648b86643 100644 --- a/library/cpp/diff/diff.h +++ b/library/cpp/diff/diff.h @@ -2,7 +2,7 @@ #include <library/cpp/lcs/lcs_via_lis.h> -#include <util/generic/algorithm.h> +#include <util/generic/algorithm.h> #include <util/generic/array_ref.h> #include <util/generic/strbuf.h> #include <util/generic/vector.h> @@ -63,7 +63,7 @@ namespace NDiff { // Save the beginning of common part in s2 c2 = s2.begin() + ctx.ResultBuffer[i]; // Find the beginning of common part in s1 - c1 = Find(e1, s1.end(), *c2); + c1 = Find(e1, s1.end(), *c2); // Follow common substring for (e1 = c1, e2 = c2; i < n && *e1 == *e2; ++e1, ++e2) { ++i; diff --git a/library/cpp/getopt/small/last_getopt.h b/library/cpp/getopt/small/last_getopt.h index 07687bc914..5314861064 100644 --- a/library/cpp/getopt/small/last_getopt.h +++ b/library/cpp/getopt/small/last_getopt.h @@ -9,7 +9,7 @@ /// see some documentation in /// https://wiki.yandex-team.ru/development/poisk/arcadia/util/lastgetopt/ -/// https://wiki.yandex-team.ru/development/poisk/arcadia/library/getopt/ +/// https://wiki.yandex-team.ru/development/poisk/arcadia/library/getopt/ /// see examples in library/cpp/getopt/last_getopt_demo //TODO: in most cases this include is unnecessary, but needed THandlerFunctor1<TpFunc, TpArg>::HandleOpt diff --git a/library/cpp/getopt/small/last_getopt_opt.h b/library/cpp/getopt/small/last_getopt_opt.h index a8dd5adca9..f4d7c2cbad 100644 --- a/library/cpp/getopt/small/last_getopt_opt.h +++ b/library/cpp/getopt/small/last_getopt_opt.h @@ -604,12 +604,12 @@ namespace NLastGetopt { return StoreResultT<T>(target); } - // Uses TMaybe<T> to store FromString<T>(arg) - template <typename T> - TOpt& StoreResult(TMaybe<T>* target) { - return StoreResultT<T>(target); - } - + // Uses TMaybe<T> to store FromString<T>(arg) + template <typename T> + TOpt& StoreResult(TMaybe<T>* target) { + return StoreResultT<T>(target); + } + template <typename TpVal, typename T, typename TpDef> TOpt& StoreResultT(T* target, const TpDef& def) { return Handler1T<TpVal>(def, NPrivate::TStoreResultFunctor<T, TpVal>(target)); diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index c99a1d053d..b17fc90cd0 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -419,21 +419,21 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; TString data; int number; - TMaybe<TString> optionalString0, optionalString1; - TMaybe<int> optionalNumber0, optionalNumber1; + TMaybe<TString> optionalString0, optionalString1; + TMaybe<int> optionalNumber0, optionalNumber1; opts.AddLongOption('d', "data").StoreResult(&data); opts.AddLongOption('n', "number").StoreResult(&number); - opts.AddLongOption("optional-string-0").StoreResult(&optionalString0); - opts.AddLongOption("optional-number-0").StoreResult(&optionalNumber0); - opts.AddLongOption("optional-string-1").StoreResult(&optionalString1); - opts.AddLongOption("optional-number-1").StoreResult(&optionalNumber1); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--data=jjhh", "-n", "11", "--optional-number-1=8", "--optional-string-1=os1"})); + opts.AddLongOption("optional-string-0").StoreResult(&optionalString0); + opts.AddLongOption("optional-number-0").StoreResult(&optionalNumber0); + opts.AddLongOption("optional-string-1").StoreResult(&optionalString1); + opts.AddLongOption("optional-number-1").StoreResult(&optionalNumber1); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--data=jjhh", "-n", "11", "--optional-number-1=8", "--optional-string-1=os1"})); UNIT_ASSERT_VALUES_EQUAL("jjhh", data); UNIT_ASSERT_VALUES_EQUAL(11, number); - UNIT_ASSERT(!optionalString0.Defined()); - UNIT_ASSERT(!optionalNumber0.Defined()); - UNIT_ASSERT_VALUES_EQUAL(*optionalString1, "os1"); - UNIT_ASSERT_VALUES_EQUAL(*optionalNumber1, 8); + UNIT_ASSERT(!optionalString0.Defined()); + UNIT_ASSERT(!optionalNumber0.Defined()); + UNIT_ASSERT_VALUES_EQUAL(*optionalString1, "os1"); + UNIT_ASSERT_VALUES_EQUAL(*optionalNumber1, 8); } Y_UNIT_TEST(TestStoreValue) { diff --git a/library/cpp/iterator/ya.make b/library/cpp/iterator/ya.make index 1ba1ffb411..bc412ee74a 100644 --- a/library/cpp/iterator/ya.make +++ b/library/cpp/iterator/ya.make @@ -15,5 +15,5 @@ SRCS( ) END() - -RECURSE_FOR_TESTS(ut) + +RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/json/domscheme_traits.h b/library/cpp/json/domscheme_traits.h index a5a99cd8cf..f5961f2592 100644 --- a/library/cpp/json/domscheme_traits.h +++ b/library/cpp/json/domscheme_traits.h @@ -100,7 +100,7 @@ struct TJsonTraits { return &(*v)[key]; } - static inline size_t DictSize(TConstValueRef v) { + static inline size_t DictSize(TConstValueRef v) { return v->GetMap().size(); } diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index 02370c2d79..afc98b8a60 100644 --- a/library/cpp/json/writer/json.cpp +++ b/library/cpp/json/writer/json.cpp @@ -89,24 +89,24 @@ namespace NJsonWriter { const int indentation = IndentSpaces * (Stack.size() - 1); if (!indentation && !closing) return; - - PrintWhitespaces(Max(0, indentation), true); - } - - void TBuf::PrintWhitespaces(size_t count, bool prependWithNewLine) { - static constexpr TStringBuf whitespacesTemplate = "\n "; - static_assert(whitespacesTemplate[0] == '\n'); - static_assert(whitespacesTemplate[1] == ' '); - - count += (prependWithNewLine); - do { - const TStringBuf buffer = whitespacesTemplate.SubString(prependWithNewLine ? 0 : 1, count); - count -= buffer.size(); - UnsafeWriteRawBytes(buffer); - prependWithNewLine = false; // skip '\n' in subsequent writes - } while (count > 0); - } - + + PrintWhitespaces(Max(0, indentation), true); + } + + void TBuf::PrintWhitespaces(size_t count, bool prependWithNewLine) { + static constexpr TStringBuf whitespacesTemplate = "\n "; + static_assert(whitespacesTemplate[0] == '\n'); + static_assert(whitespacesTemplate[1] == ' '); + + count += (prependWithNewLine); + do { + const TStringBuf buffer = whitespacesTemplate.SubString(prependWithNewLine ? 0 : 1, count); + count -= buffer.size(); + UnsafeWriteRawBytes(buffer); + prependWithNewLine = false; // skip '\n' in subsequent writes + } while (count > 0); + } + inline void TBuf::WriteComma() { if (NeedComma) { RawWriteChar(','); diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h index 0aae2531b9..3849dc4ba4 100644 --- a/library/cpp/json/writer/json.h +++ b/library/cpp/json/writer/json.h @@ -133,7 +133,7 @@ namespace NJsonWriter { void WriteBareString(const TStringBuf s, EHtmlEscapeMode hem); void WriteComma(); void PrintIndentation(bool closing); - void PrintWhitespaces(size_t count, bool prependWithNewLine); + void PrintWhitespaces(size_t count, bool prependWithNewLine); void WriteHexEscape(unsigned char c); void StackPush(EJsonEntity e); diff --git a/library/cpp/lwtrace/all.h b/library/cpp/lwtrace/all.h index d7aa57c49d..27163051e0 100644 --- a/library/cpp/lwtrace/all.h +++ b/library/cpp/lwtrace/all.h @@ -7,7 +7,7 @@ #include "start.h" // -// Full documentation: https://wiki.yandex-team.ru/development/poisk/arcadia/library/lwtrace/ +// Full documentation: https://wiki.yandex-team.ru/development/poisk/arcadia/library/lwtrace/ // // Short usage instruction: // diff --git a/library/cpp/monlib/metrics/ut/ya.make b/library/cpp/monlib/metrics/ut/ya.make index aec9974fbd..26667a8eed 100644 --- a/library/cpp/monlib/metrics/ut/ya.make +++ b/library/cpp/monlib/metrics/ut/ya.make @@ -26,7 +26,7 @@ PEERDIR( library/cpp/resource library/cpp/monlib/encode/protobuf library/cpp/monlib/encode/json - library/cpp/threading/future + library/cpp/threading/future ) END() diff --git a/library/cpp/protobuf/util/pb_io.cpp b/library/cpp/protobuf/util/pb_io.cpp index 6270ee0624..58b4960f9c 100644 --- a/library/cpp/protobuf/util/pb_io.cpp +++ b/library/cpp/protobuf/util/pb_io.cpp @@ -69,16 +69,16 @@ namespace NProtoBuf { return result; } - bool MergePartialFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage) { - google::protobuf::io::CodedInputStream input(reinterpret_cast<const ui8*>(serializedProtoMessage.data()), serializedProtoMessage.size()); - bool ok = m.MergePartialFromCodedStream(&input); - ok = ok && input.ConsumedEntireMessage(); - return ok; - } - - bool MergeFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage) { - return MergePartialFromString(m, serializedProtoMessage) && m.IsInitialized(); - } + bool MergePartialFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage) { + google::protobuf::io::CodedInputStream input(reinterpret_cast<const ui8*>(serializedProtoMessage.data()), serializedProtoMessage.size()); + bool ok = m.MergePartialFromCodedStream(&input); + ok = ok && input.ConsumedEntireMessage(); + return ok; + } + + bool MergeFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage) { + return MergePartialFromString(m, serializedProtoMessage) && m.IsInitialized(); + } } int operator&(NProtoBuf::Message& m, IBinSaver& f) { diff --git a/library/cpp/protobuf/util/pb_io.h b/library/cpp/protobuf/util/pb_io.h index 493c84cb5f..aad964555b 100644 --- a/library/cpp/protobuf/util/pb_io.h +++ b/library/cpp/protobuf/util/pb_io.h @@ -37,9 +37,9 @@ namespace NProtoBuf { bool TrySerializeToBase64String(const Message& m, TString& dataBase64); const TString ShortUtf8DebugString(const Message& message); - - bool MergePartialFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage); - bool MergeFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage); + + bool MergePartialFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage); + bool MergeFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage); } int operator&(NProtoBuf::Message& m, IBinSaver& f); diff --git a/library/cpp/protobuf/util/pb_io_ut.cpp b/library/cpp/protobuf/util/pb_io_ut.cpp index 875d6dc602..2b93d64b5d 100644 --- a/library/cpp/protobuf/util/pb_io_ut.cpp +++ b/library/cpp/protobuf/util/pb_io_ut.cpp @@ -383,36 +383,36 @@ Y_UNIT_TEST_SUITE(TTestProtoBufIO) { UNIT_ASSERT(NProtoBuf::IsEqual(message, GetCorrectMessage())); } } - - Y_UNIT_TEST(TestMergeFromString) { - NProtobufUtilUt::TMergeTest message; - NProtobufUtilUt::TMergeTest messageFirstHalf; - NProtobufUtilUt::TMergeTest messageSecondHalf; - - for (ui32 v = ~0; v != 0; v >>= 1) { - message.AddMergeInt(v); - (v > 0xffff ? messageFirstHalf : messageSecondHalf).AddMergeInt(v); - } - - const TString full = message.SerializeAsString(); - - { - NProtobufUtilUt::TMergeTest m1; - UNIT_ASSERT(NProtoBuf::MergeFromString(m1, full)); - UNIT_ASSERT(NProtoBuf::IsEqual(message, m1)); - } - { - NProtobufUtilUt::TMergeTest m2; - TStringBuf s0 = TStringBuf(full).SubStr(0, 3); - TStringBuf s1 = TStringBuf(full).SubStr(3); - // объединение результатов двух MergePartialFromString не эквивалентно вызову MergePartialFromString от объединения строк - UNIT_ASSERT(!(NProtoBuf::MergePartialFromString(m2, s0) && NProtoBuf::MergePartialFromString(m2, s1))); - } - { - NProtobufUtilUt::TMergeTest m3; - UNIT_ASSERT(NProtoBuf::MergePartialFromString(m3, messageFirstHalf.SerializeAsString())); - UNIT_ASSERT(NProtoBuf::MergeFromString(m3, messageSecondHalf.SerializeAsString())); - UNIT_ASSERT(NProtoBuf::IsEqual(message, m3)); - } - } + + Y_UNIT_TEST(TestMergeFromString) { + NProtobufUtilUt::TMergeTest message; + NProtobufUtilUt::TMergeTest messageFirstHalf; + NProtobufUtilUt::TMergeTest messageSecondHalf; + + for (ui32 v = ~0; v != 0; v >>= 1) { + message.AddMergeInt(v); + (v > 0xffff ? messageFirstHalf : messageSecondHalf).AddMergeInt(v); + } + + const TString full = message.SerializeAsString(); + + { + NProtobufUtilUt::TMergeTest m1; + UNIT_ASSERT(NProtoBuf::MergeFromString(m1, full)); + UNIT_ASSERT(NProtoBuf::IsEqual(message, m1)); + } + { + NProtobufUtilUt::TMergeTest m2; + TStringBuf s0 = TStringBuf(full).SubStr(0, 3); + TStringBuf s1 = TStringBuf(full).SubStr(3); + // объединение результатов двух MergePartialFromString не эквивалентно вызову MergePartialFromString от объединения строк + UNIT_ASSERT(!(NProtoBuf::MergePartialFromString(m2, s0) && NProtoBuf::MergePartialFromString(m2, s1))); + } + { + NProtobufUtilUt::TMergeTest m3; + UNIT_ASSERT(NProtoBuf::MergePartialFromString(m3, messageFirstHalf.SerializeAsString())); + UNIT_ASSERT(NProtoBuf::MergeFromString(m3, messageSecondHalf.SerializeAsString())); + UNIT_ASSERT(NProtoBuf::IsEqual(message, m3)); + } + } } diff --git a/library/cpp/regex/pcre/regexp_ut.cpp b/library/cpp/regex/pcre/regexp_ut.cpp index 5184e801cc..900d9587d8 100644 --- a/library/cpp/regex/pcre/regexp_ut.cpp +++ b/library/cpp/regex/pcre/regexp_ut.cpp @@ -50,7 +50,7 @@ private: UNIT_TEST_SUITE(TRegexpTest); UNIT_TEST(TestRe) UNIT_TEST(TestSubst) - UNIT_TEST(TestOffEndOfBuffer); + UNIT_TEST(TestOffEndOfBuffer); UNIT_TEST_SUITE_END(); inline void TestRe() { @@ -91,13 +91,13 @@ private: UNIT_ASSERT_VALUES_EQUAL(copyResult, newResult); } } - - void TestOffEndOfBuffer() { - const TString needle{".*[^./]gov[.].*"}; - TRegExMatch re{needle, REG_UTF8}; - const TString haystack{"fakty.ictv.ua"}; - UNIT_ASSERT_VALUES_EQUAL(re.Match(haystack.c_str()), false); - } + + void TestOffEndOfBuffer() { + const TString needle{".*[^./]gov[.].*"}; + TRegExMatch re{needle, REG_UTF8}; + const TString haystack{"fakty.ictv.ua"}; + UNIT_ASSERT_VALUES_EQUAL(re.Match(haystack.c_str()), false); + } }; UNIT_TEST_SUITE_REGISTRATION(TRegexpTest); diff --git a/library/cpp/regex/pire/ut/regexp_ut.cpp b/library/cpp/regex/pire/ut/regexp_ut.cpp index e7206de9ad..b19c9a01f8 100644 --- a/library/cpp/regex/pire/ut/regexp_ut.cpp +++ b/library/cpp/regex/pire/ut/regexp_ut.cpp @@ -8,7 +8,7 @@ Y_UNIT_TEST_SUITE(TRegExp) { Y_UNIT_TEST(False) { UNIT_ASSERT(!TMatcher(TFsm::False()).Match("").Final()); - UNIT_ASSERT(!TMatcher(TFsm::False()).Match(TStringBuf{}).Final()); + UNIT_ASSERT(!TMatcher(TFsm::False()).Match(TStringBuf{}).Final()); } Y_UNIT_TEST(Surround) { diff --git a/library/cpp/resource/registry.cpp b/library/cpp/resource/registry.cpp index 66001c4769..c032fd4c05 100644 --- a/library/cpp/resource/registry.cpp +++ b/library/cpp/resource/registry.cpp @@ -21,7 +21,7 @@ namespace { typedef std::pair<TStringBuf, TStringBuf> TDescriptor; struct TStore: public IStore, public THashMap<TStringBuf, TDescriptor*> { - void Store(const TStringBuf key, const TStringBuf data) override { + void Store(const TStringBuf key, const TStringBuf data) override { if (contains(key)) { const TStringBuf value = (*this)[key]->second; if (value != data) { @@ -49,7 +49,7 @@ namespace { Y_VERIFY(size() == Count(), "size mismatch"); } - bool FindExact(const TStringBuf key, TString* out) const override { + bool FindExact(const TStringBuf key, TString* out) const override { if (TDescriptor* const* res = FindPtr(key)) { // temporary // https://st.yandex-team.ru/DEVTOOLS-3985 @@ -68,7 +68,7 @@ namespace { return false; } - void FindMatch(const TStringBuf subkey, IMatch& cb) const override { + void FindMatch(const TStringBuf subkey, IMatch& cb) const override { for (const auto& it : *this) { if (it.first.StartsWith(subkey)) { // temporary @@ -100,11 +100,11 @@ namespace { }; } -TString NResource::Compress(const TStringBuf data) { +TString NResource::Compress(const TStringBuf data) { return GetCodec()->Encode(data); } -TString NResource::Decompress(const TStringBuf data) { +TString NResource::Decompress(const TStringBuf data) { return GetCodec()->Decode(data); } diff --git a/library/cpp/resource/registry.h b/library/cpp/resource/registry.h index fe67702cbc..819966fa31 100644 --- a/library/cpp/resource/registry.h +++ b/library/cpp/resource/registry.h @@ -6,8 +6,8 @@ #include "resource.h" namespace NResource { - TString Compress(const TStringBuf data); - TString Decompress(const TStringBuf data); + TString Compress(const TStringBuf data); + TString Decompress(const TStringBuf data); class IMatch { public: @@ -16,9 +16,9 @@ namespace NResource { class IStore { public: - virtual void Store(const TStringBuf key, const TStringBuf data) = 0; - virtual bool FindExact(const TStringBuf key, TString* out) const = 0; - virtual void FindMatch(const TStringBuf subkey, IMatch& cb) const = 0; + virtual void Store(const TStringBuf key, const TStringBuf data) = 0; + virtual bool FindExact(const TStringBuf key, TString* out) const = 0; + virtual void FindMatch(const TStringBuf subkey, IMatch& cb) const = 0; virtual size_t Count() const noexcept = 0; virtual TStringBuf KeyByIndex(size_t idx) const = 0; virtual ~IStore() { @@ -28,7 +28,7 @@ namespace NResource { IStore* CommonStore(); struct TRegHelper { - inline TRegHelper(const TStringBuf key, const TStringBuf data) { + inline TRegHelper(const TStringBuf key, const TStringBuf data) { CommonStore()->Store(key, data); } }; diff --git a/library/cpp/resource/resource.cpp b/library/cpp/resource/resource.cpp index cc20f847a5..af686951b9 100644 --- a/library/cpp/resource/resource.cpp +++ b/library/cpp/resource/resource.cpp @@ -7,11 +7,11 @@ using namespace NResource; -bool NResource::FindExact(const TStringBuf key, TString* out) { +bool NResource::FindExact(const TStringBuf key, TString* out) { return CommonStore()->FindExact(key, out); } -void NResource::FindMatch(const TStringBuf subkey, TResources* out) { +void NResource::FindMatch(const TStringBuf subkey, TResources* out) { struct TMatch: public IMatch { inline TMatch(TResources* r) : R(r) @@ -30,7 +30,7 @@ void NResource::FindMatch(const TStringBuf subkey, TResources* out) { CommonStore()->FindMatch(subkey, m); } -TString NResource::Find(const TStringBuf key) { +TString NResource::Find(const TStringBuf key) { TString ret; if (FindExact(key, &ret)) { diff --git a/library/cpp/resource/resource.h b/library/cpp/resource/resource.h index 42dd0f1891..7da20bdba7 100644 --- a/library/cpp/resource/resource.h +++ b/library/cpp/resource/resource.h @@ -12,10 +12,10 @@ namespace NResource { typedef TVector<TResource> TResources; - TString Find(const TStringBuf key); - bool FindExact(const TStringBuf key, TString* out); + TString Find(const TStringBuf key); + bool FindExact(const TStringBuf key, TString* out); //perform full scan for now - void FindMatch(const TStringBuf subkey, TResources* out); + void FindMatch(const TStringBuf subkey, TResources* out); size_t Count() noexcept; TStringBuf KeyByIndex(size_t idx); TVector<TStringBuf> ListAllKeys(); diff --git a/library/cpp/testing/benchmark/bench.cpp b/library/cpp/testing/benchmark/bench.cpp index 08d8708005..a2245f20db 100644 --- a/library/cpp/testing/benchmark/bench.cpp +++ b/library/cpp/testing/benchmark/bench.cpp @@ -43,7 +43,7 @@ namespace { TMaybe<double> CyclesPerIteration; TMaybe<double> SecondsPerIteration; double RunTime; - size_t TestId; // Sequential test id (zero-based) + size_t TestId; // Sequential test id (zero-based) }; struct ITestRunner: public TIntrusiveListItem<ITestRunner> { @@ -52,7 +52,7 @@ namespace { virtual TStringBuf Name() const noexcept = 0; virtual TResult Run(const TOptions& opts) = 0; - size_t SequentialId = 0; + size_t SequentialId = 0; }; struct TCpuBenchmark: public ITestRunner { @@ -387,39 +387,39 @@ namespace { TVector<TResult> Results_; }; - class TOrderedReporter: public IReporter { - public: - TOrderedReporter(THolder<IReporter> slave) - : Slave_(std::move(slave)) - { - } - - void Report(TResult&& result) override { - with_lock (ResultsLock_) { - OrderedResultQueue_.emplace(result.TestId, std::move(result)); - while (!OrderedResultQueue_.empty() && OrderedResultQueue_.begin()->first <= ExpectedTestId_) { - Slave_->Report(std::move(OrderedResultQueue_.begin()->second)); - OrderedResultQueue_.erase(OrderedResultQueue_.begin()); - ++ExpectedTestId_; - } - } - } - - void Finish() override { - for (auto& it : OrderedResultQueue_) { - Slave_->Report(std::move(it.second)); - } - OrderedResultQueue_.clear(); - Slave_->Finish(); - } - - private: - THolder<IReporter> Slave_; - size_t ExpectedTestId_ = 0; - TMap<size_t, TResult> OrderedResultQueue_; - TAdaptiveLock ResultsLock_; - }; - + class TOrderedReporter: public IReporter { + public: + TOrderedReporter(THolder<IReporter> slave) + : Slave_(std::move(slave)) + { + } + + void Report(TResult&& result) override { + with_lock (ResultsLock_) { + OrderedResultQueue_.emplace(result.TestId, std::move(result)); + while (!OrderedResultQueue_.empty() && OrderedResultQueue_.begin()->first <= ExpectedTestId_) { + Slave_->Report(std::move(OrderedResultQueue_.begin()->second)); + OrderedResultQueue_.erase(OrderedResultQueue_.begin()); + ++ExpectedTestId_; + } + } + } + + void Finish() override { + for (auto& it : OrderedResultQueue_) { + Slave_->Report(std::move(it.second)); + } + OrderedResultQueue_.clear(); + Slave_->Finish(); + } + + private: + THolder<IReporter> Slave_; + size_t ExpectedTestId_ = 0; + TMap<size_t, TResult> OrderedResultQueue_; + TAdaptiveLock ResultsLock_; + }; + THolder<IReporter> MakeReporter(const EOutFormat type) { switch (type) { case F_CONSOLE: @@ -437,16 +437,16 @@ namespace { return MakeHolder<TConsoleReporter>(); // make compiler happy } - + THolder<IReporter> MakeOrderedReporter(const EOutFormat type) { - return MakeHolder<TOrderedReporter>(MakeReporter(type)); - } - + return MakeHolder<TOrderedReporter>(MakeReporter(type)); + } + void EnumerateTests(TVector<ITestRunner*>& tests) { - for (size_t id : xrange(tests.size())) { - tests[id]->SequentialId = id; - } - } + for (size_t id : xrange(tests.size())) { + tests[id]->SequentialId = id; + } + } } template <> @@ -560,7 +560,7 @@ int NBench::Main(int argc, char** argv) { tests.push_back(&it); } } - EnumerateTests(tests); + EnumerateTests(tests); if (opts.ListTests) { for (const auto* const it : tests) { @@ -581,7 +581,7 @@ int NBench::Main(int argc, char** argv) { } const TOptions testOpts = {timeBudget / tests.size()}; - const auto reporter = MakeOrderedReporter(opts.OutFormat); + const auto reporter = MakeOrderedReporter(opts.OutFormat); std::function<void(ITestRunner**)> func = [&](ITestRunner** it) { auto&& res = (*it)->Run(testOpts); diff --git a/library/cpp/threading/future/core/future-inl.h b/library/cpp/threading/future/core/future-inl.h index 5fd4296a93..109b94bf92 100644 --- a/library/cpp/threading/future/core/future-inl.h +++ b/library/cpp/threading/future/core/future-inl.h @@ -961,12 +961,12 @@ namespace NThreading { inline TFuture<T> MakeFuture() { struct TCache { TFuture<T> Instance{new NImpl::TFutureState<T>(Default<T>())}; - - TCache() { - // Immediately advance state from ValueSet to ValueRead. - // This should prevent corrupting shared value with an ExtractValue() call. - Y_UNUSED(Instance.GetValue()); - } + + TCache() { + // Immediately advance state from ValueSet to ValueRead. + // This should prevent corrupting shared value with an ExtractValue() call. + Y_UNUSED(Instance.GetValue()); + } }; return Singleton<TCache>()->Instance; } diff --git a/library/cpp/threading/future/future_ut.cpp b/library/cpp/threading/future/future_ut.cpp index 05950a568d..9ddca66b37 100644 --- a/library/cpp/threading/future/future_ut.cpp +++ b/library/cpp/threading/future/future_ut.cpp @@ -260,11 +260,11 @@ namespace { } - Y_UNIT_TEST(ShouldWaitExceptionOrAll) { + Y_UNIT_TEST(ShouldWaitExceptionOrAll) { TPromise<void> promise1 = NewPromise(); TPromise<void> promise2 = NewPromise(); - TFuture<void> future = WaitExceptionOrAll(promise1, promise2); + TFuture<void> future = WaitExceptionOrAll(promise1, promise2); UNIT_ASSERT(!future.HasValue()); promise1.SetValue(); @@ -274,7 +274,7 @@ namespace { UNIT_ASSERT(future.HasValue()); } - Y_UNIT_TEST(ShouldWaitExceptionOrAllVector) { + Y_UNIT_TEST(ShouldWaitExceptionOrAllVector) { TPromise<void> promise1 = NewPromise(); TPromise<void> promise2 = NewPromise(); @@ -282,7 +282,7 @@ namespace { promises.push_back(promise1); promises.push_back(promise2); - TFuture<void> future = WaitExceptionOrAll(promises); + TFuture<void> future = WaitExceptionOrAll(promises); UNIT_ASSERT(!future.HasValue()); promise1.SetValue(); @@ -292,7 +292,7 @@ namespace { UNIT_ASSERT(future.HasValue()); } - Y_UNIT_TEST(ShouldWaitExceptionOrAllVectorWithValueType) { + Y_UNIT_TEST(ShouldWaitExceptionOrAllVectorWithValueType) { TPromise<int> promise1 = NewPromise<int>(); TPromise<int> promise2 = NewPromise<int>(); @@ -300,7 +300,7 @@ namespace { promises.push_back(promise1); promises.push_back(promise2); - TFuture<void> future = WaitExceptionOrAll(promises); + TFuture<void> future = WaitExceptionOrAll(promises); UNIT_ASSERT(!future.HasValue()); promise1.SetValue(0); @@ -310,7 +310,7 @@ namespace { UNIT_ASSERT(future.HasValue()); } - Y_UNIT_TEST(ShouldWaitExceptionOrAllList) { + Y_UNIT_TEST(ShouldWaitExceptionOrAllList) { TPromise<void> promise1 = NewPromise(); TPromise<void> promise2 = NewPromise(); @@ -318,7 +318,7 @@ namespace { promises.push_back(promise1); promises.push_back(promise2); - TFuture<void> future = WaitExceptionOrAll(promises); + TFuture<void> future = WaitExceptionOrAll(promises); UNIT_ASSERT(!future.HasValue()); promise1.SetValue(); @@ -328,10 +328,10 @@ namespace { UNIT_ASSERT(future.HasValue()); } - Y_UNIT_TEST(ShouldWaitExceptionOrAllVectorEmpty) { + Y_UNIT_TEST(ShouldWaitExceptionOrAllVectorEmpty) { TVector<TFuture<void>> promises; - TFuture<void> future = WaitExceptionOrAll(promises); + TFuture<void> future = WaitExceptionOrAll(promises); UNIT_ASSERT(future.HasValue()); } @@ -480,21 +480,21 @@ namespace { UNIT_CHECK_GENERATED_EXCEPTION(promise.ExtractValue(), TFutureException); } - Y_UNIT_TEST(ShouldNotExtractFromSharedDefault) { - UNIT_CHECK_GENERATED_EXCEPTION(MakeFuture<int>().ExtractValue(), TFutureException); - - struct TStorage { - TString String = TString(100, 'a'); - }; - try { - TString s = MakeFuture<TStorage>().ExtractValue().String; - Y_UNUSED(s); - } catch (TFutureException) { - // pass - } - UNIT_ASSERT_VALUES_EQUAL(MakeFuture<TStorage>().GetValue().String, TString(100, 'a')); - } - + Y_UNIT_TEST(ShouldNotExtractFromSharedDefault) { + UNIT_CHECK_GENERATED_EXCEPTION(MakeFuture<int>().ExtractValue(), TFutureException); + + struct TStorage { + TString String = TString(100, 'a'); + }; + try { + TString s = MakeFuture<TStorage>().ExtractValue().String; + Y_UNUSED(s); + } catch (TFutureException) { + // pass + } + UNIT_ASSERT_VALUES_EQUAL(MakeFuture<TStorage>().GetValue().String, TString(100, 'a')); + } + Y_UNIT_TEST(HandlingRepetitiveSet) { TPromise<int> promise = NewPromise<int>(); promise.SetValue(42); @@ -541,7 +541,7 @@ namespace { Y_UNIT_TEST(WaitAllowsExtract) { auto future = MakeFuture<int>(42); TVector vec{future, future, future}; - WaitExceptionOrAll(vec).GetValue(); + WaitExceptionOrAll(vec).GetValue(); WaitAny(vec).GetValue(); UNIT_ASSERT_EQUAL(future.ExtractValue(), 42); @@ -553,30 +553,30 @@ namespace { UNIT_ASSERT_EQUAL(future.ExtractValue(), 42); } - - Y_UNIT_TEST(WaitExceptionOrAllException) { - auto promise1 = NewPromise(); - auto promise2 = NewPromise(); - auto future1 = promise1.GetFuture(); - auto future2 = promise2.GetFuture(); - auto wait = WaitExceptionOrAll(future1, future2); - promise2.SetException("foo-exception"); - wait.Wait(); - UNIT_ASSERT(future2.HasException()); - UNIT_ASSERT(!future1.HasValue() && !future1.HasException()); - } - - Y_UNIT_TEST(WaitAllException) { - auto promise1 = NewPromise(); - auto promise2 = NewPromise(); - auto future1 = promise1.GetFuture(); - auto future2 = promise2.GetFuture(); - auto wait = WaitAll(future1, future2); - promise2.SetException("foo-exception"); - UNIT_ASSERT(!wait.HasValue() && !wait.HasException()); - promise1.SetValue(); - UNIT_ASSERT_EXCEPTION_CONTAINS(wait.GetValueSync(), yexception, "foo-exception"); - } + + Y_UNIT_TEST(WaitExceptionOrAllException) { + auto promise1 = NewPromise(); + auto promise2 = NewPromise(); + auto future1 = promise1.GetFuture(); + auto future2 = promise2.GetFuture(); + auto wait = WaitExceptionOrAll(future1, future2); + promise2.SetException("foo-exception"); + wait.Wait(); + UNIT_ASSERT(future2.HasException()); + UNIT_ASSERT(!future1.HasValue() && !future1.HasException()); + } + + Y_UNIT_TEST(WaitAllException) { + auto promise1 = NewPromise(); + auto promise2 = NewPromise(); + auto future1 = promise1.GetFuture(); + auto future2 = promise2.GetFuture(); + auto wait = WaitAll(future1, future2); + promise2.SetException("foo-exception"); + UNIT_ASSERT(!wait.HasValue() && !wait.HasException()); + promise1.SetValue(); + UNIT_ASSERT_EXCEPTION_CONTAINS(wait.GetValueSync(), yexception, "foo-exception"); + } Y_UNIT_TEST(FutureStateId) { TestFutureStateId<void>(); diff --git a/library/cpp/threading/future/subscription/ya.make b/library/cpp/threading/future/subscription/ya.make index cb75731dbf..db969b2319 100644 --- a/library/cpp/threading/future/subscription/ya.make +++ b/library/cpp/threading/future/subscription/ya.make @@ -13,10 +13,10 @@ SRCS( wait_any.cpp ) -PEERDIR( - library/cpp/threading/future -) - +PEERDIR( + library/cpp/threading/future +) + END() RECURSE_FOR_TESTS( diff --git a/library/cpp/threading/future/wait/wait-inl.h b/library/cpp/threading/future/wait/wait-inl.h index 2753d5446c..a6f9c55a6d 100644 --- a/library/cpp/threading/future/wait/wait-inl.h +++ b/library/cpp/threading/future/wait/wait-inl.h @@ -13,17 +13,17 @@ namespace NThreading { for (const auto& future: futures) { voidFutures.push_back(future.IgnoreResult()); - } - + } + return voidFutures; } } - template <typename TContainer> + template <typename TContainer> [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitAll(const TContainer& futures) { return WaitAll(NImpl::ToVoidFutures(futures)); - } - + } + template <typename TContainer> [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitExceptionOrAll(const TContainer& futures) { return WaitExceptionOrAll(NImpl::ToVoidFutures(futures)); diff --git a/library/cpp/threading/future/wait/wait.cpp b/library/cpp/threading/future/wait/wait.cpp index a173833a7f..d719719978 100644 --- a/library/cpp/threading/future/wait/wait.cpp +++ b/library/cpp/threading/future/wait/wait.cpp @@ -23,11 +23,11 @@ namespace NThreading { TFuture<void> WaitGeneric(TArrayRef<const TFuture<void>> futures) { if (futures.empty()) { return MakeFuture(); - } + } if (futures.size() == 1) { return futures.front(); - } - + } + TWaitGroup<WaitPolicy> wg; for (const auto& fut : futures) { wg.Add(fut); @@ -41,19 +41,19 @@ namespace NThreading { TFuture<void> WaitAll(const TFuture<void>& f1) { return WaitGeneric<TWaitPolicy::TAll>(f1); - } - + } + TFuture<void> WaitAll(const TFuture<void>& f1, const TFuture<void>& f2) { return WaitGeneric<TWaitPolicy::TAll>(f1, f2); - } - + } + TFuture<void> WaitAll(TArrayRef<const TFuture<void>> futures) { return WaitGeneric<TWaitPolicy::TAll>(futures); - } - - - //////////////////////////////////////////////////////////////////////////////// - + } + + + //////////////////////////////////////////////////////////////////////////////// + TFuture<void> WaitExceptionOrAll(const TFuture<void>& f1) { return WaitGeneric<TWaitPolicy::TExceptionOrAll>(f1); } diff --git a/library/cpp/threading/future/wait/wait.h b/library/cpp/threading/future/wait/wait.h index 6ff7d57baa..f69924a3d6 100644 --- a/library/cpp/threading/future/wait/wait.h +++ b/library/cpp/threading/future/wait/wait.h @@ -14,16 +14,16 @@ namespace NThreading { !std::is_convertible_v<TContainer, TArrayRef<const TFuture<void>>>, TFuture<void>>; } - // waits for all futures - [[nodiscard]] TFuture<void> WaitAll(const TFuture<void>& f1); - [[nodiscard]] TFuture<void> WaitAll(const TFuture<void>& f1, const TFuture<void>& f2); + // waits for all futures + [[nodiscard]] TFuture<void> WaitAll(const TFuture<void>& f1); + [[nodiscard]] TFuture<void> WaitAll(const TFuture<void>& f1, const TFuture<void>& f2); [[nodiscard]] TFuture<void> WaitAll(TArrayRef<const TFuture<void>> futures); - template <typename TContainer> + template <typename TContainer> [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitAll(const TContainer& futures); - - // waits for the first exception or for all futures - [[nodiscard]] TFuture<void> WaitExceptionOrAll(const TFuture<void>& f1); - [[nodiscard]] TFuture<void> WaitExceptionOrAll(const TFuture<void>& f1, const TFuture<void>& f2); + + // waits for the first exception or for all futures + [[nodiscard]] TFuture<void> WaitExceptionOrAll(const TFuture<void>& f1); + [[nodiscard]] TFuture<void> WaitExceptionOrAll(const TFuture<void>& f1, const TFuture<void>& f2); [[nodiscard]] TFuture<void> WaitExceptionOrAll(TArrayRef<const TFuture<void>> futures); template <typename TContainer> [[nodiscard]] NImpl::EnableGenericWait<TContainer> WaitExceptionOrAll(const TContainer& futures); diff --git a/library/cpp/threading/local_executor/ya.make b/library/cpp/threading/local_executor/ya.make index df210f92bb..e192634b94 100644 --- a/library/cpp/threading/local_executor/ya.make +++ b/library/cpp/threading/local_executor/ya.make @@ -14,7 +14,7 @@ SRCS( PEERDIR( contrib/libs/tbb - library/cpp/threading/future + library/cpp/threading/future ) END() diff --git a/library/python/runtime_py3/__res.pyx b/library/python/runtime_py3/__res.pyx index 97190d9f29..e59e1a0590 100644 --- a/library/python/runtime_py3/__res.pyx +++ b/library/python/runtime_py3/__res.pyx @@ -8,7 +8,7 @@ from util.generic.string cimport TString, TStringBuf cdef extern from "library/cpp/resource/resource.h" namespace "NResource": cdef size_t Count() except + cdef TStringBuf KeyByIndex(size_t idx) except + - cdef bool FindExact(const TStringBuf key, TString* result) nogil except + + cdef bool FindExact(const TStringBuf key, TString* result) nogil except + def count(): diff --git a/tools/enum_parser/enum_parser/main.cpp b/tools/enum_parser/enum_parser/main.cpp index 0943c69c1d..66bf6c88c2 100644 --- a/tools/enum_parser/enum_parser/main.cpp +++ b/tools/enum_parser/enum_parser/main.cpp @@ -10,10 +10,10 @@ #include <util/stream/mem.h> #include <util/charset/wide.h> -#include <util/string/builder.h> +#include <util/string/builder.h> #include <util/string/strip.h> #include <util/string/cast.h> -#include <util/string/join.h> +#include <util/string/join.h> #include <util/string/subst.h> #include <util/generic/map.h> #include <util/generic/string.h> @@ -27,7 +27,7 @@ void WriteHeader(const TString& headerName, IOutputStream& out, IOutputStream* headerOutPtr = nullptr) { out << "// This file was auto-generated. Do not edit!!!\n"; out << "#include " << headerName << "\n"; - out << "#include <tools/enum_parser/enum_serialization_runtime/enum_runtime.h>\n\n"; + out << "#include <tools/enum_parser/enum_serialization_runtime/enum_runtime.h>\n\n"; out << "#include <tools/enum_parser/enum_parser/stdlib_deps.h>\n\n"; out << "#include <util/generic/typetraits.h>\n"; out << "#include <util/generic/singleton.h>\n"; @@ -128,10 +128,10 @@ static inline void CloseArray(TStringStream& out) { out << "]\n"; } -static TString WrapStringBuf(const TStringBuf str) { +static TString WrapStringBuf(const TStringBuf str) { return TString::Join("TStringBuf(\"", str, "\")"); -} - +} + void GenerateEnum( const TEnumParser::TEnum& en, IOutputStream& out, @@ -197,18 +197,18 @@ void GenerateEnum( strValue = it.Aliases[0]; OutKey(jEnumItem, "str_value", strValue); } - nameInitializerPairs.push_back("TNameBufs::EnumStringPair(" + outerScopeStr + it.CppName + ", " + WrapStringBuf(strValue) + ")"); - cppNamesInitializer.push_back(WrapStringBuf(it.CppName)); + nameInitializerPairs.push_back("TNameBufs::EnumStringPair(" + outerScopeStr + it.CppName + ", " + WrapStringBuf(strValue) + ")"); + cppNamesInitializer.push_back(WrapStringBuf(it.CppName)); for (const auto& alias : it.Aliases) { - valueInitializerPairs.push_back("TNameBufs::EnumStringPair(" + outerScopeStr + it.CppName + ", " + WrapStringBuf(alias) + ")"); + valueInitializerPairs.push_back("TNameBufs::EnumStringPair(" + outerScopeStr + it.CppName + ", " + WrapStringBuf(alias) + ")"); OutItem(jAliases, alias); } FinishItems(jAliases); CloseArray(jAliases); if (!it.Aliases) { - valueInitializerPairs.push_back("TNameBufs::EnumStringPair(" + outerScopeStr + it.CppName + ", " + WrapStringBuf(it.CppName) + ")"); + valueInitializerPairs.push_back("TNameBufs::EnumStringPair(" + outerScopeStr + it.CppName + ", " + WrapStringBuf(it.CppName) + ")"); } OutKey(jEnumItem, "aliases", jAliases.Str(), false); @@ -221,83 +221,83 @@ void GenerateEnum( CloseArray(jItems); OutKey(jEnum, "items", jItems.Str(), false); - auto defineConstArray = [&out, payloadCache = TMap<std::pair<TString, TVector<TString>>, TString>()](const TStringBuf indent, const TStringBuf elementType, const TStringBuf name, const TVector<TString>& items) mutable { - if (items.empty()) { // ISO C++ forbids zero-size array - out << indent << "static constexpr const TArrayRef<const " << elementType << "> " << name << ";\n"; - } else { - // try to reuse one of the previous payload arrays - const auto inserted = payloadCache.emplace(std::make_pair(elementType, items), ToString(name) + "_PAYLOAD"); - const TString& payloadStorageName = inserted.first->second; - if (inserted.second) { // new array content or type - out << indent << "static constexpr const " << elementType << " " << payloadStorageName << "[" << items.size() << "]{\n"; - for (const auto& it : items) { - out << indent << " " << it << ",\n"; - } - out << indent << "};\n"; - } - out << indent << "static constexpr const TArrayRef<const " << elementType << "> " << name << "{" << payloadStorageName << "};\n"; - } - out << "\n"; - }; - - out << " class TNameBufs : public ::NEnumSerializationRuntime::TEnumDescription<" << name << "> {\n"; - out << " public:\n"; - out << " using TBase = ::NEnumSerializationRuntime::TEnumDescription<" << name << ">;\n\n"; - out << " inline TNameBufs();\n\n"; - - // Instance - out << " static inline const TNameBufs& Instance() {\n"; + auto defineConstArray = [&out, payloadCache = TMap<std::pair<TString, TVector<TString>>, TString>()](const TStringBuf indent, const TStringBuf elementType, const TStringBuf name, const TVector<TString>& items) mutable { + if (items.empty()) { // ISO C++ forbids zero-size array + out << indent << "static constexpr const TArrayRef<const " << elementType << "> " << name << ";\n"; + } else { + // try to reuse one of the previous payload arrays + const auto inserted = payloadCache.emplace(std::make_pair(elementType, items), ToString(name) + "_PAYLOAD"); + const TString& payloadStorageName = inserted.first->second; + if (inserted.second) { // new array content or type + out << indent << "static constexpr const " << elementType << " " << payloadStorageName << "[" << items.size() << "]{\n"; + for (const auto& it : items) { + out << indent << " " << it << ",\n"; + } + out << indent << "};\n"; + } + out << indent << "static constexpr const TArrayRef<const " << elementType << "> " << name << "{" << payloadStorageName << "};\n"; + } + out << "\n"; + }; + + out << " class TNameBufs : public ::NEnumSerializationRuntime::TEnumDescription<" << name << "> {\n"; + out << " public:\n"; + out << " using TBase = ::NEnumSerializationRuntime::TEnumDescription<" << name << ">;\n\n"; + out << " inline TNameBufs();\n\n"; + + // Instance + out << " static inline const TNameBufs& Instance() {\n"; out << " return *SingletonWithPriority<TNameBufs, 0>();\n"; // destroy enum serializers last, because it may be used from destructor of another global object - out << " }\n"; - out << " };\n\n"; - - // Initialization data - defineConstArray(" ", "TNameBufs::TBase::TEnumStringPair", "NAMES_INITIALIZATION_PAIRS", nameInitializerPairs); - defineConstArray(" ", "TNameBufs::TBase::TEnumStringPair", "VALUES_INITIALIZATION_PAIRS", valueInitializerPairs); - defineConstArray(" ", "TStringBuf", "CPP_NAMES_INITIALIZATION_ARRAY", cppNamesInitializer); - - out << " static constexpr const TNameBufs::TInitializationData ENUM_INITIALIZATION_DATA{\n"; - out << " NAMES_INITIALIZATION_PAIRS,\n"; - out << " VALUES_INITIALIZATION_PAIRS,\n"; - out << " CPP_NAMES_INITIALIZATION_ARRAY,\n"; - out << " " << WrapStringBuf(outerScopeStr) << ",\n"; - out << " " << WrapStringBuf(name) << "\n"; - out << " };\n\n"; - - // Constructor - out << " inline TNameBufs::TNameBufs()\n"; - out << " : TBase(ENUM_INITIALIZATION_DATA)\n"; - out << " {\n"; - out << " }\n\n"; + out << " }\n"; + out << " };\n\n"; + + // Initialization data + defineConstArray(" ", "TNameBufs::TBase::TEnumStringPair", "NAMES_INITIALIZATION_PAIRS", nameInitializerPairs); + defineConstArray(" ", "TNameBufs::TBase::TEnumStringPair", "VALUES_INITIALIZATION_PAIRS", valueInitializerPairs); + defineConstArray(" ", "TStringBuf", "CPP_NAMES_INITIALIZATION_ARRAY", cppNamesInitializer); + + out << " static constexpr const TNameBufs::TInitializationData ENUM_INITIALIZATION_DATA{\n"; + out << " NAMES_INITIALIZATION_PAIRS,\n"; + out << " VALUES_INITIALIZATION_PAIRS,\n"; + out << " CPP_NAMES_INITIALIZATION_ARRAY,\n"; + out << " " << WrapStringBuf(outerScopeStr) << ",\n"; + out << " " << WrapStringBuf(name) << "\n"; + out << " };\n\n"; + + // Constructor + out << " inline TNameBufs::TNameBufs()\n"; + out << " : TBase(ENUM_INITIALIZATION_DATA)\n"; + out << " {\n"; + out << " }\n\n"; out << "}}\n\n"; - if (headerOutPtr) { - (*headerOutPtr) << "// I/O for " << name << "\n"; - } - + if (headerOutPtr) { + (*headerOutPtr) << "// I/O for " << name << "\n"; + } + // outer ToString - if (headerOutPtr) { - (*headerOutPtr) << "const TString& ToString(" << name << ");\n"; - } + if (headerOutPtr) { + (*headerOutPtr) << "const TString& ToString(" << name << ");\n"; + } out << "const TString& ToString(" << name << " x) {\n"; out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; out << " return names.ToString(x);\n"; out << "}\n\n"; // outer FromString - if (headerOutPtr) { - (*headerOutPtr) << "bool FromString(const TString& name, " << name << "& ret);\n"; - } + if (headerOutPtr) { + (*headerOutPtr) << "bool FromString(const TString& name, " << name << "& ret);\n"; + } out << "bool FromString(const TString& name, " << name << "& ret) {\n"; out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; out << " return names.FromString(name, ret);\n"; out << "}\n\n"; // outer FromString - if (headerOutPtr) { - (*headerOutPtr) << "bool FromString(const TStringBuf& name, " << name << "& ret);\n"; - } + if (headerOutPtr) { + (*headerOutPtr) << "bool FromString(const TStringBuf& name, " << name << "& ret);\n"; + } out << "bool FromString(const TStringBuf& name, " << name << "& ret) {\n"; out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; out << " return names.FromString(name, ret);\n"; @@ -319,40 +319,40 @@ void GenerateEnum( // outer Out out << "template<>\n"; out << "void Out<" << name << ">(IOutputStream& os, TTypeTraits<" << name << ">::TFuncParam n) {\n"; - out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; - out << " return names.Out(&os, n);\n"; + out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; + out << " return names.Out(&os, n);\n"; out << "}\n\n"; - // specializations for NEnumSerializationRuntime function family - out << "namespace NEnumSerializationRuntime {\n"; - // template<> GetEnumAllValues - out << " template<>\n"; - out << " TMappedArrayView<" << name <<"> GetEnumAllValuesImpl<" << name << ">() {\n"; - out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; - out << " return names.AllEnumValues();\n"; - out << " }\n\n"; - - // template<> GetEnumAllNames - out << " template<>\n"; - out << " const TString& GetEnumAllNamesImpl<" << name << ">() {\n"; - out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; - out << " return names.AllEnumNames();\n"; - out << " }\n\n"; + // specializations for NEnumSerializationRuntime function family + out << "namespace NEnumSerializationRuntime {\n"; + // template<> GetEnumAllValues + out << " template<>\n"; + out << " TMappedArrayView<" << name <<"> GetEnumAllValuesImpl<" << name << ">() {\n"; + out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; + out << " return names.AllEnumValues();\n"; + out << " }\n\n"; + + // template<> GetEnumAllNames + out << " template<>\n"; + out << " const TString& GetEnumAllNamesImpl<" << name << ">() {\n"; + out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; + out << " return names.AllEnumNames();\n"; + out << " }\n\n"; // template<> GetEnumNames<EnumType> - out << " template<>\n"; - out << " TMappedDictView<" << name << ", TString> GetEnumNamesImpl<" << name << ">() {\n"; - out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; - out << " return names.EnumNames();\n"; - out << " }\n\n"; - - // template<> GetEnumAllCppNames, see IGNIETFERRO-534 - out << " template<>\n"; - out << " const TVector<TString>& GetEnumAllCppNamesImpl<" << name << ">() {\n"; - out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; - out << " return names.AllEnumCppNames();\n"; - out << " }\n"; - + out << " template<>\n"; + out << " TMappedDictView<" << name << ", TString> GetEnumNamesImpl<" << name << ">() {\n"; + out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; + out << " return names.EnumNames();\n"; + out << " }\n\n"; + + // template<> GetEnumAllCppNames, see IGNIETFERRO-534 + out << " template<>\n"; + out << " const TVector<TString>& GetEnumAllCppNamesImpl<" << name << ">() {\n"; + out << " const " << nsName << "::TNameBufs& names = " << nsName << "::TNameBufs::Instance();\n"; + out << " return names.AllEnumCppNames();\n"; + out << " }\n"; + out << "}\n\n"; if (headerOutPtr) { diff --git a/tools/enum_parser/enum_serialization_runtime/README.md b/tools/enum_parser/enum_serialization_runtime/README.md index 7d2cbae4ce..0f87800b00 100644 --- a/tools/enum_parser/enum_serialization_runtime/README.md +++ b/tools/enum_parser/enum_serialization_runtime/README.md @@ -1,2 +1,2 @@ -This library should not be used or referred directly. -Use `GENERATE_ENUM_SERIALIZATION_WITH_HEADER` and `GENERATE_ENUM_SERIALIZATION` macros instead. +This library should not be used or referred directly. +Use `GENERATE_ENUM_SERIALIZATION_WITH_HEADER` and `GENERATE_ENUM_SERIALIZATION` macros instead. diff --git a/tools/enum_parser/enum_serialization_runtime/enum_runtime.cpp b/tools/enum_parser/enum_serialization_runtime/enum_runtime.cpp index 73d38b396a..80a38fab91 100644 --- a/tools/enum_parser/enum_serialization_runtime/enum_runtime.cpp +++ b/tools/enum_parser/enum_serialization_runtime/enum_runtime.cpp @@ -1,100 +1,100 @@ -#include "enum_runtime.h" - -#include <util/generic/map.h> -#include <util/generic/yexception.h> -#include <util/stream/output.h> - -namespace NEnumSerializationRuntime { - template <typename TEnumRepresentationType> - [[noreturn]] static void ThrowUndefinedValueException(const TEnumRepresentationType key, const TStringBuf className) { - throw yexception() << "Undefined value " << key << " in " << className << ". "; - } - - template <typename TEnumRepresentationType> - const TString& TEnumDescriptionBase<TEnumRepresentationType>::ToString(TRepresentationType key) const { - const auto it = Names.find(key); - if (Y_LIKELY(it != Names.end())) { - return it->second; - } - ThrowUndefinedValueException(key, ClassName); - } - - template <typename TEnumRepresentationType> - std::pair<bool, TEnumRepresentationType> TEnumDescriptionBase<TEnumRepresentationType>::TryFromString(const TStringBuf name) const { - const auto it = Values.find(name); - if (it != Values.end()) { - return {true, it->second}; - } - return {false, TRepresentationType()}; - } - - [[noreturn]] static void ThrowUndefinedNameException(const TStringBuf name, const TStringBuf className, const TStringBuf allEnumNames) { - ythrow yexception() << "Key '" << name << "' not found in enum " << className << ". Valid options are: " << allEnumNames << ". "; - } - - template <typename TEnumRepresentationType> - auto TEnumDescriptionBase<TEnumRepresentationType>::FromString(const TStringBuf name) const -> TRepresentationType { - const auto findResult = TryFromString(name); - if (Y_LIKELY(findResult.first)) { - return findResult.second; - } - ThrowUndefinedNameException(name, ClassName, AllEnumNames()); - } - - template <typename TEnumRepresentationType> - void TEnumDescriptionBase<TEnumRepresentationType>::Out(IOutputStream* os, const TRepresentationType key) const { - (*os) << this->ToString(key); - } - - template <typename TEnumRepresentationType> - TEnumDescriptionBase<TEnumRepresentationType>::TEnumDescriptionBase(const TInitializationData& enumInitData) - : ClassName(enumInitData.ClassName) - { - const TArrayRef<const TEnumStringPair>& namesInitializer = enumInitData.NamesInitializer; - const TArrayRef<const TEnumStringPair>& valuesInitializer = enumInitData.ValuesInitializer; - const TArrayRef<const TStringBuf>& cppNamesInitializer = enumInitData.CppNamesInitializer; - - TMap<TRepresentationType, TString> mapValueToName; - TMap<TString, TRepresentationType> mapNameToValue; +#include "enum_runtime.h" + +#include <util/generic/map.h> +#include <util/generic/yexception.h> +#include <util/stream/output.h> + +namespace NEnumSerializationRuntime { + template <typename TEnumRepresentationType> + [[noreturn]] static void ThrowUndefinedValueException(const TEnumRepresentationType key, const TStringBuf className) { + throw yexception() << "Undefined value " << key << " in " << className << ". "; + } + + template <typename TEnumRepresentationType> + const TString& TEnumDescriptionBase<TEnumRepresentationType>::ToString(TRepresentationType key) const { + const auto it = Names.find(key); + if (Y_LIKELY(it != Names.end())) { + return it->second; + } + ThrowUndefinedValueException(key, ClassName); + } + + template <typename TEnumRepresentationType> + std::pair<bool, TEnumRepresentationType> TEnumDescriptionBase<TEnumRepresentationType>::TryFromString(const TStringBuf name) const { + const auto it = Values.find(name); + if (it != Values.end()) { + return {true, it->second}; + } + return {false, TRepresentationType()}; + } + + [[noreturn]] static void ThrowUndefinedNameException(const TStringBuf name, const TStringBuf className, const TStringBuf allEnumNames) { + ythrow yexception() << "Key '" << name << "' not found in enum " << className << ". Valid options are: " << allEnumNames << ". "; + } + + template <typename TEnumRepresentationType> + auto TEnumDescriptionBase<TEnumRepresentationType>::FromString(const TStringBuf name) const -> TRepresentationType { + const auto findResult = TryFromString(name); + if (Y_LIKELY(findResult.first)) { + return findResult.second; + } + ThrowUndefinedNameException(name, ClassName, AllEnumNames()); + } + + template <typename TEnumRepresentationType> + void TEnumDescriptionBase<TEnumRepresentationType>::Out(IOutputStream* os, const TRepresentationType key) const { + (*os) << this->ToString(key); + } + + template <typename TEnumRepresentationType> + TEnumDescriptionBase<TEnumRepresentationType>::TEnumDescriptionBase(const TInitializationData& enumInitData) + : ClassName(enumInitData.ClassName) + { + const TArrayRef<const TEnumStringPair>& namesInitializer = enumInitData.NamesInitializer; + const TArrayRef<const TEnumStringPair>& valuesInitializer = enumInitData.ValuesInitializer; + const TArrayRef<const TStringBuf>& cppNamesInitializer = enumInitData.CppNamesInitializer; + + TMap<TRepresentationType, TString> mapValueToName; + TMap<TString, TRepresentationType> mapNameToValue; const bool bijectiveHint = (namesInitializer.data() == valuesInitializer.data() && namesInitializer.size() == valuesInitializer.size()); - if (bijectiveHint) { - for (const TEnumStringPair& it : namesInitializer) { - TString name{it.Name}; - mapValueToName.emplace(it.Key, name); - mapNameToValue.emplace(std::move(name), it.Key); - } - } else { - for (const TEnumStringPair& it : namesInitializer) { + if (bijectiveHint) { + for (const TEnumStringPair& it : namesInitializer) { + TString name{it.Name}; + mapValueToName.emplace(it.Key, name); + mapNameToValue.emplace(std::move(name), it.Key); + } + } else { + for (const TEnumStringPair& it : namesInitializer) { mapValueToName.emplace(it.Key, TString(it.Name)); - } - for (const TEnumStringPair& it : valuesInitializer) { + } + for (const TEnumStringPair& it : valuesInitializer) { mapNameToValue.emplace(TString(it.Name), it.Key); - } - } - Names = std::move(mapValueToName); - Values = std::move(mapNameToValue); - - AllValues.reserve(Names.size()); - for (const auto& it : Names) { + } + } + Names = std::move(mapValueToName); + Values = std::move(mapNameToValue); + + AllValues.reserve(Names.size()); + for (const auto& it : Names) { if (!AllNames.empty()) { - AllNames += ", "; - } - AllNames += TString::Join('\'', it.second, '\''); - AllValues.push_back(it.first); - } - - AllCppNames.reserve(cppNamesInitializer.size()); - for (const auto& cn : cppNamesInitializer) { - AllCppNames.push_back(TString::Join(enumInitData.CppNamesPrefix, cn)); - } - } - - template <typename TEnumRepresentationType> - TEnumDescriptionBase<TEnumRepresentationType>::~TEnumDescriptionBase() = default; - - // explicit instantiation - template class TEnumDescriptionBase<int>; - template class TEnumDescriptionBase<unsigned>; - template class TEnumDescriptionBase<long long>; - template class TEnumDescriptionBase<unsigned long long>; -} + AllNames += ", "; + } + AllNames += TString::Join('\'', it.second, '\''); + AllValues.push_back(it.first); + } + + AllCppNames.reserve(cppNamesInitializer.size()); + for (const auto& cn : cppNamesInitializer) { + AllCppNames.push_back(TString::Join(enumInitData.CppNamesPrefix, cn)); + } + } + + template <typename TEnumRepresentationType> + TEnumDescriptionBase<TEnumRepresentationType>::~TEnumDescriptionBase() = default; + + // explicit instantiation + template class TEnumDescriptionBase<int>; + template class TEnumDescriptionBase<unsigned>; + template class TEnumDescriptionBase<long long>; + template class TEnumDescriptionBase<unsigned long long>; +} diff --git a/tools/enum_parser/enum_serialization_runtime/enum_runtime.h b/tools/enum_parser/enum_serialization_runtime/enum_runtime.h index f157d43109..905406a9d1 100644 --- a/tools/enum_parser/enum_serialization_runtime/enum_runtime.h +++ b/tools/enum_parser/enum_serialization_runtime/enum_runtime.h @@ -1,116 +1,116 @@ -#pragma once - -#include <util/generic/array_ref.h> -#include <util/generic/strbuf.h> -#include <util/generic/string.h> -#include <util/generic/vector.h> -#include <util/generic/serialized_enum.h> - -#include <utility> - -class IOutputStream; - -namespace NEnumSerializationRuntime { - /// Stores all information about enumeration except its real type - template <typename TEnumRepresentationType> - class TEnumDescriptionBase { - public: - using TRepresentationType = TEnumRepresentationType; - - struct TEnumStringPair { - const TRepresentationType Key; - const TStringBuf Name; - }; - - /// Refers initialization data stored in constexpr-friendly format - struct TInitializationData { - const TArrayRef<const TEnumStringPair> NamesInitializer; - const TArrayRef<const TEnumStringPair> ValuesInitializer; - const TArrayRef<const TStringBuf> CppNamesInitializer; - const TStringBuf CppNamesPrefix; - const TStringBuf ClassName; - }; - - public: - TEnumDescriptionBase(const TInitializationData& enumInitData); - ~TEnumDescriptionBase(); - - const TString& ToString(TRepresentationType key) const; - std::pair<bool, TRepresentationType> TryFromString(const TStringBuf name) const; - TRepresentationType FromString(const TStringBuf name) const; - void Out(IOutputStream* os, const TRepresentationType key) const; - - const TString& AllEnumNames() const noexcept { - return AllNames; - } - - const TVector<TString>& AllEnumCppNames() const noexcept { - return AllCppNames; - } - - const TMap<TRepresentationType, TString>& TypelessEnumNames() const noexcept { - return Names; - } - - const TVector<TRepresentationType>& TypelessEnumValues() const noexcept { - return AllValues; - } - - private: - TMap<TRepresentationType, TString> Names; - TMap<TString, TRepresentationType> Values; - TString AllNames; - TVector<TString> AllCppNames; - TString ClassName; - TVector<TRepresentationType> AllValues; - }; - - /// Wraps TEnumDescriptionBase and performs on-demand casts - template <typename EEnum, typename TEnumRepresentationType = typename NDetail::TSelectEnumRepresentationType<EEnum>::TType> - class TEnumDescription: public NDetail::TMappedViewBase<EEnum, TEnumRepresentationType>, private TEnumDescriptionBase<TEnumRepresentationType> { - public: - using TBase = TEnumDescriptionBase<TEnumRepresentationType>; - using TCast = NDetail::TMappedViewBase<EEnum, TEnumRepresentationType>; - using TBase::AllEnumCppNames; - using TBase::AllEnumNames; - using typename TBase::TEnumStringPair; - using typename TBase::TRepresentationType; - using typename TBase::TInitializationData; - - public: - using TBase::TBase; - - const TString& ToString(const EEnum key) const { - return TBase::ToString(TCast::CastToRepresentationType(key)); - } - - bool FromString(const TStringBuf name, EEnum& ret) const { - const auto findResult = TBase::TryFromString(name); - if (findResult.first) { - ret = TCast::CastFromRepresentationType(findResult.second); - return true; - } - return false; - } - - EEnum FromString(const TStringBuf name) const { - return TCast::CastFromRepresentationType(TBase::FromString(name)); - } - - TMappedDictView<EEnum, TString> EnumNames() const noexcept { - return {TBase::TypelessEnumNames()}; - } - - TMappedArrayView<EEnum> AllEnumValues() const noexcept { - return {TBase::TypelessEnumValues()}; - } - - void Out(IOutputStream* os, const EEnum key) const { - TBase::Out(os, TCast::CastToRepresentationType(key)); - } - - static constexpr TEnumStringPair EnumStringPair(const EEnum key, const TStringBuf name) noexcept { - return {TCast::CastToRepresentationType(key), name}; - } - }; -} +#pragma once + +#include <util/generic/array_ref.h> +#include <util/generic/strbuf.h> +#include <util/generic/string.h> +#include <util/generic/vector.h> +#include <util/generic/serialized_enum.h> + +#include <utility> + +class IOutputStream; + +namespace NEnumSerializationRuntime { + /// Stores all information about enumeration except its real type + template <typename TEnumRepresentationType> + class TEnumDescriptionBase { + public: + using TRepresentationType = TEnumRepresentationType; + + struct TEnumStringPair { + const TRepresentationType Key; + const TStringBuf Name; + }; + + /// Refers initialization data stored in constexpr-friendly format + struct TInitializationData { + const TArrayRef<const TEnumStringPair> NamesInitializer; + const TArrayRef<const TEnumStringPair> ValuesInitializer; + const TArrayRef<const TStringBuf> CppNamesInitializer; + const TStringBuf CppNamesPrefix; + const TStringBuf ClassName; + }; + + public: + TEnumDescriptionBase(const TInitializationData& enumInitData); + ~TEnumDescriptionBase(); + + const TString& ToString(TRepresentationType key) const; + std::pair<bool, TRepresentationType> TryFromString(const TStringBuf name) const; + TRepresentationType FromString(const TStringBuf name) const; + void Out(IOutputStream* os, const TRepresentationType key) const; + + const TString& AllEnumNames() const noexcept { + return AllNames; + } + + const TVector<TString>& AllEnumCppNames() const noexcept { + return AllCppNames; + } + + const TMap<TRepresentationType, TString>& TypelessEnumNames() const noexcept { + return Names; + } + + const TVector<TRepresentationType>& TypelessEnumValues() const noexcept { + return AllValues; + } + + private: + TMap<TRepresentationType, TString> Names; + TMap<TString, TRepresentationType> Values; + TString AllNames; + TVector<TString> AllCppNames; + TString ClassName; + TVector<TRepresentationType> AllValues; + }; + + /// Wraps TEnumDescriptionBase and performs on-demand casts + template <typename EEnum, typename TEnumRepresentationType = typename NDetail::TSelectEnumRepresentationType<EEnum>::TType> + class TEnumDescription: public NDetail::TMappedViewBase<EEnum, TEnumRepresentationType>, private TEnumDescriptionBase<TEnumRepresentationType> { + public: + using TBase = TEnumDescriptionBase<TEnumRepresentationType>; + using TCast = NDetail::TMappedViewBase<EEnum, TEnumRepresentationType>; + using TBase::AllEnumCppNames; + using TBase::AllEnumNames; + using typename TBase::TEnumStringPair; + using typename TBase::TRepresentationType; + using typename TBase::TInitializationData; + + public: + using TBase::TBase; + + const TString& ToString(const EEnum key) const { + return TBase::ToString(TCast::CastToRepresentationType(key)); + } + + bool FromString(const TStringBuf name, EEnum& ret) const { + const auto findResult = TBase::TryFromString(name); + if (findResult.first) { + ret = TCast::CastFromRepresentationType(findResult.second); + return true; + } + return false; + } + + EEnum FromString(const TStringBuf name) const { + return TCast::CastFromRepresentationType(TBase::FromString(name)); + } + + TMappedDictView<EEnum, TString> EnumNames() const noexcept { + return {TBase::TypelessEnumNames()}; + } + + TMappedArrayView<EEnum> AllEnumValues() const noexcept { + return {TBase::TypelessEnumValues()}; + } + + void Out(IOutputStream* os, const EEnum key) const { + TBase::Out(os, TCast::CastToRepresentationType(key)); + } + + static constexpr TEnumStringPair EnumStringPair(const EEnum key, const TStringBuf name) noexcept { + return {TCast::CastToRepresentationType(key), name}; + } + }; +} diff --git a/tools/enum_parser/enum_serialization_runtime/ya.make b/tools/enum_parser/enum_serialization_runtime/ya.make index c18e4aee10..67c971027f 100644 --- a/tools/enum_parser/enum_serialization_runtime/ya.make +++ b/tools/enum_parser/enum_serialization_runtime/ya.make @@ -1,13 +1,13 @@ -LIBRARY() - -OWNER( - g:util - swarmer -) - -SRCS( - enum_runtime.cpp -) - - -END() +LIBRARY() + +OWNER( + g:util + swarmer +) + +SRCS( + enum_runtime.cpp +) + + +END() diff --git a/tools/enum_parser/ya.make b/tools/enum_parser/ya.make index 762b282b3e..5bf0717668 100644 --- a/tools/enum_parser/ya.make +++ b/tools/enum_parser/ya.make @@ -2,5 +2,5 @@ RECURSE( parse_enum parse_enum/ut enum_parser - enum_serialization_runtime + enum_serialization_runtime ) diff --git a/util/charset/benchmark/to_lower/metrics/ya.make b/util/charset/benchmark/to_lower/metrics/ya.make index 5bb3461a8d..ca5b897fb8 100644 --- a/util/charset/benchmark/to_lower/metrics/ya.make +++ b/util/charset/benchmark/to_lower/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( agorodilov g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/charset/benchmark/utf8_to_wide/metrics/ya.make b/util/charset/benchmark/utf8_to_wide/metrics/ya.make index c406e25bee..68d2375faa 100644 --- a/util/charset/benchmark/utf8_to_wide/metrics/ya.make +++ b/util/charset/benchmark/utf8_to_wide/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( agorodilov g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/charset/benchmark/ya.make b/util/charset/benchmark/ya.make index de3e04ef22..8c196a78d4 100644 --- a/util/charset/benchmark/ya.make +++ b/util/charset/benchmark/ya.make @@ -2,7 +2,7 @@ OWNER( agorodilov g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) RECURSE( to_lower diff --git a/util/charset/ut/ya.make b/util/charset/ut/ya.make index 6526815e92..ebe677d957 100644 --- a/util/charset/ut/ya.make +++ b/util/charset/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util/charset) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) DATA(arcadia/util/charset/ut/utf8) diff --git a/util/charset/ya.make b/util/charset/ya.make index 26d38cb10b..db9b410b20 100644 --- a/util/charset/ya.make +++ b/util/charset/ya.make @@ -1,7 +1,7 @@ LIBRARY() OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) NO_UTIL() @@ -29,7 +29,7 @@ ELSE() ENDIF() END() - -RECURSE_FOR_TESTS( - ut -) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/datetime/ut/ya.make b/util/datetime/ut/ya.make index c2bc714059..ed001b4a8f 100644 --- a/util/datetime/ut/ya.make +++ b/util/datetime/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( datetime/base_ut.cpp diff --git a/util/datetime/ya.make b/util/datetime/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/datetime/ya.make +++ b/util/datetime/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/digest/ut/ya.make b/util/digest/ut/ya.make index 245b2cf6d2..70c141ccf9 100644 --- a/util/digest/ut/ya.make +++ b/util/digest/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( digest/fnv_ut.cpp diff --git a/util/digest/ya.make b/util/digest/ya.make index e378a7e419..10b832449d 100644 --- a/util/digest/ya.make +++ b/util/digest/ya.make @@ -1,12 +1,12 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PROVIDES(cityhash) - + RECURSE( benchmark ) -RECURSE_FOR_TESTS( - ut -) +RECURSE_FOR_TESTS( + ut +) diff --git a/util/draft/ut/ya.make b/util/draft/ut/ya.make index 37ab9413c5..5b8693e478 100644 --- a/util/draft/ut/ya.make +++ b/util/draft/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST() OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCDIR(util/draft) diff --git a/util/draft/ya.make b/util/draft/ya.make index e00674b682..5d101f9f05 100644 --- a/util/draft/ya.make +++ b/util/draft/ya.make @@ -1,7 +1,7 @@ LIBRARY() OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) NO_UTIL() @@ -20,7 +20,7 @@ SRCS( ) END() - -RECURSE_FOR_TESTS( - ut -) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/folder/fwd.cpp b/util/folder/fwd.cpp index 4214b6df83..2261ef316c 100644 --- a/util/folder/fwd.cpp +++ b/util/folder/fwd.cpp @@ -1 +1 @@ -#include "fwd.h" +#include "fwd.h" diff --git a/util/folder/fwd.h b/util/folder/fwd.h index 8b1869a2d9..85e61b3150 100644 --- a/util/folder/fwd.h +++ b/util/folder/fwd.h @@ -1,5 +1,5 @@ -#pragma once - -class TFsPath; - -class TTempDir; +#pragma once + +class TFsPath; + +class TTempDir; diff --git a/util/folder/path.h b/util/folder/path.h index 2fb4d6b4ef..18d9f82b13 100644 --- a/util/folder/path.h +++ b/util/folder/path.h @@ -1,6 +1,6 @@ #pragma once -#include "fwd.h" +#include "fwd.h" #include "pathsplit.h" #include <util/generic/ptr.h> diff --git a/util/folder/tempdir.h b/util/folder/tempdir.h index ff458f83b9..14da1f90e6 100644 --- a/util/folder/tempdir.h +++ b/util/folder/tempdir.h @@ -1,6 +1,6 @@ #pragma once -#include "fwd.h" +#include "fwd.h" #include "path.h" #include <util/generic/string.h> diff --git a/util/folder/ut/ya.make b/util/folder/ut/ya.make index 64877d9b58..24aa46d703 100644 --- a/util/folder/ut/ya.make +++ b/util/folder/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( folder/dirut_ut.cpp diff --git a/util/folder/ya.make b/util/folder/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/folder/ya.make +++ b/util/folder/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index badfb88993..62b32731e6 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -83,16 +83,16 @@ static inline void StableSort(TContainer& container, TCompare compare) { StableSort(container.begin(), container.end(), compare); } -template <class TIterator, typename TGetKey> -static inline void StableSortBy(TIterator begin, TIterator end, const TGetKey& getKey) { +template <class TIterator, typename TGetKey> +static inline void StableSortBy(TIterator begin, TIterator end, const TGetKey& getKey) { StableSort(begin, end, [&](auto&& left, auto&& right) { return getKey(left) < getKey(right); }); -} - -template <class TContainer, typename TGetKey> -static inline void StableSortBy(TContainer& container, const TGetKey& getKey) { - StableSortBy(container.begin(), container.end(), getKey); -} - +} + +template <class TContainer, typename TGetKey> +static inline void StableSortBy(TContainer& container, const TGetKey& getKey) { + StableSortBy(container.begin(), container.end(), getKey); +} + template <class T> static inline void PartialSort(T f, T m, T l) { std::partial_sort(f, m, l); @@ -135,9 +135,9 @@ static inline auto FindPtr(I f, I l, const T& v) -> decltype(&*f) { template <class C, class T> static inline auto FindPtr(C&& c, const T& v) { - using std::begin; - using std::end; - return FindPtr(begin(c), end(c), v); + using std::begin; + using std::end; + return FindPtr(begin(c), end(c), v); } template <class I, class P> @@ -160,9 +160,9 @@ static inline bool AllOf(I f, I l, P pred) { template <class C, class P> static inline bool AllOf(const C& c, P pred) { - using std::begin; - using std::end; - return AllOf(begin(c), end(c), pred); + using std::begin; + using std::end; + return AllOf(begin(c), end(c), pred); } template <class I, class P> @@ -172,9 +172,9 @@ static inline bool AnyOf(I f, I l, P pred) { template <class C, class P> static inline bool AnyOf(const C& c, P pred) { - using std::begin; - using std::end; - return AnyOf(begin(c), end(c), pred); + using std::begin; + using std::end; + return AnyOf(begin(c), end(c), pred); } // FindIfPtr - return NULL if not found. Works for arrays, containers, iterators @@ -186,17 +186,17 @@ static inline auto FindIfPtr(I f, I l, P pred) -> decltype(&*f) { template <class C, class P> static inline auto FindIfPtr(C&& c, P pred) { - using std::begin; - using std::end; - return FindIfPtr(begin(c), end(c), pred); + using std::begin; + using std::end; + return FindIfPtr(begin(c), end(c), pred); } template <class C, class T> static inline size_t FindIndex(C&& c, const T& x) { - using std::begin; - using std::end; - auto it = Find(begin(c), end(c), x); - return it == end(c) ? NPOS : (it - begin(c)); + using std::begin; + using std::end; + auto it = Find(begin(c), end(c), x); + return it == end(c) ? NPOS : (it - begin(c)); } template <class C, class P> @@ -650,9 +650,9 @@ static inline auto CountIf(It first, It last, P p) { template <class C, class P> static inline auto CountIf(const C& c, P pred) { - using std::begin; - using std::end; - return CountIf(begin(c), end(c), pred); + using std::begin; + using std::end; + return CountIf(begin(c), end(c), pred); } template <class I1, class I2> diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 8d732fcc0c..35ef7cfe35 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -13,11 +13,11 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(1 == AnyOf(TStringBuf("10"), isOne)); UNIT_ASSERT(1 == AnyOf(TStringBuf("11"), isOne)); UNIT_ASSERT(0 == AnyOf(TStringBuf(), isOne)); - - const char array00[]{'0', '0'}; - UNIT_ASSERT(0 == AnyOf(array00, isOne)); - const char array01[]{'0', '1'}; - UNIT_ASSERT(1 == AnyOf(array01, isOne)); + + const char array00[]{'0', '0'}; + UNIT_ASSERT(0 == AnyOf(array00, isOne)); + const char array01[]{'0', '1'}; + UNIT_ASSERT(1 == AnyOf(array01, isOne)); } Y_UNIT_TEST(AllOfTest) { @@ -26,11 +26,11 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(0 == AllOf(TStringBuf("10"), isOne)); UNIT_ASSERT(1 == AllOf(TStringBuf("11"), isOne)); UNIT_ASSERT(1 == AllOf(TStringBuf(), isOne)); - - const char array01[]{'0', '1'}; - UNIT_ASSERT(0 == AllOf(array01, isOne)); - const char array11[]{'1', '1'}; - UNIT_ASSERT(1 == AllOf(array11, isOne)); + + const char array01[]{'0', '1'}; + UNIT_ASSERT(0 == AllOf(array01, isOne)); + const char array11[]{'1', '1'}; + UNIT_ASSERT(1 == AllOf(array11, isOne)); } Y_UNIT_TEST(CountIfTest) { @@ -39,9 +39,9 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(0 == CountIf(TStringBuf("___________"), isOne)); UNIT_ASSERT(0 == CountIf(TStringBuf(), isOne)); UNIT_ASSERT(1 == CountIf(TStringBuf("1"), isOne)); - - const char array[] = "____1________1____1_______"; - UNIT_ASSERT(3 == CountIf(array, isOne)); + + const char array[] = "____1________1____1_______"; + UNIT_ASSERT(3 == CountIf(array, isOne)); } Y_UNIT_TEST(CountTest) { @@ -51,9 +51,9 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(0 == Count(TStringBuf("___________"), '1')); UNIT_ASSERT(0 == Count(TStringBuf(), '1')); UNIT_ASSERT(1 == Count(TStringBuf("1"), '1')); - - const char array[] = "____1________1____1_______"; - UNIT_ASSERT(3 == Count(array, '1')); + + const char array[] = "____1________1____1_______"; + UNIT_ASSERT(3 == Count(array, '1')); } struct TStrokaNoCopy: TString { @@ -510,11 +510,11 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(StableSortByTest) { TVector<int> collection = {404, 101, 106, 203, 102, 205, 401}; - StableSortBy(collection, [](int x) { return x / 100; }); + StableSortBy(collection, [](int x) { return x / 100; }); TVector<int> expected = {101, 106, 102, 203, 205, 404, 401}; - UNIT_ASSERT_VALUES_EQUAL(collection, expected); - } - + UNIT_ASSERT_VALUES_EQUAL(collection, expected); + } + Y_UNIT_TEST(SortUniqueByTest) { TVector<int> collection = {404, 101, 101, 203, 101, 203, 404}; StableSortUniqueBy(collection, [](int x) { return x / 100; }); diff --git a/util/generic/array_ref.h b/util/generic/array_ref.h index 1ac60ac7d3..f8bc42e179 100644 --- a/util/generic/array_ref.h +++ b/util/generic/array_ref.h @@ -35,39 +35,39 @@ public: using reverse_iterator = std::reverse_iterator<iterator>; using const_reverse_iterator = std::reverse_iterator<const_iterator>; - constexpr inline TArrayRef() noexcept + constexpr inline TArrayRef() noexcept : T_(nullptr) , S_(0) { } - constexpr inline TArrayRef(T* data, size_t len) noexcept + constexpr inline TArrayRef(T* data, size_t len) noexcept : T_(data) , S_(len) { } - constexpr inline TArrayRef(T* begin, T* end) noexcept + constexpr inline TArrayRef(T* begin, T* end) noexcept : T_(begin) , S_(end - begin) { } - constexpr inline TArrayRef(std::initializer_list<T> list) noexcept + constexpr inline TArrayRef(std::initializer_list<T> list) noexcept : T_(list.begin()) , S_(list.size()) { } template <class Container> - constexpr inline TArrayRef(Container&& container, decltype(std::declval<T*&>() = container.data(), nullptr) = nullptr) noexcept + constexpr inline TArrayRef(Container&& container, decltype(std::declval<T*&>() = container.data(), nullptr) = nullptr) noexcept : T_(container.data()) , S_(container.size()) { } template <size_t N> - constexpr inline TArrayRef(T (&array)[N]) noexcept + constexpr inline TArrayRef(T (&array)[N]) noexcept : T_(array) , S_(N) { @@ -250,12 +250,12 @@ TArrayRef<char> as_writable_bytes(TArrayRef<T> arrayRef) noexcept { } template <class Range> -constexpr TArrayRef<const typename Range::value_type> MakeArrayRef(const Range& range) { +constexpr TArrayRef<const typename Range::value_type> MakeArrayRef(const Range& range) { return TArrayRef<const typename Range::value_type>(range); } template <class Range> -constexpr TArrayRef<typename Range::value_type> MakeArrayRef(Range& range) { +constexpr TArrayRef<typename Range::value_type> MakeArrayRef(Range& range) { return TArrayRef<typename Range::value_type>(range); } @@ -270,11 +270,11 @@ constexpr TArrayRef<const typename Range::value_type> MakeConstArrayRef(Range& r } template <class T> -constexpr TArrayRef<T> MakeArrayRef(T* data, size_t size) { +constexpr TArrayRef<T> MakeArrayRef(T* data, size_t size) { return TArrayRef<T>(data, size); } template <class T> -constexpr TArrayRef<T> MakeArrayRef(T* begin, T* end) { +constexpr TArrayRef<T> MakeArrayRef(T* begin, T* end) { return TArrayRef<T>(begin, end); } diff --git a/util/generic/array_ref_ut.cpp b/util/generic/array_ref_ut.cpp index 4c8eaf7135..b322fd75ae 100644 --- a/util/generic/array_ref_ut.cpp +++ b/util/generic/array_ref_ut.cpp @@ -283,10 +283,10 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { Do(a); UNIT_ASSERT_VALUES_EQUAL(a[0], 8); } - - Y_UNIT_TEST(TestConstexpr) { - static constexpr const int a[] = {1, 2, -3, -4}; - static constexpr const auto r0 = MakeArrayRef(a, 1); + + Y_UNIT_TEST(TestConstexpr) { + static constexpr const int a[] = {1, 2, -3, -4}; + static constexpr const auto r0 = MakeArrayRef(a, 1); static_assert(r0.size() == 1, "r0.size() is not equal 1"); static_assert(r0.data()[0] == 1, "r0.data()[0] is not equal to 1"); @@ -297,7 +297,7 @@ Y_UNIT_TEST_SUITE(TestArrayRef) { static constexpr const TArrayRef<const int> r2 = r1; static_assert(r2.size() == 4, "r2.size() is not equal to 4"); static_assert(r2.data()[2] == -3, "r2.data()[2] is not equal to -3"); - } + } template <typename T> static void Foo(const TConstArrayRef<T>) { diff --git a/util/generic/benchmark/fastclp2/metrics/ya.make b/util/generic/benchmark/fastclp2/metrics/ya.make index b2d17ebad3..1a3b73a398 100644 --- a/util/generic/benchmark/fastclp2/metrics/ya.make +++ b/util/generic/benchmark/fastclp2/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/generic/benchmark/fastclp2/ya.make b/util/generic/benchmark/fastclp2/ya.make index 976977014f..7ba0dcee94 100644 --- a/util/generic/benchmark/fastclp2/ya.make +++ b/util/generic/benchmark/fastclp2/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) Y_BENCHMARK() diff --git a/util/generic/benchmark/log2/metrics/ya.make b/util/generic/benchmark/log2/metrics/ya.make index eb987e38d2..0e7801fddb 100644 --- a/util/generic/benchmark/log2/metrics/ya.make +++ b/util/generic/benchmark/log2/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/generic/benchmark/log2/ya.make b/util/generic/benchmark/log2/ya.make index 45d751909e..baac034e69 100644 --- a/util/generic/benchmark/log2/ya.make +++ b/util/generic/benchmark/log2/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) Y_BENCHMARK() diff --git a/util/generic/benchmark/rotate_bits/metrics/ya.make b/util/generic/benchmark/rotate_bits/metrics/ya.make index ac27d2f845..f16c659236 100644 --- a/util/generic/benchmark/rotate_bits/metrics/ya.make +++ b/util/generic/benchmark/rotate_bits/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/generic/benchmark/rotate_bits/ya.make b/util/generic/benchmark/rotate_bits/ya.make index 976977014f..7ba0dcee94 100644 --- a/util/generic/benchmark/rotate_bits/ya.make +++ b/util/generic/benchmark/rotate_bits/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) Y_BENCHMARK() diff --git a/util/generic/benchmark/singleton/ya.make b/util/generic/benchmark/singleton/ya.make index 12d3d316c8..ae6576c52f 100644 --- a/util/generic/benchmark/singleton/ya.make +++ b/util/generic/benchmark/singleton/ya.make @@ -1,7 +1,7 @@ Y_BENCHMARK() OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( f.cpp diff --git a/util/generic/benchmark/smart_pointers/ya.make b/util/generic/benchmark/smart_pointers/ya.make index 7059abc3a4..5628d4fb8a 100644 --- a/util/generic/benchmark/smart_pointers/ya.make +++ b/util/generic/benchmark/smart_pointers/ya.make @@ -1,7 +1,7 @@ Y_BENCHMARK() OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( main.cpp diff --git a/util/generic/benchmark/sort/ya.make b/util/generic/benchmark/sort/ya.make index 7059abc3a4..5628d4fb8a 100644 --- a/util/generic/benchmark/sort/ya.make +++ b/util/generic/benchmark/sort/ya.make @@ -1,7 +1,7 @@ Y_BENCHMARK() OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( main.cpp diff --git a/util/generic/benchmark/vector_count_ctor/metrics/ya.make b/util/generic/benchmark/vector_count_ctor/metrics/ya.make index c48f89b564..a763150b58 100644 --- a/util/generic/benchmark/vector_count_ctor/metrics/ya.make +++ b/util/generic/benchmark/vector_count_ctor/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/generic/benchmark/vector_count_ctor/ya.make b/util/generic/benchmark/vector_count_ctor/ya.make index 42ce442819..1406f81210 100644 --- a/util/generic/benchmark/vector_count_ctor/ya.make +++ b/util/generic/benchmark/vector_count_ctor/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) Y_BENCHMARK() diff --git a/util/generic/benchmark/ya.make b/util/generic/benchmark/ya.make index 635860a646..98358ad6bd 100644 --- a/util/generic/benchmark/ya.make +++ b/util/generic/benchmark/ya.make @@ -1,6 +1,6 @@ OWNER(yazevnul g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) RECURSE( fastclp2 diff --git a/util/generic/fuzz/vector/ya.make b/util/generic/fuzz/vector/ya.make index b8614f6411..9c3ee10b1d 100644 --- a/util/generic/fuzz/vector/ya.make +++ b/util/generic/fuzz/vector/ya.make @@ -4,7 +4,7 @@ OWNER( pg g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( main.cpp diff --git a/util/generic/hash.cpp b/util/generic/hash.cpp index a674ee4538..10f07c5940 100644 --- a/util/generic/hash.cpp +++ b/util/generic/hash.cpp @@ -45,7 +45,7 @@ TString NPrivate::MapKeyToString(unsigned long long key) { TString NPrivate::MapKeyToString(long long key) { return ToString(key); } - -void NPrivate::ThrowKeyNotFoundInHashTableException(const TStringBuf keyRepresentation) { - ythrow yexception() << "Key not found in hashtable: " << keyRepresentation; -} + +void NPrivate::ThrowKeyNotFoundInHashTableException(const TStringBuf keyRepresentation) { + ythrow yexception() << "Key not found in hashtable: " << keyRepresentation; +} diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..11d157a152 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -219,12 +219,12 @@ public: using const_iterator = const_pointer; using size_type = size_t; using difference_type = ptrdiff_t; - using TBucketDivisor = ::NPrivate::THashDivisor; + using TBucketDivisor = ::NPrivate::THashDivisor; _yhashtable_buckets(const Alloc& other) : base_type(other) , Data(nullptr) - , Size() + , Size() { } @@ -232,13 +232,13 @@ public: Y_ASSERT(!Data); } - void initialize_dynamic(TBucketDivisor size) { + void initialize_dynamic(TBucketDivisor size) { Y_ASSERT(!Data); - Data = this->_get_alloc().allocate(size() + 2) + 1; + Data = this->_get_alloc().allocate(size() + 2) + 1; Size = size; - *reinterpret_cast<size_type*>(Data - 1) = size() + 2; + *reinterpret_cast<size_type*>(Data - 1) = size() + 2; } void deinitialize_dynamic() { @@ -246,11 +246,11 @@ public: this->_get_alloc().deallocate(Data - 1, *reinterpret_cast<size_type*>(Data - 1)); Data = pointer(); - Size = TBucketDivisor(); + Size = TBucketDivisor(); } - void initialize_static(pointer data, TBucketDivisor size) { - Y_ASSERT(!Data && data && size() >= 1); + void initialize_static(pointer data, TBucketDivisor size) { + Y_ASSERT(!Data && data && size() >= 1); Data = data; Size = size; @@ -260,11 +260,11 @@ public: Y_ASSERT(Data); Data = pointer(); - Size = TBucketDivisor(); + Size = TBucketDivisor(); } - void resize_noallocate(TBucketDivisor size) { - Y_ASSERT(size() <= capacity()); + void resize_noallocate(TBucketDivisor size) { + Y_ASSERT(size() <= capacity()); Size = size; } @@ -276,10 +276,10 @@ public: return Data; } iterator end() { - return Data + Size(); + return Data + Size(); } const_iterator end() const { - return Data + Size(); + return Data + Size(); } pointer data() { @@ -290,30 +290,30 @@ public: } size_type size() const { - return Size(); + return Size(); } size_type capacity() const { return *reinterpret_cast<size_type*>(Data - 1); } - TBucketDivisor ExtSize() const { - return Size; - } - int BucketDivisorHint() const { - return +Size.Hint; - } + TBucketDivisor ExtSize() const { + return Size; + } + int BucketDivisorHint() const { + return +Size.Hint; + } allocator_type get_allocator() const { return this->_get_alloc(); } const_reference operator[](size_type index) const { - Y_ASSERT(index <= Size()); + Y_ASSERT(index <= Size()); return *(Data + index); } reference operator[](size_type index) { - Y_ASSERT(index <= Size()); + Y_ASSERT(index <= Size()); return *(Data + index); } @@ -329,7 +329,7 @@ private: pointer Data; /** Size of the buckets array. Doesn't take the marker element at the end into account. */ - TBucketDivisor Size; + TBucketDivisor Size; }; /** @@ -455,7 +455,7 @@ class THashTable: private _yhashtable_traits<Value, Key, HashFcn, ExtractKey, Eq using node = typename traits_type::node; using nodep_allocator_type = typename traits_type::nodep_allocator_type; using buckets_type = _yhashtable_buckets<node*, nodep_allocator_type>; - using TBucketDivisor = ::NPrivate::THashDivisor; + using TBucketDivisor = ::NPrivate::THashDivisor; public: using key_type = Key; @@ -560,7 +560,7 @@ public: if (ht.empty()) { initialize_buckets(buckets, 0); } else { - initialize_buckets_dynamic(buckets, ht.buckets.ExtSize()); + initialize_buckets_dynamic(buckets, ht.buckets.ExtSize()); copy_from_dynamic(ht); } } @@ -591,10 +591,10 @@ public: initialize_buckets(buckets, 0); } else { if (buckets.capacity() > ht.buckets.size()) { - buckets.resize_noallocate(ht.buckets.ExtSize()); + buckets.resize_noallocate(ht.buckets.ExtSize()); } else { deinitialize_buckets(buckets); - initialize_buckets_dynamic(buckets, ht.buckets.ExtSize()); + initialize_buckets_dynamic(buckets, ht.buckets.ExtSize()); } copy_from_dynamic(ht); @@ -845,10 +845,10 @@ public: basic_clear(); if (downsize < buckets.size()) { - const TBucketDivisor newSize = HashBucketCountExt(downsize); - if (newSize() < buckets.size()) { - Y_ASSERT(newSize() >= 7); /* We cannot downsize static buckets. */ - buckets.resize_noallocate(newSize); + const TBucketDivisor newSize = HashBucketCountExt(downsize); + if (newSize() < buckets.size()) { + Y_ASSERT(newSize() >= 7); /* We cannot downsize static buckets. */ + buckets.resize_noallocate(newSize); } } } @@ -880,19 +880,19 @@ public: private: static void initialize_buckets(buckets_type& buckets, size_type sizeHint) { if (sizeHint == 0) { - buckets.initialize_static(reinterpret_cast<node**>(const_cast<void**>(_yhashtable_empty_data)) + 1, TBucketDivisor::One()); + buckets.initialize_static(reinterpret_cast<node**>(const_cast<void**>(_yhashtable_empty_data)) + 1, TBucketDivisor::One()); } else { - TBucketDivisor size = HashBucketCountExt(sizeHint); - Y_ASSERT(size() >= 7); + TBucketDivisor size = HashBucketCountExt(sizeHint); + Y_ASSERT(size() >= 7); initialize_buckets_dynamic(buckets, size); } } - static void initialize_buckets_dynamic(buckets_type& buckets, TBucketDivisor size) { + static void initialize_buckets_dynamic(buckets_type& buckets, TBucketDivisor size) { buckets.initialize_dynamic(size); - memset(buckets.data(), 0, size() * sizeof(*buckets.data())); - buckets[size()] = (node*)1; + memset(buckets.data(), 0, size() * sizeof(*buckets.data())); + buckets[size()] = (node*)1; } static void deinitialize_buckets(buckets_type& buckets) { @@ -909,7 +909,7 @@ private: template <class OtherKey> size_type bkt_num_key(const OtherKey& key) const { - return bkt_num_key(key, buckets.ExtSize()); + return bkt_num_key(key, buckets.ExtSize()); } template <class OtherValue> @@ -918,14 +918,14 @@ private: } template <class OtherKey> - size_type bkt_num_key(const OtherKey& key, TBucketDivisor n) const { - const size_type bucket = n.Remainder(this->_get_hash_fun()(key)); - Y_ASSERT((0 <= bucket) && (bucket < n())); - return bucket; + size_type bkt_num_key(const OtherKey& key, TBucketDivisor n) const { + const size_type bucket = n.Remainder(this->_get_hash_fun()(key)); + Y_ASSERT((0 <= bucket) && (bucket < n())); + return bucket; } template <class OtherValue> - size_type bkt_num(const OtherValue& obj, TBucketDivisor n) const { + size_type bkt_num(const OtherValue& obj, TBucketDivisor n) const { return bkt_num_key(get_key(obj), n); } @@ -1268,8 +1268,8 @@ bool THashTable<V, K, HF, Ex, Eq, A>::reserve(size_type num_elements_hint) { if (old_n != 1 && num_elements_hint <= old_n) // TODO: this if is for backwards compatibility down to order-in-buckets level. Can be safely removed. return false; - const TBucketDivisor n = HashBucketCountExt(num_elements_hint + 1, buckets.BucketDivisorHint() + 1); - if (n() > old_n) { + const TBucketDivisor n = HashBucketCountExt(num_elements_hint + 1, buckets.BucketDivisorHint() + 1); + if (n() > old_n) { buckets_type tmp(buckets.get_allocator()); initialize_buckets_dynamic(tmp, n); #ifdef __STL_USE_EXCEPTIONS @@ -1417,8 +1417,8 @@ namespace NPrivate { inline TString MapKeyToString(char* key) { return MapKeyToString(TStringBuf(key)); } - - [[noreturn]] void ThrowKeyNotFoundInHashTableException(const TStringBuf keyRepresentation); + + [[noreturn]] void ThrowKeyNotFoundInHashTableException(const TStringBuf keyRepresentation); } template <class Key, class T, class HashFcn, class EqualKey, class Alloc> @@ -1652,8 +1652,8 @@ public: using namespace ::NPrivate; const_iterator it = find(key); - if (Y_UNLIKELY(it == end())) { - ::NPrivate::ThrowKeyNotFoundInHashTableException(MapKeyToString(key)); + if (Y_UNLIKELY(it == end())) { + ::NPrivate::ThrowKeyNotFoundInHashTableException(MapKeyToString(key)); } return it->second; @@ -1664,8 +1664,8 @@ public: using namespace ::NPrivate; iterator it = find(key); - if (Y_UNLIKELY(it == end())) { - ::NPrivate::ThrowKeyNotFoundInHashTableException(MapKeyToString(key)); + if (Y_UNLIKELY(it == end())) { + ::NPrivate::ThrowKeyNotFoundInHashTableException(MapKeyToString(key)); } return it->second; diff --git a/util/generic/hash_primes.cpp b/util/generic/hash_primes.cpp index 656d31e046..41b23c308c 100644 --- a/util/generic/hash_primes.cpp +++ b/util/generic/hash_primes.cpp @@ -2,9 +2,9 @@ #include "array_size.h" #include "algorithm.h" -/// Order of fields: reciprocal, reciprocal shift, adjacent hint, divisor -#if defined(_32_) -static constexpr ::NPrivate::THashDivisor PRIME_DIVISORS_HOLDER[]{ +/// Order of fields: reciprocal, reciprocal shift, adjacent hint, divisor +#if defined(_32_) +static constexpr ::NPrivate::THashDivisor PRIME_DIVISORS_HOLDER[]{ {0x00000000u, 0u, -1, 0xffffffffu}, // guard value, not a valid divisor {0x24924925u, 2u, 0, 7u}, {0xe1e1e1e2u, 4u, 1, 17u}, @@ -16,30 +16,30 @@ static constexpr ::NPrivate::THashDivisor PRIME_DIVISORS_HOLDER[]{ {0x54e3b41au, 9u, 7, 769u}, {0x53c8eaeeu, 10u, 8, 1543u}, {0x548eacc6u, 11u, 9, 3079u}, - {0x54f1e41eu, 12u, 10, 6151u}, - {0x554e390au, 13u, 11, 12289u}, - {0x5518ee41u, 14u, 12, 24593u}, - {0x554c7203u, 15u, 13, 49157u}, - {0x5549c781u, 16u, 14, 98317u}, - {0x55531c76u, 17u, 15, 196613u}, - {0x554fc734u, 18u, 16, 393241u}, - {0x555538e4u, 19u, 17, 786433u}, - {0x55550e39u, 20u, 18, 1572869u}, - {0x5555071du, 21u, 19, 3145739u}, - {0x5555271du, 22u, 20, 6291469u}, - {0x55554c72u, 23u, 21, 12582917u}, - {0x55554472u, 24u, 22, 25165843u}, - {0x5555531du, 25u, 23, 50331653u}, - {0x55555039u, 26u, 24, 100663319u}, - {0x55555339u, 27u, 25, 201326611u}, - {0x5555550fu, 28u, 26, 402653189u}, - {0x555552ddu, 29u, 27, 805306457u}, - {0x55555544u, 30u, 28, 1610612741u}, - {0x55555554u, 31u, 29, 3221225473u}, - {0x00000006u, 31u, 30, 4294967291u}, -}; -#else -static constexpr ::NPrivate::THashDivisor PRIME_DIVISORS_HOLDER[]{ + {0x54f1e41eu, 12u, 10, 6151u}, + {0x554e390au, 13u, 11, 12289u}, + {0x5518ee41u, 14u, 12, 24593u}, + {0x554c7203u, 15u, 13, 49157u}, + {0x5549c781u, 16u, 14, 98317u}, + {0x55531c76u, 17u, 15, 196613u}, + {0x554fc734u, 18u, 16, 393241u}, + {0x555538e4u, 19u, 17, 786433u}, + {0x55550e39u, 20u, 18, 1572869u}, + {0x5555071du, 21u, 19, 3145739u}, + {0x5555271du, 22u, 20, 6291469u}, + {0x55554c72u, 23u, 21, 12582917u}, + {0x55554472u, 24u, 22, 25165843u}, + {0x5555531du, 25u, 23, 50331653u}, + {0x55555039u, 26u, 24, 100663319u}, + {0x55555339u, 27u, 25, 201326611u}, + {0x5555550fu, 28u, 26, 402653189u}, + {0x555552ddu, 29u, 27, 805306457u}, + {0x55555544u, 30u, 28, 1610612741u}, + {0x55555554u, 31u, 29, 3221225473u}, + {0x00000006u, 31u, 30, 4294967291u}, +}; +#else +static constexpr ::NPrivate::THashDivisor PRIME_DIVISORS_HOLDER[]{ {0x0000000000000000ul, 0u, -1, 0xffffffffu}, // guard value, not a valid divisor {0x2492492492492493ul, 2u, 0, 7u}, {0xe1e1e1e1e1e1e1e2ul, 4u, 1, 17u}, @@ -51,71 +51,71 @@ static constexpr ::NPrivate::THashDivisor PRIME_DIVISORS_HOLDER[]{ {0x54e3b4194ce65de1ul, 9u, 7, 769u}, {0x53c8eaedea6e7f17ul, 10u, 8, 1543u}, {0x548eacc5e1e6e3fcul, 11u, 9, 3079u}, - {0x54f1e41d7767d70cul, 12u, 10, 6151u}, - {0x554e39097a781d80ul, 13u, 11, 12289u}, - {0x5518ee4079ea6929ul, 14u, 12, 24593u}, - {0x554c72025d459231ul, 15u, 13, 49157u}, - {0x5549c78094504ff3ul, 16u, 14, 98317u}, - {0x55531c757b3c329cul, 17u, 15, 196613u}, - {0x554fc7339753b424ul, 18u, 16, 393241u}, - {0x555538e39097b3f4ul, 19u, 17, 786433u}, - {0x55550e38f25ecd82ul, 20u, 18, 1572869u}, - {0x5555071c83b421d2ul, 21u, 19, 3145739u}, - {0x5555271c78097a6aul, 22u, 20, 6291469u}, - {0x55554c71c757b425ul, 23u, 21, 12582917u}, - {0x55554471c7f25ec7ul, 24u, 22, 25165843u}, - {0x5555531c71cad098ul, 25u, 23, 50331653u}, - {0x55555038e3a1d098ul, 26u, 24, 100663319u}, - {0x55555338e3919098ul, 27u, 25, 201326611u}, - {0x5555550e38e39d0aul, 28u, 26, 402653189u}, - {0x555552dc71cbb1eeul, 29u, 27, 805306457u}, - {0x555555438e38e47cul, 30u, 28, 1610612741u}, - {0x555555538e38e391ul, 31u, 29, 3221225473u}, - {0x000000050000001aul, 31u, 30, 4294967291u}, -}; -#endif - -static constexpr const ::NPrivate::THashDivisor* PRIME_DIVISORS = &PRIME_DIVISORS_HOLDER[1]; ///< Address of the first valid divisor + {0x54f1e41d7767d70cul, 12u, 10, 6151u}, + {0x554e39097a781d80ul, 13u, 11, 12289u}, + {0x5518ee4079ea6929ul, 14u, 12, 24593u}, + {0x554c72025d459231ul, 15u, 13, 49157u}, + {0x5549c78094504ff3ul, 16u, 14, 98317u}, + {0x55531c757b3c329cul, 17u, 15, 196613u}, + {0x554fc7339753b424ul, 18u, 16, 393241u}, + {0x555538e39097b3f4ul, 19u, 17, 786433u}, + {0x55550e38f25ecd82ul, 20u, 18, 1572869u}, + {0x5555071c83b421d2ul, 21u, 19, 3145739u}, + {0x5555271c78097a6aul, 22u, 20, 6291469u}, + {0x55554c71c757b425ul, 23u, 21, 12582917u}, + {0x55554471c7f25ec7ul, 24u, 22, 25165843u}, + {0x5555531c71cad098ul, 25u, 23, 50331653u}, + {0x55555038e3a1d098ul, 26u, 24, 100663319u}, + {0x55555338e3919098ul, 27u, 25, 201326611u}, + {0x5555550e38e39d0aul, 28u, 26, 402653189u}, + {0x555552dc71cbb1eeul, 29u, 27, 805306457u}, + {0x555555438e38e47cul, 30u, 28, 1610612741u}, + {0x555555538e38e391ul, 31u, 29, 3221225473u}, + {0x000000050000001aul, 31u, 30, 4294967291u}, +}; +#endif + +static constexpr const ::NPrivate::THashDivisor* PRIME_DIVISORS = &PRIME_DIVISORS_HOLDER[1]; ///< Address of the first valid divisor static constexpr size_t PRIME_DIVISORS_SIZE = Y_ARRAY_SIZE(PRIME_DIVISORS_HOLDER) - 1; ///< Number of valid divisors without the guarding value - + unsigned long HashBucketCount(unsigned long elementCount) { - return HashBucketCountExt(elementCount)(); -} - -static inline ::NPrivate::THashDivisor HashBucketBoundedSearch(unsigned long elementCount) { - const auto begin = PRIME_DIVISORS; - const auto end = PRIME_DIVISORS + PRIME_DIVISORS_SIZE - 1; // adjust range so the last element will be returned if elementCount is bigger than all PRIME_DIVISORS - return *LowerBoundBy(begin, end, elementCount, std::mem_fn(&::NPrivate::THashDivisor::Divisor)); -} - -Y_CONST_FUNCTION -::NPrivate::THashDivisor HashBucketCountExt(unsigned long elementCount) { - if (elementCount <= PRIME_DIVISORS[0]()) { - return PRIME_DIVISORS[0]; - } - - return HashBucketBoundedSearch(elementCount); -} - -Y_CONST_FUNCTION -::NPrivate::THashDivisor HashBucketCountExt(unsigned long elementCount, int hint) { - if (Y_LIKELY(static_cast<size_t>(hint) < PRIME_DIVISORS_SIZE)) { - const int index = hint; - const ::NPrivate::THashDivisor* cnd = PRIME_DIVISORS + index; - if (Y_LIKELY(elementCount <= cnd->Divisor)) { - const ::NPrivate::THashDivisor* prev = cnd - 1; - static_assert(~PRIME_DIVISORS[-1].Divisor == 0, "Invalid guard"); - /* - If index == 0 then PRIME_DIVISORS[0] should be returned. - Otherwise `cnd` is correct value iff (prev->Divisor < elementCount). - Ergo hint is correct if (index == 0 || prev->Divisor < elementCount); - But we can set guard's value to -1 and check both conditions at once. - */ - if (Y_LIKELY(prev->Divisor + 1u <= elementCount)) { - return *cnd; - } - } + return HashBucketCountExt(elementCount)(); +} + +static inline ::NPrivate::THashDivisor HashBucketBoundedSearch(unsigned long elementCount) { + const auto begin = PRIME_DIVISORS; + const auto end = PRIME_DIVISORS + PRIME_DIVISORS_SIZE - 1; // adjust range so the last element will be returned if elementCount is bigger than all PRIME_DIVISORS + return *LowerBoundBy(begin, end, elementCount, std::mem_fn(&::NPrivate::THashDivisor::Divisor)); +} + +Y_CONST_FUNCTION +::NPrivate::THashDivisor HashBucketCountExt(unsigned long elementCount) { + if (elementCount <= PRIME_DIVISORS[0]()) { + return PRIME_DIVISORS[0]; } - return HashBucketBoundedSearch(elementCount); + return HashBucketBoundedSearch(elementCount); } + +Y_CONST_FUNCTION +::NPrivate::THashDivisor HashBucketCountExt(unsigned long elementCount, int hint) { + if (Y_LIKELY(static_cast<size_t>(hint) < PRIME_DIVISORS_SIZE)) { + const int index = hint; + const ::NPrivate::THashDivisor* cnd = PRIME_DIVISORS + index; + if (Y_LIKELY(elementCount <= cnd->Divisor)) { + const ::NPrivate::THashDivisor* prev = cnd - 1; + static_assert(~PRIME_DIVISORS[-1].Divisor == 0, "Invalid guard"); + /* + If index == 0 then PRIME_DIVISORS[0] should be returned. + Otherwise `cnd` is correct value iff (prev->Divisor < elementCount). + Ergo hint is correct if (index == 0 || prev->Divisor < elementCount); + But we can set guard's value to -1 and check both conditions at once. + */ + if (Y_LIKELY(prev->Divisor + 1u <= elementCount)) { + return *cnd; + } + } + } + + return HashBucketBoundedSearch(elementCount); +} diff --git a/util/generic/hash_primes.h b/util/generic/hash_primes.h index 4dc2da0b8f..d2bf12082c 100644 --- a/util/generic/hash_primes.h +++ b/util/generic/hash_primes.h @@ -1,12 +1,12 @@ #pragma once -#include <util/system/compiler.h> -#include <util/system/types.h> - -#if defined(_MSC_VER) && defined(_M_X64) +#include <util/system/compiler.h> +#include <util/system/types.h> + +#if defined(_MSC_VER) && defined(_M_X64) #include <intrin.h> -#endif - +#endif + /** * Calculates the number of buckets for the hash table that will hold the given * number of elements. @@ -15,124 +15,124 @@ * @returns Number of buckets, a prime number that is * greater or equal to `elementCount`. */ -Y_CONST_FUNCTION +Y_CONST_FUNCTION unsigned long HashBucketCount(unsigned long elementCount); - -namespace NPrivate { - - /// Implementation of algorithm 4.1 from: Torbjörn Granlund and Peter L. Montgomery. 1994. Division by invariant integers using multiplication. - /// @see https://gmplib.org/~tege/divcnst-pldi94.pdf - template <typename TDivisor, typename TDividend, typename MulUnsignedUpper> - class TReciprocalDivisor { + +namespace NPrivate { + + /// Implementation of algorithm 4.1 from: Torbjörn Granlund and Peter L. Montgomery. 1994. Division by invariant integers using multiplication. + /// @see https://gmplib.org/~tege/divcnst-pldi94.pdf + template <typename TDivisor, typename TDividend, typename MulUnsignedUpper> + class TReciprocalDivisor { static_assert(sizeof(TDivisor) <= sizeof(TDividend), "TDivisor and TDividend should have the same size"); - public: - constexpr TReciprocalDivisor() noexcept = default; - - constexpr TReciprocalDivisor(TDividend reciprocal, ui8 reciprocalShift, i8 hint, TDivisor divisor) noexcept - : Reciprocal(reciprocal) - , Divisor(divisor) - , ReciprocalShift(reciprocalShift) - , Hint(hint) - { - } - - /// Return (dividend % Divisor) - Y_FORCE_INLINE TDividend Remainder(TDividend dividend) const noexcept { - if (Y_UNLIKELY(Divisor == 1)) { - return 0; - } - TDividend r = dividend - Quotent(dividend) * Divisor; - return r; - } - - Y_FORCE_INLINE TDivisor operator()() const noexcept { - return Divisor; - } - - Y_FORCE_INLINE static constexpr TReciprocalDivisor One() noexcept { - return {1u, 0u, -1, 1u}; - } - - private: - /// returns (dividend / Divisor) - Y_FORCE_INLINE TDividend Quotent(TDividend dividend) const noexcept { - const TDividend t = MulUnsignedUpper{}(dividend, Reciprocal); - const TDividend q = (t + ((dividend - t) >> 1)) >> ReciprocalShift; - return q; - } - - public: - TDividend Reciprocal = 0; - TDivisor Divisor = 0; - ui8 ReciprocalShift = 0; - i8 Hint = 0; ///< Additional data: needless for division, but useful for the adjacent divisors search - }; - - template <typename T, typename TExtended, size_t shift> - struct TMulUnsignedUpper { - /// Return the high bits of the product of two unsigned integers. - Y_FORCE_INLINE T operator()(T a, T b) const noexcept { - return (static_cast<TExtended>(a) * static_cast<TExtended>(b)) >> shift; - } - }; - -#if defined(_32_) - using THashDivisor = ::NPrivate::TReciprocalDivisor<ui32, ui32, TMulUnsignedUpper<ui32, ui64, 32>>; -#else + public: + constexpr TReciprocalDivisor() noexcept = default; + + constexpr TReciprocalDivisor(TDividend reciprocal, ui8 reciprocalShift, i8 hint, TDivisor divisor) noexcept + : Reciprocal(reciprocal) + , Divisor(divisor) + , ReciprocalShift(reciprocalShift) + , Hint(hint) + { + } + + /// Return (dividend % Divisor) + Y_FORCE_INLINE TDividend Remainder(TDividend dividend) const noexcept { + if (Y_UNLIKELY(Divisor == 1)) { + return 0; + } + TDividend r = dividend - Quotent(dividend) * Divisor; + return r; + } + + Y_FORCE_INLINE TDivisor operator()() const noexcept { + return Divisor; + } + + Y_FORCE_INLINE static constexpr TReciprocalDivisor One() noexcept { + return {1u, 0u, -1, 1u}; + } + + private: + /// returns (dividend / Divisor) + Y_FORCE_INLINE TDividend Quotent(TDividend dividend) const noexcept { + const TDividend t = MulUnsignedUpper{}(dividend, Reciprocal); + const TDividend q = (t + ((dividend - t) >> 1)) >> ReciprocalShift; + return q; + } + + public: + TDividend Reciprocal = 0; + TDivisor Divisor = 0; + ui8 ReciprocalShift = 0; + i8 Hint = 0; ///< Additional data: needless for division, but useful for the adjacent divisors search + }; + + template <typename T, typename TExtended, size_t shift> + struct TMulUnsignedUpper { + /// Return the high bits of the product of two unsigned integers. + Y_FORCE_INLINE T operator()(T a, T b) const noexcept { + return (static_cast<TExtended>(a) * static_cast<TExtended>(b)) >> shift; + } + }; + +#if defined(_32_) + using THashDivisor = ::NPrivate::TReciprocalDivisor<ui32, ui32, TMulUnsignedUpper<ui32, ui64, 32>>; +#else #if defined(Y_HAVE_INT128) - using THashDivisor = ::NPrivate::TReciprocalDivisor<ui32, ui64, TMulUnsignedUpper<ui64, unsigned __int128, 64>>; + using THashDivisor = ::NPrivate::TReciprocalDivisor<ui32, ui64, TMulUnsignedUpper<ui64, unsigned __int128, 64>>; #elif defined(_MSC_VER) && defined(_M_X64) - struct TMulUnsignedUpperVCIntrin { - /// Return the high 64 bits of the product of two 64-bit unsigned integers. - Y_FORCE_INLINE ui64 operator()(ui64 a, ui64 b) const noexcept { - return __umulh(a, b); - } - }; - using THashDivisor = ::NPrivate::TReciprocalDivisor<ui32, ui64, TMulUnsignedUpperVCIntrin>; + struct TMulUnsignedUpperVCIntrin { + /// Return the high 64 bits of the product of two 64-bit unsigned integers. + Y_FORCE_INLINE ui64 operator()(ui64 a, ui64 b) const noexcept { + return __umulh(a, b); + } + }; + using THashDivisor = ::NPrivate::TReciprocalDivisor<ui32, ui64, TMulUnsignedUpperVCIntrin>; #else - template <typename TDivisor, typename TDividend> - class TNaiveDivisor { - public: - constexpr TNaiveDivisor() noexcept = default; - - constexpr TNaiveDivisor(TDivisor divisor) noexcept - : Divisor(divisor) - { - } - - constexpr TNaiveDivisor(TDividend reciprocal, ui8 reciprocalShift, i8 hint, TDivisor divisor) noexcept - : TNaiveDivisor(divisor) - { - Y_UNUSED(reciprocal); - Y_UNUSED(reciprocalShift); - Y_UNUSED(hint); - } - - Y_FORCE_INLINE TDividend Remainder(TDividend dividend) const noexcept { - return dividend % Divisor; - } - - Y_FORCE_INLINE TDivisor operator()() const noexcept { - return Divisor; - } - - Y_FORCE_INLINE static constexpr TNaiveDivisor One() noexcept { - return {1u}; - } - - public: - TDivisor Divisor = 0; - static constexpr i8 Hint = -1; - }; - - using THashDivisor = ::NPrivate::TNaiveDivisor<ui32, ui64>; + template <typename TDivisor, typename TDividend> + class TNaiveDivisor { + public: + constexpr TNaiveDivisor() noexcept = default; + + constexpr TNaiveDivisor(TDivisor divisor) noexcept + : Divisor(divisor) + { + } + + constexpr TNaiveDivisor(TDividend reciprocal, ui8 reciprocalShift, i8 hint, TDivisor divisor) noexcept + : TNaiveDivisor(divisor) + { + Y_UNUSED(reciprocal); + Y_UNUSED(reciprocalShift); + Y_UNUSED(hint); + } + + Y_FORCE_INLINE TDividend Remainder(TDividend dividend) const noexcept { + return dividend % Divisor; + } + + Y_FORCE_INLINE TDivisor operator()() const noexcept { + return Divisor; + } + + Y_FORCE_INLINE static constexpr TNaiveDivisor One() noexcept { + return {1u}; + } + + public: + TDivisor Divisor = 0; + static constexpr i8 Hint = -1; + }; + + using THashDivisor = ::NPrivate::TNaiveDivisor<ui32, ui64>; #endif -#endif -} - -Y_CONST_FUNCTION -::NPrivate::THashDivisor HashBucketCountExt(unsigned long elementCount); - -Y_CONST_FUNCTION -::NPrivate::THashDivisor HashBucketCountExt(unsigned long elementCount, int hint); +#endif +} + +Y_CONST_FUNCTION +::NPrivate::THashDivisor HashBucketCountExt(unsigned long elementCount); + +Y_CONST_FUNCTION +::NPrivate::THashDivisor HashBucketCountExt(unsigned long elementCount, int hint); diff --git a/util/generic/hash_primes_ut.cpp b/util/generic/hash_primes_ut.cpp index 7b5bf8b5c9..6f0315c7dc 100644 --- a/util/generic/hash_primes_ut.cpp +++ b/util/generic/hash_primes_ut.cpp @@ -2,10 +2,10 @@ #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/vector.h> -#include <util/string/builder.h> -#include <util/random/fast.h> - +#include <util/generic/vector.h> +#include <util/string/builder.h> +#include <util/random/fast.h> + Y_UNIT_TEST_SUITE(TestHashPrimes) { Y_UNIT_TEST(Test1) { UNIT_ASSERT_VALUES_EQUAL(HashBucketCount(1), 7); @@ -13,68 +13,68 @@ Y_UNIT_TEST_SUITE(TestHashPrimes) { UNIT_ASSERT_VALUES_EQUAL(HashBucketCount(7), 7); UNIT_ASSERT_VALUES_EQUAL(HashBucketCount(8), 17); } - - static TVector<size_t> Numbers() { - TVector<size_t> numbers; - - TFastRng64 rng{961923}; - size_t k = 1; - for (size_t j = 0; j < 8000; ++j) { - numbers.push_back(rng.GenRand()); - numbers.push_back(k *= 57); - } - for (size_t p = 1; p != 0; p <<= 1) { - for (size_t offset : {-2, -1, 0, 1, 2}) { - numbers.push_back(p + offset); - } - } - return numbers; - } - - static TVector<size_t> Divisors() { - TVector<size_t> divisors; - divisors.push_back(HashBucketCountExt(0)()); - for (;;) { - const size_t prevSize = divisors.back(); - const size_t nextSize = HashBucketCountExt(prevSize + 1)(); - if (nextSize <= prevSize) { - break; - } - divisors.push_back(nextSize); - } - return divisors; - } - - Y_UNIT_TEST(Remainder) { - const TVector<size_t> numbers = Numbers(); - const TVector<size_t> divisors = Divisors(); - - auto testDivisor = [&](const auto& c) { - for (size_t n : numbers) { - UNIT_ASSERT_VALUES_EQUAL_C(n % c(), c.Remainder(n), (TStringBuilder() << "n=" << n << "; d=" << c())); - } - }; - - for (size_t d : divisors) { - const auto c = HashBucketCountExt(d); - UNIT_ASSERT_VALUES_EQUAL_C(d, c(), (TStringBuilder() << "d=" << d)); - testDivisor(c); - } - testDivisor(::NPrivate::THashDivisor::One()); - } - - Y_UNIT_TEST(MisleadingHints) { - TFastRng64 rng{332142}; - TVector<size_t> cases = Numbers(); - for (size_t d : Divisors()) { - cases.push_back(d); - } - - for (size_t c : cases) { - for (size_t reps = 0; reps < 3; ++reps) { - const i8 hint = rng.Uniform(256) - 128; - UNIT_ASSERT_VALUES_EQUAL_C(HashBucketCountExt(c)(), HashBucketCountExt(c, hint)(), (TStringBuilder() << "c=" << c << "; hint=" << hint)); - } - } - } + + static TVector<size_t> Numbers() { + TVector<size_t> numbers; + + TFastRng64 rng{961923}; + size_t k = 1; + for (size_t j = 0; j < 8000; ++j) { + numbers.push_back(rng.GenRand()); + numbers.push_back(k *= 57); + } + for (size_t p = 1; p != 0; p <<= 1) { + for (size_t offset : {-2, -1, 0, 1, 2}) { + numbers.push_back(p + offset); + } + } + return numbers; + } + + static TVector<size_t> Divisors() { + TVector<size_t> divisors; + divisors.push_back(HashBucketCountExt(0)()); + for (;;) { + const size_t prevSize = divisors.back(); + const size_t nextSize = HashBucketCountExt(prevSize + 1)(); + if (nextSize <= prevSize) { + break; + } + divisors.push_back(nextSize); + } + return divisors; + } + + Y_UNIT_TEST(Remainder) { + const TVector<size_t> numbers = Numbers(); + const TVector<size_t> divisors = Divisors(); + + auto testDivisor = [&](const auto& c) { + for (size_t n : numbers) { + UNIT_ASSERT_VALUES_EQUAL_C(n % c(), c.Remainder(n), (TStringBuilder() << "n=" << n << "; d=" << c())); + } + }; + + for (size_t d : divisors) { + const auto c = HashBucketCountExt(d); + UNIT_ASSERT_VALUES_EQUAL_C(d, c(), (TStringBuilder() << "d=" << d)); + testDivisor(c); + } + testDivisor(::NPrivate::THashDivisor::One()); + } + + Y_UNIT_TEST(MisleadingHints) { + TFastRng64 rng{332142}; + TVector<size_t> cases = Numbers(); + for (size_t d : Divisors()) { + cases.push_back(d); + } + + for (size_t c : cases) { + for (size_t reps = 0; reps < 3; ++reps) { + const i8 hint = rng.Uniform(256) - 128; + UNIT_ASSERT_VALUES_EQUAL_C(HashBucketCountExt(c)(), HashBucketCountExt(c, hint)(), (TStringBuilder() << "c=" << c << "; hint=" << hint)); + } + } + } } diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 0551d58770..dec374c4a6 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -722,7 +722,7 @@ void THashTest::TestSizeOf() { * THashTable are empty. It does rely on knowledge of THashTable internals, * so if those change, the test will have to be adjusted accordingly. */ - size_t expectedSize = sizeof(uintptr_t) + 3 * sizeof(size_t); + size_t expectedSize = sizeof(uintptr_t) + 3 * sizeof(size_t); UNIT_ASSERT_VALUES_EQUAL(sizeof(THashMap<int, int>), expectedSize); UNIT_ASSERT_VALUES_EQUAL(sizeof(THashMap<std::pair<int, int>, std::pair<int, int>>), expectedSize); diff --git a/util/generic/maybe.cpp b/util/generic/maybe.cpp index 43262934f8..4d90243795 100644 --- a/util/generic/maybe.cpp +++ b/util/generic/maybe.cpp @@ -3,13 +3,13 @@ [[noreturn]] void NMaybe::TPolicyUndefinedExcept::OnEmpty(const std::type_info& valueTypeInfo) { ythrow yexception() << "TMaybe is empty, value type: "sv << TypeName(valueTypeInfo); -} - +} + [[noreturn]] void NMaybe::TPolicyUndefinedFail::OnEmpty(const std::type_info& valueTypeInfo) { const TString typeName = TypeName(valueTypeInfo); Y_FAIL("TMaybe is empty, value type: %s", typeName.c_str()); -} - +} + template <> void Out<TNothing>(IOutputStream& o, const TNothing&) { o << "(empty maybe)"; diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 34d21aebcd..e853c43d97 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -300,7 +300,7 @@ public: } void CheckDefined() const { - if (Y_UNLIKELY(!Defined())) { + if (Y_UNLIKELY(!Defined())) { Policy::OnEmpty(typeid(TValueType)); } } @@ -313,46 +313,46 @@ public: return Defined() ? Data() : nullptr; } - constexpr const T& GetRef() const& { + constexpr const T& GetRef() const& { CheckDefined(); return *Data(); } - constexpr T& GetRef() & { + constexpr T& GetRef() & { CheckDefined(); return *Data(); } - constexpr const T&& GetRef() const&& { - CheckDefined(); - - return std::move(*Data()); - } - - constexpr T&& GetRef() && { - CheckDefined(); - - return std::move(*Data()); - } - - constexpr const T& operator*() const& { + constexpr const T&& GetRef() const&& { + CheckDefined(); + + return std::move(*Data()); + } + + constexpr T&& GetRef() && { + CheckDefined(); + + return std::move(*Data()); + } + + constexpr const T& operator*() const& { return GetRef(); } - constexpr T& operator*() & { + constexpr T& operator*() & { return GetRef(); } - constexpr const T&& operator*() const&& { - return std::move(GetRef()); - } - - constexpr T&& operator*() && { - return std::move(GetRef()); - } - + constexpr const T&& operator*() const&& { + return std::move(GetRef()); + } + + constexpr T&& operator*() && { + return std::move(GetRef()); + } + constexpr const T* operator->() const { return &GetRef(); } diff --git a/util/generic/maybe_ut.cpp b/util/generic/maybe_ut.cpp index 2c1a425c5e..5769a5f43d 100644 --- a/util/generic/maybe_ut.cpp +++ b/util/generic/maybe_ut.cpp @@ -201,12 +201,12 @@ Y_UNIT_TEST_SUITE(TMaybeTest) { m4 = std::move(m2); UNIT_ASSERT(m4.Defined()); UNIT_ASSERT_VALUES_EQUAL(m4->Flag, 2); - - // Move value from temporary maybe instance - TMovable o5 = *MakeMaybe<TMovable>(5); - UNIT_ASSERT_VALUES_EQUAL(o5.Flag, 5); - TMovable o6 = MakeMaybe<TMovable>(6).GetRef(); - UNIT_ASSERT_VALUES_EQUAL(o6.Flag, 6); + + // Move value from temporary maybe instance + TMovable o5 = *MakeMaybe<TMovable>(5); + UNIT_ASSERT_VALUES_EQUAL(o5.Flag, 5); + TMovable o6 = MakeMaybe<TMovable>(6).GetRef(); + UNIT_ASSERT_VALUES_EQUAL(o6.Flag, 6); } Y_UNIT_TEST(TestCast) { diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp index c2dcff23f6..6b028f410d 100644 --- a/util/generic/ptr_ut.cpp +++ b/util/generic/ptr_ut.cpp @@ -25,7 +25,7 @@ class TPointerTest: public TTestBase { UNIT_TEST(TestIntrPtr); UNIT_TEST(TestIntrusiveConvertion); UNIT_TEST(TestIntrusiveConstConvertion); - UNIT_TEST(TestIntrusiveConstConstruction); + UNIT_TEST(TestIntrusiveConstConstruction); UNIT_TEST(TestMakeIntrusive); UNIT_TEST(TestCopyOnWritePtr1); UNIT_TEST(TestCopyOnWritePtr2); @@ -77,7 +77,7 @@ private: void TestIntrPtr(); void TestIntrusiveConvertion(); void TestIntrusiveConstConvertion(); - void TestIntrusiveConstConstruction(); + void TestIntrusiveConstConstruction(); void TestMakeIntrusive(); void TestCopyOnWritePtr1(); void TestCopyOnWritePtr2(); @@ -776,60 +776,60 @@ void TPointerTest::TestRefCountedPtrsInHashSet() { TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A, TCustomIntrusivePtrOps>>(); TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A, TCustomIntrusivePtrOps>>(); } - -class TRefCountedWithStatistics: public TNonCopyable { -public: - struct TExternalCounter { - TAtomic Counter{0}; - TAtomic Increments{0}; - }; - - TRefCountedWithStatistics(TExternalCounter& cnt) - : ExternalCounter_(cnt) - { - ExternalCounter_ = {}; // reset counters - } - - void Ref() noexcept { - AtomicIncrement(ExternalCounter_.Counter); - AtomicIncrement(ExternalCounter_.Increments); - } - - void UnRef() noexcept { - if (AtomicDecrement(ExternalCounter_.Counter) == 0) { - TDelete::Destroy(this); - } - } - - void DecRef() noexcept { - Y_VERIFY(AtomicDecrement(ExternalCounter_.Counter) != 0); - } - -private: - TExternalCounter& ExternalCounter_; -}; - -void TPointerTest::TestIntrusiveConstConstruction() { - { - TRefCountedWithStatistics::TExternalCounter cnt; - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0); - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 0); - TIntrusivePtr<TRefCountedWithStatistics> i{MakeIntrusive<TRefCountedWithStatistics>(cnt)}; - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 1); - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1); - i.Reset(); - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0); - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1); - } - { - TRefCountedWithStatistics::TExternalCounter cnt; - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0); - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 0); - TIntrusiveConstPtr<TRefCountedWithStatistics> c{MakeIntrusive<TRefCountedWithStatistics>(cnt)}; - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 1); - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1); - c.Reset(); - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0); - UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1); - } -} + +class TRefCountedWithStatistics: public TNonCopyable { +public: + struct TExternalCounter { + TAtomic Counter{0}; + TAtomic Increments{0}; + }; + + TRefCountedWithStatistics(TExternalCounter& cnt) + : ExternalCounter_(cnt) + { + ExternalCounter_ = {}; // reset counters + } + + void Ref() noexcept { + AtomicIncrement(ExternalCounter_.Counter); + AtomicIncrement(ExternalCounter_.Increments); + } + + void UnRef() noexcept { + if (AtomicDecrement(ExternalCounter_.Counter) == 0) { + TDelete::Destroy(this); + } + } + + void DecRef() noexcept { + Y_VERIFY(AtomicDecrement(ExternalCounter_.Counter) != 0); + } + +private: + TExternalCounter& ExternalCounter_; +}; + +void TPointerTest::TestIntrusiveConstConstruction() { + { + TRefCountedWithStatistics::TExternalCounter cnt; + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0); + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 0); + TIntrusivePtr<TRefCountedWithStatistics> i{MakeIntrusive<TRefCountedWithStatistics>(cnt)}; + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 1); + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1); + i.Reset(); + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0); + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1); + } + { + TRefCountedWithStatistics::TExternalCounter cnt; + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0); + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 0); + TIntrusiveConstPtr<TRefCountedWithStatistics> c{MakeIntrusive<TRefCountedWithStatistics>(cnt)}; + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 1); + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1); + c.Reset(); + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0); + UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1); + } +} diff --git a/util/generic/scope.h b/util/generic/scope.h index b2c33af61e..394c8af6be 100644 --- a/util/generic/scope.h +++ b/util/generic/scope.h @@ -43,15 +43,15 @@ namespace NPrivate { // General implementaion of RAII idiom (resource acquisition is initialization). Executes // function upon return from the current scope. // -// @note expects `body` to provide no-throw guarantee, otherwise whenever an exception -// is thrown and leaves the outermost block of `body`, the function `std::terminate` is called. +// @note expects `body` to provide no-throw guarantee, otherwise whenever an exception +// is thrown and leaves the outermost block of `body`, the function `std::terminate` is called. // @see http://drdobbs.com/184403758 for detailed motivation. #define Y_SCOPE_EXIT(...) const auto Y_GENERATE_UNIQUE_ID(scopeGuard) Y_DECLARE_UNUSED = ::NPrivate::TMakeGuardHelper{} | [__VA_ARGS__]() mutable -> void // \brief `Y_DEFER { body };` // // Same as `Y_SCOPE_EXIT` but doesn't require user to provide capture-list explicitly (it -// implicitly uses `[&]` capture). Have same requirements for `body`. +// implicitly uses `[&]` capture). Have same requirements for `body`. // // Inspired by `defer` statement in languages like Swift and Go. // diff --git a/util/generic/serialized_enum.cpp b/util/generic/serialized_enum.cpp index 1478c50b22..f4c2a2ecef 100644 --- a/util/generic/serialized_enum.cpp +++ b/util/generic/serialized_enum.cpp @@ -1 +1 @@ -#include "serialized_enum.h" +#include "serialized_enum.h" diff --git a/util/generic/serialized_enum.h b/util/generic/serialized_enum.h index 79df2bac22..1cf78499bf 100644 --- a/util/generic/serialized_enum.h +++ b/util/generic/serialized_enum.h @@ -1,20 +1,20 @@ #pragma once #include <util/generic/fwd.h> -#include <util/generic/vector.h> -#include <util/generic/map.h> +#include <util/generic/vector.h> +#include <util/generic/map.h> #include <cstddef> -#include <type_traits> +#include <type_traits> /* -A file with declarations of enumeration-related functions. -It doesn't contains definitions. To generate them you have to add +A file with declarations of enumeration-related functions. +It doesn't contains definitions. To generate them you have to add GENERATE_ENUM_SERIALIZATION_WITH_HEADER(your_header_with_your_enum.h) -or - GENERATE_ENUM_SERIALIZATION(your_header_with_your_enum.h) +or + GENERATE_ENUM_SERIALIZATION(your_header_with_your_enum.h) in your ya.make @@ -31,58 +31,58 @@ in your ya.make template <typename EnumT> Y_CONST_FUNCTION constexpr size_t GetEnumItemsCount(); -namespace NEnumSerializationRuntime { - namespace NDetail { - template <typename EEnum> - struct TSelectEnumRepresentationType; - - template <typename TEnumType, typename TRepresentationType, class TStorage = TVector<TRepresentationType>> - class TMappedArrayView; - - template <typename TEnumType, typename TRepresentationType, typename TValueType, class TStorage = TMap<TRepresentationType, TValueType>> - class TMappedDictView; - } - - /// Class with behaviour similar to TMap<EnumT, TValueType> - template <typename EnumT, typename TValueType> - using TMappedDictView = NDetail::TMappedDictView<EnumT, typename NDetail::TSelectEnumRepresentationType<EnumT>::TType, TValueType>; - - /// Class with behaviour similar to TVector<EnumT> - template <typename EnumT> - using TMappedArrayView = NDetail::TMappedArrayView<EnumT, typename NDetail::TSelectEnumRepresentationType<EnumT>::TType>; - - /** - * Returns names for items in enum or enum class - * - * @tparam EnumT enum type - */ - template <typename EnumT> - TMappedDictView<EnumT, TString> GetEnumNamesImpl(); - /** - * Returns unique items in enum or enum class - * - * @tparam EnumT enum type - */ - template <typename EnumT> - ::NEnumSerializationRuntime::TMappedArrayView<EnumT> GetEnumAllValuesImpl(); - - /** - * Returns human-readable comma-separated list of names in enum or enum class - * - * @tparam EnumT enum type - */ - template <typename EnumT> - const TString& GetEnumAllNamesImpl(); - - /** - * Returns C++ identifiers for items in enum or enum class - * - * @tparam EnumT enum type - */ - template <typename EnumT> - const TVector<TString>& GetEnumAllCppNamesImpl(); -} - +namespace NEnumSerializationRuntime { + namespace NDetail { + template <typename EEnum> + struct TSelectEnumRepresentationType; + + template <typename TEnumType, typename TRepresentationType, class TStorage = TVector<TRepresentationType>> + class TMappedArrayView; + + template <typename TEnumType, typename TRepresentationType, typename TValueType, class TStorage = TMap<TRepresentationType, TValueType>> + class TMappedDictView; + } + + /// Class with behaviour similar to TMap<EnumT, TValueType> + template <typename EnumT, typename TValueType> + using TMappedDictView = NDetail::TMappedDictView<EnumT, typename NDetail::TSelectEnumRepresentationType<EnumT>::TType, TValueType>; + + /// Class with behaviour similar to TVector<EnumT> + template <typename EnumT> + using TMappedArrayView = NDetail::TMappedArrayView<EnumT, typename NDetail::TSelectEnumRepresentationType<EnumT>::TType>; + + /** + * Returns names for items in enum or enum class + * + * @tparam EnumT enum type + */ + template <typename EnumT> + TMappedDictView<EnumT, TString> GetEnumNamesImpl(); + /** + * Returns unique items in enum or enum class + * + * @tparam EnumT enum type + */ + template <typename EnumT> + ::NEnumSerializationRuntime::TMappedArrayView<EnumT> GetEnumAllValuesImpl(); + + /** + * Returns human-readable comma-separated list of names in enum or enum class + * + * @tparam EnumT enum type + */ + template <typename EnumT> + const TString& GetEnumAllNamesImpl(); + + /** + * Returns C++ identifiers for items in enum or enum class + * + * @tparam EnumT enum type + */ + template <typename EnumT> + const TVector<TString>& GetEnumAllCppNamesImpl(); +} + /** * Returns names for items in enum or enum class * @@ -90,310 +90,310 @@ namespace NEnumSerializationRuntime { */ template <typename EnumT> Y_CONST_FUNCTION ::NEnumSerializationRuntime::TMappedDictView<EnumT, TString> GetEnumNames() { - return ::NEnumSerializationRuntime::GetEnumNamesImpl<EnumT>(); -} - -/** - * Returns unique items in enum or enum class - * - * @tparam EnumT enum type - */ -template <typename EnumT> + return ::NEnumSerializationRuntime::GetEnumNamesImpl<EnumT>(); +} + +/** + * Returns unique items in enum or enum class + * + * @tparam EnumT enum type + */ +template <typename EnumT> Y_CONST_FUNCTION ::NEnumSerializationRuntime::TMappedArrayView<EnumT> GetEnumAllValues() { - return ::NEnumSerializationRuntime::GetEnumAllValuesImpl<EnumT>(); -} - -/** - * Returns human-readable comma-separated list of names in enum or enum class - * - * @tparam EnumT enum type - */ -template <typename EnumT> + return ::NEnumSerializationRuntime::GetEnumAllValuesImpl<EnumT>(); +} + +/** + * Returns human-readable comma-separated list of names in enum or enum class + * + * @tparam EnumT enum type + */ +template <typename EnumT> Y_CONST_FUNCTION const TString& GetEnumAllNames() { - return ::NEnumSerializationRuntime::GetEnumAllNamesImpl<EnumT>(); -} - -/** - * Returns C++ identifiers for items in enum or enum class - * - * @tparam EnumT enum type - */ -template <typename EnumT> + return ::NEnumSerializationRuntime::GetEnumAllNamesImpl<EnumT>(); +} + +/** + * Returns C++ identifiers for items in enum or enum class + * + * @tparam EnumT enum type + */ +template <typename EnumT> Y_CONST_FUNCTION const TVector<TString>& GetEnumAllCppNames() { - return ::NEnumSerializationRuntime::GetEnumAllCppNamesImpl<EnumT>(); -} - -namespace NEnumSerializationRuntime { - namespace NDetail { - /// Checks that the `From` type can be promoted up to the `To` type without losses - template <typename From, typename To> - struct TIsPromotable: public std::is_same<std::common_type_t<From, To>, To> { - static_assert(std::is_integral<From>::value, "`From` type has to be an integer"); - static_assert(std::is_integral<To>::value, "`To` type has to be an integer"); - }; - - /// Selects enum representation type. Works like std::underlying_type_t<>, but promotes small types up to `int` - template <typename EEnum> - struct TSelectEnumRepresentationType { - using TUnderlyingType = std::underlying_type_t<EEnum>; - using TIsSigned = std::is_signed<TUnderlyingType>; - using TRepresentationType = std::conditional_t< - TIsSigned::value, - std::conditional_t< - TIsPromotable<TUnderlyingType, int>::value, - int, - long long>, - std::conditional_t< - TIsPromotable<TUnderlyingType, unsigned>::value, - unsigned, - unsigned long long>>; - using TType = TRepresentationType; - static_assert(sizeof(TUnderlyingType) <= sizeof(TType), "size of `TType` is not smaller than the size of `TUnderlyingType`"); - }; - - template <typename TEnumType, typename TRepresentationType> - class TMappedViewBase { - static_assert(sizeof(std::underlying_type_t<TEnumType>) <= sizeof(TRepresentationType), "Internal type is probably too small to represent all possible values"); - - public: - static constexpr TEnumType CastFromRepresentationType(const TRepresentationType key) noexcept { - return static_cast<TEnumType>(key); - } - - static constexpr TRepresentationType CastToRepresentationType(const TEnumType key) noexcept { - return static_cast<TRepresentationType>(key); - } - }; - - /// Wrapper class with behaviour similar to TVector<EnumT> - /// - /// @tparam TEnumType enum type at the external interface - /// @tparam TRepresentationType designated underlying type of enum - /// @tparam TStorage internal container type - template <typename TEnumType, typename TRepresentationType, class TStorage> - class TMappedArrayView: public TMappedViewBase<TEnumType, TRepresentationType> { - public: - using value_type = TEnumType; - - public: - TMappedArrayView(const TStorage& a) noexcept - : Ref(a) - { - } - - class TIterator { - public: - using TSlaveIteratorType = typename TStorage::const_iterator; - - using difference_type = std::ptrdiff_t; - using value_type = TEnumType; - using pointer = const TEnumType*; - using reference = const TEnumType&; - using iterator_category = std::bidirectional_iterator_tag; - - public: - TIterator(TSlaveIteratorType it) - : Slave(std::move(it)) - { - } - - bool operator==(const TIterator& it) const { - return Slave == it.Slave; - } - - bool operator!=(const TIterator& it) const { - return !(*this == it); - } - - TEnumType operator*() const { - return TMappedArrayView::CastFromRepresentationType(*Slave); - } - - TIterator& operator++() { - ++Slave; - return *this; - } - - TIterator& operator--() { - --Slave; - return *this; - } - - TIterator operator++(int) { - auto temp = Slave; - ++Slave; - return temp; - } - - TIterator operator--(int) { - auto temp = Slave; - --Slave; - return temp; - } - - private: - TSlaveIteratorType Slave; - }; - - TIterator begin() const { - return Ref.begin(); - } - - TIterator end() const { - return Ref.end(); - } - - size_t size() const { - return Ref.size(); - } - + return ::NEnumSerializationRuntime::GetEnumAllCppNamesImpl<EnumT>(); +} + +namespace NEnumSerializationRuntime { + namespace NDetail { + /// Checks that the `From` type can be promoted up to the `To` type without losses + template <typename From, typename To> + struct TIsPromotable: public std::is_same<std::common_type_t<From, To>, To> { + static_assert(std::is_integral<From>::value, "`From` type has to be an integer"); + static_assert(std::is_integral<To>::value, "`To` type has to be an integer"); + }; + + /// Selects enum representation type. Works like std::underlying_type_t<>, but promotes small types up to `int` + template <typename EEnum> + struct TSelectEnumRepresentationType { + using TUnderlyingType = std::underlying_type_t<EEnum>; + using TIsSigned = std::is_signed<TUnderlyingType>; + using TRepresentationType = std::conditional_t< + TIsSigned::value, + std::conditional_t< + TIsPromotable<TUnderlyingType, int>::value, + int, + long long>, + std::conditional_t< + TIsPromotable<TUnderlyingType, unsigned>::value, + unsigned, + unsigned long long>>; + using TType = TRepresentationType; + static_assert(sizeof(TUnderlyingType) <= sizeof(TType), "size of `TType` is not smaller than the size of `TUnderlyingType`"); + }; + + template <typename TEnumType, typename TRepresentationType> + class TMappedViewBase { + static_assert(sizeof(std::underlying_type_t<TEnumType>) <= sizeof(TRepresentationType), "Internal type is probably too small to represent all possible values"); + + public: + static constexpr TEnumType CastFromRepresentationType(const TRepresentationType key) noexcept { + return static_cast<TEnumType>(key); + } + + static constexpr TRepresentationType CastToRepresentationType(const TEnumType key) noexcept { + return static_cast<TRepresentationType>(key); + } + }; + + /// Wrapper class with behaviour similar to TVector<EnumT> + /// + /// @tparam TEnumType enum type at the external interface + /// @tparam TRepresentationType designated underlying type of enum + /// @tparam TStorage internal container type + template <typename TEnumType, typename TRepresentationType, class TStorage> + class TMappedArrayView: public TMappedViewBase<TEnumType, TRepresentationType> { + public: + using value_type = TEnumType; + + public: + TMappedArrayView(const TStorage& a) noexcept + : Ref(a) + { + } + + class TIterator { + public: + using TSlaveIteratorType = typename TStorage::const_iterator; + + using difference_type = std::ptrdiff_t; + using value_type = TEnumType; + using pointer = const TEnumType*; + using reference = const TEnumType&; + using iterator_category = std::bidirectional_iterator_tag; + + public: + TIterator(TSlaveIteratorType it) + : Slave(std::move(it)) + { + } + + bool operator==(const TIterator& it) const { + return Slave == it.Slave; + } + + bool operator!=(const TIterator& it) const { + return !(*this == it); + } + + TEnumType operator*() const { + return TMappedArrayView::CastFromRepresentationType(*Slave); + } + + TIterator& operator++() { + ++Slave; + return *this; + } + + TIterator& operator--() { + --Slave; + return *this; + } + + TIterator operator++(int) { + auto temp = Slave; + ++Slave; + return temp; + } + + TIterator operator--(int) { + auto temp = Slave; + --Slave; + return temp; + } + + private: + TSlaveIteratorType Slave; + }; + + TIterator begin() const { + return Ref.begin(); + } + + TIterator end() const { + return Ref.end(); + } + + size_t size() const { + return Ref.size(); + } + Y_PURE_FUNCTION bool empty() const { - return Ref.empty(); - } - - TEnumType at(size_t index) const { - return this->CastFromRepresentationType(Ref.at(index)); - } - - TEnumType operator[](size_t index) const { - return this->CastFromRepresentationType(Ref[index]); - } - - // Allocate container and copy view's content into it - template <template <class...> class TContainer = TVector> - TContainer<TEnumType> Materialize() const { - return {begin(), end()}; - } - - private: - const TStorage& Ref; - }; - - /// Wrapper class with behaviour similar to TMap<EnumT, TValueType> - /// - /// @tparam TEnumType enum type at the external interface - /// @tparam TRepresentationType designated underlying type of enum - /// @tparam TValueType mapped value - /// @tparam TStorage internal container type - template <typename TEnumType, typename TRepresentationType, typename TValueType, class TStorage> - class TMappedDictView: public TMappedViewBase<TEnumType, TRepresentationType> { - public: - using TMappedItemType = std::pair<const TEnumType, const TValueType&>; - - class TDereferenceResultHolder { - public: - TDereferenceResultHolder(const TRepresentationType enumValue, const TValueType& payload) noexcept - : Data(TMappedDictView::CastFromRepresentationType(enumValue), payload) - { - } - - const TMappedItemType* operator->() const noexcept { - return &Data; - } - - private: - TMappedItemType Data; - }; - - TMappedDictView(const TStorage& m) noexcept - : Ref(m) - { - } - - class TIterator { - public: - using TSlaveIteratorType = typename TStorage::const_iterator; - - using difference_type = std::ptrdiff_t; - using value_type = TMappedItemType; - using pointer = const TMappedItemType*; - using reference = const TMappedItemType&; - using iterator_category = std::bidirectional_iterator_tag; - - public: - TIterator(TSlaveIteratorType it) - : Slave(std::move(it)) - { - } - - bool operator==(const TIterator& it) const { - return Slave == it.Slave; - } - - bool operator!=(const TIterator& it) const { - return !(*this == it); - } - - TDereferenceResultHolder operator->() const { - return {Slave->first, Slave->second}; - } - - TMappedItemType operator*() const { - return {TMappedDictView::CastFromRepresentationType(Slave->first), Slave->second}; - } - - TIterator& operator++() { - ++Slave; - return *this; - } - - TIterator& operator--() { - --Slave; - return *this; - } - - TIterator operator++(int) { - auto temp = Slave; - ++Slave; - return temp; - } - - TIterator operator--(int) { - auto temp = Slave; - --Slave; - return temp; - } - - private: - TSlaveIteratorType Slave; - }; - - TIterator begin() const { - return Ref.begin(); - } - - TIterator end() const { - return Ref.end(); - } - - size_t size() const { - return Ref.size(); - } - + return Ref.empty(); + } + + TEnumType at(size_t index) const { + return this->CastFromRepresentationType(Ref.at(index)); + } + + TEnumType operator[](size_t index) const { + return this->CastFromRepresentationType(Ref[index]); + } + + // Allocate container and copy view's content into it + template <template <class...> class TContainer = TVector> + TContainer<TEnumType> Materialize() const { + return {begin(), end()}; + } + + private: + const TStorage& Ref; + }; + + /// Wrapper class with behaviour similar to TMap<EnumT, TValueType> + /// + /// @tparam TEnumType enum type at the external interface + /// @tparam TRepresentationType designated underlying type of enum + /// @tparam TValueType mapped value + /// @tparam TStorage internal container type + template <typename TEnumType, typename TRepresentationType, typename TValueType, class TStorage> + class TMappedDictView: public TMappedViewBase<TEnumType, TRepresentationType> { + public: + using TMappedItemType = std::pair<const TEnumType, const TValueType&>; + + class TDereferenceResultHolder { + public: + TDereferenceResultHolder(const TRepresentationType enumValue, const TValueType& payload) noexcept + : Data(TMappedDictView::CastFromRepresentationType(enumValue), payload) + { + } + + const TMappedItemType* operator->() const noexcept { + return &Data; + } + + private: + TMappedItemType Data; + }; + + TMappedDictView(const TStorage& m) noexcept + : Ref(m) + { + } + + class TIterator { + public: + using TSlaveIteratorType = typename TStorage::const_iterator; + + using difference_type = std::ptrdiff_t; + using value_type = TMappedItemType; + using pointer = const TMappedItemType*; + using reference = const TMappedItemType&; + using iterator_category = std::bidirectional_iterator_tag; + + public: + TIterator(TSlaveIteratorType it) + : Slave(std::move(it)) + { + } + + bool operator==(const TIterator& it) const { + return Slave == it.Slave; + } + + bool operator!=(const TIterator& it) const { + return !(*this == it); + } + + TDereferenceResultHolder operator->() const { + return {Slave->first, Slave->second}; + } + + TMappedItemType operator*() const { + return {TMappedDictView::CastFromRepresentationType(Slave->first), Slave->second}; + } + + TIterator& operator++() { + ++Slave; + return *this; + } + + TIterator& operator--() { + --Slave; + return *this; + } + + TIterator operator++(int) { + auto temp = Slave; + ++Slave; + return temp; + } + + TIterator operator--(int) { + auto temp = Slave; + --Slave; + return temp; + } + + private: + TSlaveIteratorType Slave; + }; + + TIterator begin() const { + return Ref.begin(); + } + + TIterator end() const { + return Ref.end(); + } + + size_t size() const { + return Ref.size(); + } + Y_PURE_FUNCTION bool empty() const { - return Ref.empty(); - } - - bool contains(const TEnumType key) const { + return Ref.empty(); + } + + bool contains(const TEnumType key) const { return Ref.contains(this->CastToRepresentationType(key)); - } - - TIterator find(const TEnumType key) const { - return Ref.find(this->CastToRepresentationType(key)); - } - - const TValueType& at(const TEnumType key) const { - return Ref.at(this->CastToRepresentationType(key)); - } - - // Allocate container and copy view's content into it - template <template <class...> class TContainer = TMap> - TContainer<TEnumType, TValueType> Materialize() const { - return {begin(), end()}; - } - - private: - const TStorage& Ref; - }; - } -} + } + + TIterator find(const TEnumType key) const { + return Ref.find(this->CastToRepresentationType(key)); + } + + const TValueType& at(const TEnumType key) const { + return Ref.at(this->CastToRepresentationType(key)); + } + + // Allocate container and copy view's content into it + template <template <class...> class TContainer = TMap> + TContainer<TEnumType, TValueType> Materialize() const { + return {begin(), end()}; + } + + private: + const TStorage& Ref; + }; + } +} diff --git a/util/generic/serialized_enum_ut.cpp b/util/generic/serialized_enum_ut.cpp index 3a94e1d471..0c1b276a38 100644 --- a/util/generic/serialized_enum_ut.cpp +++ b/util/generic/serialized_enum_ut.cpp @@ -1,120 +1,120 @@ -#include "serialized_enum.h" - +#include "serialized_enum.h" + #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/deque.h> -#include <util/generic/map.h> -#include <util/generic/typelist.h> -#include <util/generic/vector.h> - -Y_UNIT_TEST_SUITE(TestSerializedEnum) { - Y_UNIT_TEST(RepresentationTypes) { - using namespace NEnumSerializationRuntime::NDetail; - - static_assert(TIsPromotable<int, int>::value, "int -> int"); - static_assert(TIsPromotable<char, int>::value, "char -> int"); - static_assert(TIsPromotable<unsigned short, unsigned long>::value, "unsigned short -> unsigned long"); - static_assert(TIsPromotable<i64, long long>::value, "i64 -> long long"); - static_assert(!TIsPromotable<ui64, ui8>::value, "ui64 -> ui8"); - static_assert(!TIsPromotable<i64, short>::value, "i64 -> short"); - - enum EEmpty { - }; + +#include <util/generic/deque.h> +#include <util/generic/map.h> +#include <util/generic/typelist.h> +#include <util/generic/vector.h> + +Y_UNIT_TEST_SUITE(TestSerializedEnum) { + Y_UNIT_TEST(RepresentationTypes) { + using namespace NEnumSerializationRuntime::NDetail; + + static_assert(TIsPromotable<int, int>::value, "int -> int"); + static_assert(TIsPromotable<char, int>::value, "char -> int"); + static_assert(TIsPromotable<unsigned short, unsigned long>::value, "unsigned short -> unsigned long"); + static_assert(TIsPromotable<i64, long long>::value, "i64 -> long long"); + static_assert(!TIsPromotable<ui64, ui8>::value, "ui64 -> ui8"); + static_assert(!TIsPromotable<i64, short>::value, "i64 -> short"); + + enum EEmpty { + }; UNIT_ASSERT_C((TTypeList<int, unsigned>::THave<typename TSelectEnumRepresentationType<EEmpty>::TType>::value), "empty enum using signed or unsigned integer underlying type"); - - using TRepresentationTypeList = TTypeList<int, unsigned, long long, unsigned long long>; - - enum class ERegular { - One = 1, - Two = 2, - Five = 5, - }; + + using TRepresentationTypeList = TTypeList<int, unsigned, long long, unsigned long long>; + + enum class ERegular { + One = 1, + Two = 2, + Five = 5, + }; UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<ERegular>::TType>::value); - + enum class ESmall: unsigned char { - Six = 6, - }; + Six = 6, + }; UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<ESmall>::TType>::value); - + enum class EHugeUnsigned: ui64 { - Value = 0, - }; + Value = 0, + }; UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<EHugeUnsigned>::TType>::value); - + enum class EHugeSigned: i64 { - Value = -2, - }; + Value = -2, + }; UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<EHugeSigned>::TType>::value); - } - - Y_UNIT_TEST(MappedArrayView) { + } + + Y_UNIT_TEST(MappedArrayView) { enum class ETestEnum: signed char { - Zero = 0, - One = 1, - Two = 2, - Three = 3, - Four = 4, - Eleven = 11, - }; - const TVector<int> values = {1, 2, 3, 0, 0, 0, 11, 0, 0, 0, 0, 0, 2}; - const auto view = ::NEnumSerializationRuntime::TMappedArrayView<ETestEnum>{values}; - - UNIT_ASSERT_VALUES_EQUAL(view.size(), values.size()); - UNIT_ASSERT_VALUES_EQUAL(view.empty(), false); - UNIT_ASSERT_EQUAL(*view.begin(), ETestEnum::One); - UNIT_ASSERT_EQUAL(view[6], ETestEnum::Eleven); - UNIT_ASSERT_EXCEPTION(view.at(-1), std::out_of_range); - UNIT_ASSERT_VALUES_EQUAL(sizeof(view[4]), sizeof(signed char)); - UNIT_ASSERT_VALUES_EQUAL(sizeof(values[4]), sizeof(int)); - for (const ETestEnum e : view) { - UNIT_ASSERT_UNEQUAL(e, ETestEnum::Four); - } - - const TVector<ETestEnum> typedValues = {ETestEnum::One, ETestEnum::Two, ETestEnum::Three, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Eleven, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Two}; - UNIT_ASSERT_EQUAL(typedValues, view.Materialize()); - - const TDeque<ETestEnum> typedValuesDeque{typedValues.begin(), typedValues.end()}; - UNIT_ASSERT_EQUAL(typedValuesDeque, view.Materialize<TDeque>()); - } - - Y_UNIT_TEST(MappedDictView) { + Zero = 0, + One = 1, + Two = 2, + Three = 3, + Four = 4, + Eleven = 11, + }; + const TVector<int> values = {1, 2, 3, 0, 0, 0, 11, 0, 0, 0, 0, 0, 2}; + const auto view = ::NEnumSerializationRuntime::TMappedArrayView<ETestEnum>{values}; + + UNIT_ASSERT_VALUES_EQUAL(view.size(), values.size()); + UNIT_ASSERT_VALUES_EQUAL(view.empty(), false); + UNIT_ASSERT_EQUAL(*view.begin(), ETestEnum::One); + UNIT_ASSERT_EQUAL(view[6], ETestEnum::Eleven); + UNIT_ASSERT_EXCEPTION(view.at(-1), std::out_of_range); + UNIT_ASSERT_VALUES_EQUAL(sizeof(view[4]), sizeof(signed char)); + UNIT_ASSERT_VALUES_EQUAL(sizeof(values[4]), sizeof(int)); + for (const ETestEnum e : view) { + UNIT_ASSERT_UNEQUAL(e, ETestEnum::Four); + } + + const TVector<ETestEnum> typedValues = {ETestEnum::One, ETestEnum::Two, ETestEnum::Three, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Eleven, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Zero, ETestEnum::Two}; + UNIT_ASSERT_EQUAL(typedValues, view.Materialize()); + + const TDeque<ETestEnum> typedValuesDeque{typedValues.begin(), typedValues.end()}; + UNIT_ASSERT_EQUAL(typedValuesDeque, view.Materialize<TDeque>()); + } + + Y_UNIT_TEST(MappedDictView) { enum class ETestEnum: unsigned short { - Zero = 0, - One = 1, - Two = 2, - Three = 3, - Four = 4, - Eleven = 11, - Fake = (unsigned short)(-1), - }; - const TMap<unsigned, unsigned> map = {{0, 1}, {1, 2}, {2, 4}, {3, 8}, {4, 16}, {11, 2048}}; - const auto view = ::NEnumSerializationRuntime::NDetail::TMappedDictView<ETestEnum, unsigned, unsigned, decltype(map)>{map}; - - UNIT_ASSERT_VALUES_EQUAL(view.size(), map.size()); - UNIT_ASSERT_VALUES_EQUAL(map.empty(), false); - - UNIT_ASSERT_EQUAL(view.begin()->first, ETestEnum::Zero); - UNIT_ASSERT_VALUES_EQUAL(view.begin()->second, 1u); - - UNIT_ASSERT_VALUES_EQUAL(view.contains(ETestEnum::Fake), false); - UNIT_ASSERT_VALUES_EQUAL(view.contains(ETestEnum::Four), true); - - UNIT_ASSERT_EXCEPTION(view.at(ETestEnum::Fake), std::out_of_range); - UNIT_ASSERT_NO_EXCEPTION(view.at(ETestEnum::Eleven)); - - UNIT_ASSERT_VALUES_EQUAL(view.at(ETestEnum::Three), 8u); - - unsigned mask = 0; - unsigned sum = 0; - for (const auto e : view) { - mask |= e.second; - sum += e.second; - } - UNIT_ASSERT_VALUES_EQUAL(mask, 2079); - UNIT_ASSERT_VALUES_EQUAL(sum, 2079); - - const TMap<ETestEnum, unsigned> materialized = view.Materialize<TMap>(); - UNIT_ASSERT_VALUES_EQUAL(materialized.size(), map.size()); - UNIT_ASSERT_VALUES_EQUAL(materialized.at(ETestEnum::Four), 16); - } -} + Zero = 0, + One = 1, + Two = 2, + Three = 3, + Four = 4, + Eleven = 11, + Fake = (unsigned short)(-1), + }; + const TMap<unsigned, unsigned> map = {{0, 1}, {1, 2}, {2, 4}, {3, 8}, {4, 16}, {11, 2048}}; + const auto view = ::NEnumSerializationRuntime::NDetail::TMappedDictView<ETestEnum, unsigned, unsigned, decltype(map)>{map}; + + UNIT_ASSERT_VALUES_EQUAL(view.size(), map.size()); + UNIT_ASSERT_VALUES_EQUAL(map.empty(), false); + + UNIT_ASSERT_EQUAL(view.begin()->first, ETestEnum::Zero); + UNIT_ASSERT_VALUES_EQUAL(view.begin()->second, 1u); + + UNIT_ASSERT_VALUES_EQUAL(view.contains(ETestEnum::Fake), false); + UNIT_ASSERT_VALUES_EQUAL(view.contains(ETestEnum::Four), true); + + UNIT_ASSERT_EXCEPTION(view.at(ETestEnum::Fake), std::out_of_range); + UNIT_ASSERT_NO_EXCEPTION(view.at(ETestEnum::Eleven)); + + UNIT_ASSERT_VALUES_EQUAL(view.at(ETestEnum::Three), 8u); + + unsigned mask = 0; + unsigned sum = 0; + for (const auto e : view) { + mask |= e.second; + sum += e.second; + } + UNIT_ASSERT_VALUES_EQUAL(mask, 2079); + UNIT_ASSERT_VALUES_EQUAL(sum, 2079); + + const TMap<ETestEnum, unsigned> materialized = view.Materialize<TMap>(); + UNIT_ASSERT_VALUES_EQUAL(materialized.size(), map.size()); + UNIT_ASSERT_VALUES_EQUAL(materialized.at(ETestEnum::Four), 16); + } +} diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 69cde785af..fa4ea1f57e 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -20,11 +20,11 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { std::string_view helloWorld("Hello, World!"); TStringBuf fromStringView(helloWorld); UNIT_ASSERT_EQUAL(fromStringView.data(), helloWorld.data()); - UNIT_ASSERT_EQUAL(fromStringView.size(), helloWorld.size()); + UNIT_ASSERT_EQUAL(fromStringView.size(), helloWorld.size()); std::string_view fromStringBuf = fromStringView; UNIT_ASSERT_EQUAL(helloWorld.data(), fromStringBuf.data()); - UNIT_ASSERT_EQUAL(helloWorld.size(), fromStringBuf.size()); + UNIT_ASSERT_EQUAL(helloWorld.size(), fromStringBuf.size()); } Y_UNIT_TEST(TestConstExpr) { @@ -37,16 +37,16 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT_VALUES_EQUAL(str1, str2); UNIT_ASSERT_VALUES_EQUAL(str2, str3); UNIT_ASSERT_VALUES_EQUAL(str1, str3); - - static constexpr std::string_view view1(str1); - UNIT_ASSERT_VALUES_EQUAL(str1, view1); - static_assert(str1.data() == view1.data()); - static_assert(str1.size() == view1.size()); - - static constexpr TStringBuf str4(view1); - UNIT_ASSERT_VALUES_EQUAL(str1, str4); - static_assert(str1.data() == str4.data()); - static_assert(str1.size() == str4.size()); + + static constexpr std::string_view view1(str1); + UNIT_ASSERT_VALUES_EQUAL(str1, view1); + static_assert(str1.data() == view1.data()); + static_assert(str1.size() == view1.size()); + + static constexpr TStringBuf str4(view1); + UNIT_ASSERT_VALUES_EQUAL(str1, str4); + static_assert(str1.data() == str4.data()); + static_assert(str1.size() == str4.size()); } Y_UNIT_TEST(TestAfter) { diff --git a/util/generic/string.h b/util/generic/string.h index 8cd8aa6917..d7ea474d76 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -134,10 +134,10 @@ public: return *this; } - TBasicCharRef& operator=(const TBasicCharRef& other) { - return this->operator=(static_cast<TChar>(other)); - } - + TBasicCharRef& operator=(const TBasicCharRef& other) { + return this->operator=(static_cast<TChar>(other)); + } + /* * WARN: * Though references are copyable types according to the standard, diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index 44bb10bdeb..906363794d 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -1031,19 +1031,19 @@ public: UNIT_ASSERT_VALUES_EQUAL(s0[3], (ui8)'\0'); UNIT_ASSERT_VALUES_EQUAL(s1[3], (ui8)'\0'); UNIT_ASSERT_VALUES_EQUAL(s2[3], (ui8)'\0'); - - /* Assignment one char reference to another results in modification of underlying character */ - { - const char_type dark_eyed[] = {'d', 'a', 'r', 'k', '-', 'e', 'y', 'e', 'd', 0}; - const char_type red_eared[] = {'r', 'e', 'd', '-', 'e', 'a', 'r', 'e', 'd', 0}; - TStringType s0 = dark_eyed; - TStringType s1 = TStringType::Uninitialized(s0.size()); - for (size_t i = 0; i < s1.size(); ++i) { - const size_t j = (3u * (i + 1u) ^ 1u) % s0.size(); - s1[i] = s0[j]; - } - UNIT_ASSERT_VALUES_EQUAL(s1, red_eared); - } + + /* Assignment one char reference to another results in modification of underlying character */ + { + const char_type dark_eyed[] = {'d', 'a', 'r', 'k', '-', 'e', 'y', 'e', 'd', 0}; + const char_type red_eared[] = {'r', 'e', 'd', '-', 'e', 'a', 'r', 'e', 'd', 0}; + TStringType s0 = dark_eyed; + TStringType s1 = TStringType::Uninitialized(s0.size()); + for (size_t i = 0; i < s1.size(); ++i) { + const size_t j = (3u * (i + 1u) ^ 1u) % s0.size(); + s1[i] = s0[j]; + } + UNIT_ASSERT_VALUES_EQUAL(s1, red_eared); + } } #endif diff --git a/util/generic/typetraits.h b/util/generic/typetraits.h index d165bd1a06..202d1c5c6e 100644 --- a/util/generic/typetraits.h +++ b/util/generic/typetraits.h @@ -281,12 +281,12 @@ struct TIsSpecializationOf<T, T<Ts...>>: std::true_type {}; * } */ template <typename... T> -constexpr bool TDependentFalse = false; +constexpr bool TDependentFalse = false; // FIXME: neither nvcc10 nor nvcc11 support using auto in this context #if defined(__NVCC__) template <size_t Value> -constexpr bool TValueDependentFalse = false; +constexpr bool TValueDependentFalse = false; #else template <auto... Values> constexpr bool TValueDependentFalse = false; diff --git a/util/generic/typetraits_ut.cpp b/util/generic/typetraits_ut.cpp index e7571c75ec..fe2ee6abe3 100644 --- a/util/generic/typetraits_ut.cpp +++ b/util/generic/typetraits_ut.cpp @@ -461,8 +461,8 @@ static_assert(!TIsSpecializationOf<std::pair, std::vector<int>>::value, ""); static_assert(TIsIterable<std::vector<int>>::value, ""); static_assert(!TIsIterable<int>::value, ""); static_assert(TIsIterable<int[42]>::value, ""); - -// test for TDependentFalse -static_assert(TDependentFalse<int> == false); -static_assert(TDependentFalse<TNonPodClass> == false); -static_assert(TValueDependentFalse<0x1000> == false); + +// test for TDependentFalse +static_assert(TDependentFalse<int> == false); +static_assert(TDependentFalse<TNonPodClass> == false); +static_assert(TValueDependentFalse<0x1000> == false); diff --git a/util/generic/ut/ya.make b/util/generic/ut/ya.make index 6eaf24cc5f..1e0bedb780 100644 --- a/util/generic/ut/ya.make +++ b/util/generic/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) FORK_TESTS() @@ -35,7 +35,7 @@ SRCS( generic/overloaded_ut.cpp generic/ptr_ut.cpp generic/queue_ut.cpp - generic/serialized_enum_ut.cpp + generic/serialized_enum_ut.cpp generic/set_ut.cpp generic/singleton_ut.cpp generic/size_literals_ut.cpp diff --git a/util/generic/utility.h b/util/generic/utility.h index 43b98eeafc..4be1373a7f 100644 --- a/util/generic/utility.h +++ b/util/generic/utility.h @@ -6,7 +6,7 @@ template <class T> static constexpr const T& Min(const T& l, const T& r) { - return r < l ? r : l; + return r < l ? r : l; } template <typename T, typename... Args> @@ -16,7 +16,7 @@ static constexpr const T& Min(const T& a, const T& b, const Args&... args) { template <class T> static constexpr const T& Max(const T& l, const T& r) { - return l < r ? r : l; + return l < r ? r : l; } template <typename T, typename... Args> diff --git a/util/generic/utility_ut.cpp b/util/generic/utility_ut.cpp index 8e9d5afff9..1e106c651f 100644 --- a/util/generic/utility_ut.cpp +++ b/util/generic/utility_ut.cpp @@ -23,16 +23,16 @@ private: TTest& operator=(const TTest&); }; -struct TUnorderedTag { - TStringBuf Tag; -}; - -static bool operator<(const TUnorderedTag, const TUnorderedTag) { - return false; -} - -static bool operator>(const TUnorderedTag, const TUnorderedTag) = delete; - +struct TUnorderedTag { + TStringBuf Tag; +}; + +static bool operator<(const TUnorderedTag, const TUnorderedTag) { + return false; +} + +static bool operator>(const TUnorderedTag, const TUnorderedTag) = delete; + Y_UNIT_TEST_SUITE(TUtilityTest) { Y_UNIT_TEST(TestSwapPrimitive) { @@ -60,7 +60,7 @@ Y_UNIT_TEST_SUITE(TUtilityTest) { static_assert(Max(10, 3, 8) == 10, "Max doesn't work"); UNIT_ASSERT_EQUAL(Min(10, 3, 8), 3); UNIT_ASSERT_EQUAL(Max(3.5, 4.2, 8.1, 99.025, 0.33, 29.0), 99.025); - + UNIT_ASSERT_VALUES_EQUAL(Min(TUnorderedTag{"first"}, TUnorderedTag{"second"}).Tag, "first"); UNIT_ASSERT_VALUES_EQUAL(Max(TUnorderedTag{"first"}, TUnorderedTag{"second"}).Tag, "first"); UNIT_ASSERT_VALUES_EQUAL(Min(TUnorderedTag{"first"}, TUnorderedTag{"second"}, TUnorderedTag{"third"}).Tag, "first"); diff --git a/util/generic/vector_ut.cpp b/util/generic/vector_ut.cpp index 0f6b4037a0..673be2fb20 100644 --- a/util/generic/vector_ut.cpp +++ b/util/generic/vector_ut.cpp @@ -553,9 +553,9 @@ private: vec.crop(1); // Should not require default constructor UNIT_ASSERT(vec.size() == 1); UNIT_ASSERT(vec[0].Val == 42); - vec.crop(50); // Does nothing if new size is greater than the current size() - UNIT_ASSERT(vec.size() == 1); - UNIT_ASSERT(vec[0].Val == 42); + vec.crop(50); // Does nothing if new size is greater than the current size() + UNIT_ASSERT(vec.size() == 1); + UNIT_ASSERT(vec[0].Val == 42); } void TestYResize() { diff --git a/util/generic/xrange.h b/util/generic/xrange.h index 5fc8c82912..4d9c309001 100644 --- a/util/generic/xrange.h +++ b/util/generic/xrange.h @@ -85,12 +85,12 @@ namespace NPrivate { return TIterator(Value - b); } - template <typename IntType> - TIterator& operator-=(const IntType& b) noexcept { - Value -= b; - return *this; - } - + template <typename IntType> + TIterator& operator-=(const IntType& b) noexcept { + Value -= b; + return *this; + } + constexpr bool operator<(const TIterator& b) const noexcept { return Value < b.Value; } @@ -175,31 +175,31 @@ namespace NPrivate { } constexpr TDiff operator-(const TIterator& b) const noexcept { - return (Value_ - b.Value_) / Parent_->Step_; + return (Value_ - b.Value_) / Parent_->Step_; } template <typename IntType> constexpr TIterator operator+(const IntType& b) const noexcept { - return TIterator(*this) += b; + return TIterator(*this) += b; } template <typename IntType> TIterator& operator+=(const IntType& b) noexcept { - Value_ += b * Parent_->Step_; + Value_ += b * Parent_->Step_; return *this; } template <typename IntType> constexpr TIterator operator-(const IntType& b) const noexcept { - return TIterator(*this) -= b; - } - - template <typename IntType> - TIterator& operator-=(const IntType& b) noexcept { - Value_ -= b * Parent_->Step_; - return *this; + return TIterator(*this) -= b; } + template <typename IntType> + TIterator& operator-=(const IntType& b) noexcept { + Value_ -= b * Parent_->Step_; + return *this; + } + private: T Value_; const TSteppedXRange* Parent_; diff --git a/util/generic/xrange_ut.cpp b/util/generic/xrange_ut.cpp index 8106da03e7..c41d47c9d1 100644 --- a/util/generic/xrange_ut.cpp +++ b/util/generic/xrange_ut.cpp @@ -1,10 +1,10 @@ #include "xrange.h" #include "algorithm.h" -#include "maybe.h" +#include "maybe.h" #include "vector.h" #include <library/cpp/testing/unittest/registar.h> -#include <util/string/builder.h> +#include <util/string/builder.h> Y_UNIT_TEST_SUITE(XRange) { void TestXRangeImpl(size_t begin, size_t end) { @@ -156,62 +156,62 @@ Y_UNIT_TEST_SUITE(XRange) { TestEmptyRanges(emptySteppedRanges); } - - template <class TRange> - static void TestIteratorDifferenceImpl(TRange range, int a, int b, TMaybe<int> step) { - auto fmtCase = [&]() -> TString { return TStringBuilder() << "xrange(" << a << ", " << b << (step ? ", " + ToString(*step) : TString{}) << ")"; }; - auto begin = std::begin(range); - auto end = std::end(range); - auto distance = end - begin; - UNIT_ASSERT_VALUES_EQUAL_C(range.size(), distance, fmtCase()); - UNIT_ASSERT_EQUAL_C(end, begin + distance, fmtCase()); - } - - Y_UNIT_TEST(IteratorDifference) { - for (int a = -20; a <= 20; ++a) { - for (int b = -20; b <= 20; ++b) { - for (int step = -25; step <= 25; ++step) { - if (step != 0) { - TestIteratorDifferenceImpl(xrange(a, b, step), a, b, step); - } - } - TestIteratorDifferenceImpl(xrange(a, b), a, b, Nothing()); - } - } - } - - Y_UNIT_TEST(Advance) { - { - auto range = xrange(30, 160, 7); - auto it = std::begin(range); - it += 5; - UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 5), *it); - UNIT_ASSERT_VALUES_EQUAL(65, *it); - it -= 2; - UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 3), *it); - UNIT_ASSERT_VALUES_EQUAL(51, *it); - std::advance(it, 10); - UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 13), *it); - UNIT_ASSERT_VALUES_EQUAL(121, *it); - std::advance(it, -5); - UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 8), *it); - UNIT_ASSERT_VALUES_EQUAL(86, *it); - } - { - auto range = xrange(-20, 100); - auto it = std::begin(range); - it += 5; - UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 5), *it); - UNIT_ASSERT_VALUES_EQUAL(-15, *it); - it -= 2; - UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 3), *it); - UNIT_ASSERT_VALUES_EQUAL(-17, *it); - std::advance(it, 30); - UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 33), *it); - UNIT_ASSERT_VALUES_EQUAL(13, *it); - std::advance(it, -8); - UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 25), *it); - UNIT_ASSERT_VALUES_EQUAL(5, *it); - } - } + + template <class TRange> + static void TestIteratorDifferenceImpl(TRange range, int a, int b, TMaybe<int> step) { + auto fmtCase = [&]() -> TString { return TStringBuilder() << "xrange(" << a << ", " << b << (step ? ", " + ToString(*step) : TString{}) << ")"; }; + auto begin = std::begin(range); + auto end = std::end(range); + auto distance = end - begin; + UNIT_ASSERT_VALUES_EQUAL_C(range.size(), distance, fmtCase()); + UNIT_ASSERT_EQUAL_C(end, begin + distance, fmtCase()); + } + + Y_UNIT_TEST(IteratorDifference) { + for (int a = -20; a <= 20; ++a) { + for (int b = -20; b <= 20; ++b) { + for (int step = -25; step <= 25; ++step) { + if (step != 0) { + TestIteratorDifferenceImpl(xrange(a, b, step), a, b, step); + } + } + TestIteratorDifferenceImpl(xrange(a, b), a, b, Nothing()); + } + } + } + + Y_UNIT_TEST(Advance) { + { + auto range = xrange(30, 160, 7); + auto it = std::begin(range); + it += 5; + UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 5), *it); + UNIT_ASSERT_VALUES_EQUAL(65, *it); + it -= 2; + UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 3), *it); + UNIT_ASSERT_VALUES_EQUAL(51, *it); + std::advance(it, 10); + UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 13), *it); + UNIT_ASSERT_VALUES_EQUAL(121, *it); + std::advance(it, -5); + UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 8), *it); + UNIT_ASSERT_VALUES_EQUAL(86, *it); + } + { + auto range = xrange(-20, 100); + auto it = std::begin(range); + it += 5; + UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 5), *it); + UNIT_ASSERT_VALUES_EQUAL(-15, *it); + it -= 2; + UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 3), *it); + UNIT_ASSERT_VALUES_EQUAL(-17, *it); + std::advance(it, 30); + UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 33), *it); + UNIT_ASSERT_VALUES_EQUAL(13, *it); + std::advance(it, -8); + UNIT_ASSERT_VALUES_EQUAL(*(std::begin(range) + 25), *it); + UNIT_ASSERT_VALUES_EQUAL(5, *it); + } + } } diff --git a/util/generic/ya.make b/util/generic/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/generic/ya.make +++ b/util/generic/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/generic/yexception.cpp b/util/generic/yexception.cpp index 2ce6c4369d..46dc3de712 100644 --- a/util/generic/yexception.cpp +++ b/util/generic/yexception.cpp @@ -1,4 +1,4 @@ -#include "bt_exception.h" +#include "bt_exception.h" #include "yexception.h" #include <util/system/backtrace.h> @@ -112,11 +112,11 @@ void fputs(const std::exception& e, FILE* f) { message[len] = 0; fputs(message, f); } - -void ::NPrivate::ThrowYException(const ::NPrivate::TSimpleExceptionMessage& sm) { - throw sm.Location + yexception() << sm.Message; -} - -void ::NPrivate::ThrowYExceptionWithBacktrace(const ::NPrivate::TSimpleExceptionMessage& sm) { - throw sm.Location + TWithBackTrace<yexception>() << sm.Message; -} + +void ::NPrivate::ThrowYException(const ::NPrivate::TSimpleExceptionMessage& sm) { + throw sm.Location + yexception() << sm.Message; +} + +void ::NPrivate::ThrowYExceptionWithBacktrace(const ::NPrivate::TSimpleExceptionMessage& sm) { + throw sm.Location + TWithBackTrace<yexception>() << sm.Message; +} diff --git a/util/generic/yexception.h b/util/generic/yexception.h index b0c604e8c4..b7e93c06da 100644 --- a/util/generic/yexception.h +++ b/util/generic/yexception.h @@ -1,6 +1,6 @@ #pragma once -#include "bt_exception.h" +#include "bt_exception.h" #include "strbuf.h" #include "string.h" #include "utility.h" @@ -140,18 +140,18 @@ struct TBadCastException: public virtual TBadArgumentException { #define ythrow throw __LOCATION__ + -namespace NPrivate { - /// Encapsulates data for one of the most common case in which - /// exception message contists of single constant string - struct TSimpleExceptionMessage { - TSourceLocation Location; - TStringBuf Message; - }; - +namespace NPrivate { + /// Encapsulates data for one of the most common case in which + /// exception message contists of single constant string + struct TSimpleExceptionMessage { + TSourceLocation Location; + TStringBuf Message; + }; + [[noreturn]] void ThrowYException(const TSimpleExceptionMessage& sm); - [[noreturn]] void ThrowYExceptionWithBacktrace(const TSimpleExceptionMessage& sm); -} - + [[noreturn]] void ThrowYExceptionWithBacktrace(const TSimpleExceptionMessage& sm); +} + void fputs(const std::exception& e, FILE* f = stderr); TString CurrentExceptionMessage(); @@ -182,24 +182,24 @@ TString FormatExc(const std::exception& exception); } \ } while (false) -/// @def Y_ENSURE_SIMPLE -/// This macro works like the Y_ENSURE, but requires the second argument to be a constant string view. -/// Should not be used directly. -#define Y_ENSURE_SIMPLE(CONDITION, MESSAGE, THROW_FUNCTION) \ - do { \ - if (Y_UNLIKELY(!(CONDITION))) { \ - /* use variable to guarantee evaluation at compile time */ \ - static constexpr const ::NPrivate::TSimpleExceptionMessage __SIMPLE_EXCEPTION_MESSAGE{__LOCATION__, (MESSAGE)}; \ - THROW_FUNCTION(__SIMPLE_EXCEPTION_MESSAGE); \ - } \ - } while (false) - +/// @def Y_ENSURE_SIMPLE +/// This macro works like the Y_ENSURE, but requires the second argument to be a constant string view. +/// Should not be used directly. +#define Y_ENSURE_SIMPLE(CONDITION, MESSAGE, THROW_FUNCTION) \ + do { \ + if (Y_UNLIKELY(!(CONDITION))) { \ + /* use variable to guarantee evaluation at compile time */ \ + static constexpr const ::NPrivate::TSimpleExceptionMessage __SIMPLE_EXCEPTION_MESSAGE{__LOCATION__, (MESSAGE)}; \ + THROW_FUNCTION(__SIMPLE_EXCEPTION_MESSAGE); \ + } \ + } while (false) + #define Y_ENSURE_IMPL_1(CONDITION) Y_ENSURE_SIMPLE(CONDITION, ::TStringBuf("Condition violated: `" Y_STRINGIZE(CONDITION) "'"), ::NPrivate::ThrowYException) #define Y_ENSURE_IMPL_2(CONDITION, MESSAGE) Y_ENSURE_EX(CONDITION, yexception() << MESSAGE) #define Y_ENSURE_BT_IMPL_1(CONDITION) Y_ENSURE_SIMPLE(CONDITION, ::TStringBuf("Condition violated: `" Y_STRINGIZE(CONDITION) "'"), ::NPrivate::ThrowYExceptionWithBacktrace) -#define Y_ENSURE_BT_IMPL_2(CONDITION, MESSAGE) Y_ENSURE_EX(CONDITION, TWithBackTrace<yexception>() << MESSAGE) - +#define Y_ENSURE_BT_IMPL_2(CONDITION, MESSAGE) Y_ENSURE_EX(CONDITION, TWithBackTrace<yexception>() << MESSAGE) + /** * @def Y_ENSURE * @@ -214,18 +214,18 @@ TString FormatExc(const std::exception& exception); * @endcode */ #define Y_ENSURE(...) Y_PASS_VA_ARGS(Y_MACRO_IMPL_DISPATCHER_2(__VA_ARGS__, Y_ENSURE_IMPL_2, Y_ENSURE_IMPL_1)(__VA_ARGS__)) - -/** - * @def Y_ENSURE_BT - * - * This macro is inteded to use as a shortcut for `if () { throw TWithBackTrace<yexception>() << "message"; }`. - * - * @code - * void DoSomethingLovely(const int x, const int y) { - * Y_ENSURE_BT(x > y, "`x` must be greater than `y`"); - * Y_ENSURE_BT(x > y); // if you are too lazy - * // actually doing something nice here - * } - * @endcode - */ -#define Y_ENSURE_BT(...) Y_PASS_VA_ARGS(Y_MACRO_IMPL_DISPATCHER_2(__VA_ARGS__, Y_ENSURE_BT_IMPL_2, Y_ENSURE_BT_IMPL_1)(__VA_ARGS__)) + +/** + * @def Y_ENSURE_BT + * + * This macro is inteded to use as a shortcut for `if () { throw TWithBackTrace<yexception>() << "message"; }`. + * + * @code + * void DoSomethingLovely(const int x, const int y) { + * Y_ENSURE_BT(x > y, "`x` must be greater than `y`"); + * Y_ENSURE_BT(x > y); // if you are too lazy + * // actually doing something nice here + * } + * @endcode + */ +#define Y_ENSURE_BT(...) Y_PASS_VA_ARGS(Y_MACRO_IMPL_DISPATCHER_2(__VA_ARGS__, Y_ENSURE_BT_IMPL_2, Y_ENSURE_BT_IMPL_1)(__VA_ARGS__)) diff --git a/util/generic/yexception_ut.cpp b/util/generic/yexception_ut.cpp index cb3e29fed8..732aa12656 100644 --- a/util/generic/yexception_ut.cpp +++ b/util/generic/yexception_ut.cpp @@ -10,7 +10,7 @@ static inline void Throw2DontMove() { #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/algorithm.h> +#include <util/generic/algorithm.h> #include <util/memory/tempbuf.h> #include <util/random/mersenne.h> #include <util/stream/output.h> @@ -32,9 +32,9 @@ static IOutputStream* OUTS = nullptr; namespace NOuter::NInner { void Compare10And20() { Y_ENSURE(10 > 20); - } -} - + } +} + class TExceptionTest: public TTestBase { UNIT_TEST_SUITE(TExceptionTest); UNIT_TEST_EXCEPTION(TestException, yexception) @@ -46,8 +46,8 @@ class TExceptionTest: public TTestBase { UNIT_TEST(TestVirtualInheritance) UNIT_TEST(TestMixedCode) UNIT_TEST(TestBackTrace) - UNIT_TEST(TestEnsureWithBackTrace1) - UNIT_TEST(TestEnsureWithBackTrace2) + UNIT_TEST(TestEnsureWithBackTrace1) + UNIT_TEST(TestEnsureWithBackTrace2) UNIT_TEST(TestRethrowAppend) UNIT_TEST(TestMacroOverload) UNIT_TEST(TestMessageCrop) @@ -86,48 +86,48 @@ private: UNIT_ASSERT(false); } - template <typename TException> - static void EnsureCurrentExceptionHasBackTrace() { - auto exceptionPtr = std::current_exception(); - UNIT_ASSERT_C(exceptionPtr != nullptr, "No exception"); - try { - std::rethrow_exception(exceptionPtr); - } catch (const TException& e) { - const TBackTrace* bt = e.BackTrace(); - UNIT_ASSERT(bt != nullptr); - } catch (...) { - UNIT_ASSERT_C(false, "Unexpected exception type"); - } - }; - - inline void TestEnsureWithBackTrace1() { - try { - Y_ENSURE_BT(4 > 6); - } catch (...) { - const TString msg = CurrentExceptionMessage(); - UNIT_ASSERT(msg.Contains("4 > 6")); - UNIT_ASSERT(msg.Contains("\n")); - EnsureCurrentExceptionHasBackTrace<yexception>(); - return; - } - UNIT_ASSERT(false); - } - - inline void TestEnsureWithBackTrace2() { - try { + template <typename TException> + static void EnsureCurrentExceptionHasBackTrace() { + auto exceptionPtr = std::current_exception(); + UNIT_ASSERT_C(exceptionPtr != nullptr, "No exception"); + try { + std::rethrow_exception(exceptionPtr); + } catch (const TException& e) { + const TBackTrace* bt = e.BackTrace(); + UNIT_ASSERT(bt != nullptr); + } catch (...) { + UNIT_ASSERT_C(false, "Unexpected exception type"); + } + }; + + inline void TestEnsureWithBackTrace1() { + try { + Y_ENSURE_BT(4 > 6); + } catch (...) { + const TString msg = CurrentExceptionMessage(); + UNIT_ASSERT(msg.Contains("4 > 6")); + UNIT_ASSERT(msg.Contains("\n")); + EnsureCurrentExceptionHasBackTrace<yexception>(); + return; + } + UNIT_ASSERT(false); + } + + inline void TestEnsureWithBackTrace2() { + try { Y_ENSURE_BT(4 > 6, "custom " << "message"); - } catch (...) { - const TString msg = CurrentExceptionMessage(); - UNIT_ASSERT(!msg.Contains("4 > 6")); - UNIT_ASSERT(msg.Contains("custom message")); - UNIT_ASSERT(msg.Contains("\n")); - EnsureCurrentExceptionHasBackTrace<yexception>(); - return; - } - UNIT_ASSERT(false); - } - + } catch (...) { + const TString msg = CurrentExceptionMessage(); + UNIT_ASSERT(!msg.Contains("4 > 6")); + UNIT_ASSERT(msg.Contains("custom message")); + UNIT_ASSERT(msg.Contains("\n")); + EnsureCurrentExceptionHasBackTrace<yexception>(); + return; + } + UNIT_ASSERT(false); + } + inline void TestVirtualInheritance() { TStringStream ss; @@ -273,12 +273,12 @@ private: } catch (const yexception& e) { UNIT_ASSERT(e.AsStrBuf().Contains("exception message to search for")); } - - try { - NOuter::NInner::Compare10And20(); - } catch (const yexception& e) { - UNIT_ASSERT(e.AsStrBuf().Contains("10 > 20")); - } + + try { + NOuter::NInner::Compare10And20(); + } catch (const yexception& e) { + UNIT_ASSERT(e.AsStrBuf().Contains("10 > 20")); + } } void TestMessageCrop() { diff --git a/util/memory/addstorage.h b/util/memory/addstorage.h index 597c73a988..81c8260b9d 100644 --- a/util/memory/addstorage.h +++ b/util/memory/addstorage.h @@ -5,40 +5,40 @@ #include <new> -namespace NPrivate { - class TAdditionalStorageInfo { +namespace NPrivate { + class TAdditionalStorageInfo { public: - constexpr TAdditionalStorageInfo(size_t length) noexcept - : Length_(length) - { + constexpr TAdditionalStorageInfo(size_t length) noexcept + : Length_(length) + { } - constexpr size_t Length() const noexcept { - return Length_; + constexpr size_t Length() const noexcept { + return Length_; } private: - size_t Length_; + size_t Length_; }; -} - -template <class T> -class alignas(::NPrivate::TAdditionalStorageInfo) TAdditionalStorage { - using TInfo = ::NPrivate::TAdditionalStorageInfo; +} +template <class T> +class alignas(::NPrivate::TAdditionalStorageInfo) TAdditionalStorage { + using TInfo = ::NPrivate::TAdditionalStorageInfo; + public: inline TAdditionalStorage() noexcept = default; inline ~TAdditionalStorage() = default; inline void* operator new(size_t len1, size_t len2) { - static_assert(alignof(T) >= alignof(TInfo)); - Y_ASSERT(len1 == sizeof(T)); - void* data = ::operator new(CombinedSizeOfInstanceWithTInfo() + len2); - void* info = InfoPtr(static_cast<T*>(data)); - Y_UNUSED(new (info) TInfo(len2)); + static_assert(alignof(T) >= alignof(TInfo)); + Y_ASSERT(len1 == sizeof(T)); + void* data = ::operator new(CombinedSizeOfInstanceWithTInfo() + len2); + void* info = InfoPtr(static_cast<T*>(data)); + Y_UNUSED(new (info) TInfo(len2)); - return data; + return data; } inline void operator delete(void* ptr) noexcept { @@ -58,36 +58,36 @@ public: } inline void* AdditionalData() const noexcept { - return (char*)(static_cast<const T*>(this)) + CombinedSizeOfInstanceWithTInfo(); + return (char*)(static_cast<const T*>(this)) + CombinedSizeOfInstanceWithTInfo(); } static inline T* ObjectFromData(void* data) noexcept { - return reinterpret_cast<T*>(static_cast<char*>(data) - CombinedSizeOfInstanceWithTInfo()); + return reinterpret_cast<T*>(static_cast<char*>(data) - CombinedSizeOfInstanceWithTInfo()); } inline size_t AdditionalDataLength() const noexcept { - return InfoPtr(static_cast<const T*>(this))->Length(); + return InfoPtr(static_cast<const T*>(this))->Length(); } private: static inline void DoDelete(void* ptr) noexcept { - TInfo* info = InfoPtr(static_cast<T*>(ptr)); + TInfo* info = InfoPtr(static_cast<T*>(ptr)); info->~TInfo(); - ::operator delete(ptr); - } - - static constexpr size_t CombinedSizeOfInstanceWithTInfo() noexcept { - return AlignUp(sizeof(T), alignof(TInfo)) + sizeof(TInfo); - } - - static constexpr TInfo* InfoPtr(T* instance) noexcept { - return const_cast<TInfo*>(InfoPtr(static_cast<const T*>(instance))); - } - - static constexpr const TInfo* InfoPtr(const T* instance) noexcept { - return reinterpret_cast<const TInfo*>(reinterpret_cast<const char*>(instance) + CombinedSizeOfInstanceWithTInfo() - sizeof(TInfo)); + ::operator delete(ptr); } + static constexpr size_t CombinedSizeOfInstanceWithTInfo() noexcept { + return AlignUp(sizeof(T), alignof(TInfo)) + sizeof(TInfo); + } + + static constexpr TInfo* InfoPtr(T* instance) noexcept { + return const_cast<TInfo*>(InfoPtr(static_cast<const T*>(instance))); + } + + static constexpr const TInfo* InfoPtr(const T* instance) noexcept { + return reinterpret_cast<const TInfo*>(reinterpret_cast<const char*>(instance) + CombinedSizeOfInstanceWithTInfo() - sizeof(TInfo)); + } + private: - void* operator new(size_t) = delete; + void* operator new(size_t) = delete; }; diff --git a/util/memory/benchmark/pool/metrics/ya.make b/util/memory/benchmark/pool/metrics/ya.make index c671bc5c1c..5dcd3f8343 100644 --- a/util/memory/benchmark/pool/metrics/ya.make +++ b/util/memory/benchmark/pool/metrics/ya.make @@ -1,5 +1,5 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/memory/benchmark/pool/ya.make b/util/memory/benchmark/pool/ya.make index 5f4f7d3f15..85199aa3af 100644 --- a/util/memory/benchmark/pool/ya.make +++ b/util/memory/benchmark/pool/ya.make @@ -1,5 +1,5 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) Y_BENCHMARK() diff --git a/util/memory/benchmark/ya.make b/util/memory/benchmark/ya.make index 2259b9434e..0fe18aae9d 100644 --- a/util/memory/benchmark/ya.make +++ b/util/memory/benchmark/ya.make @@ -1,5 +1,5 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) RECURSE( pool diff --git a/util/memory/blob.h b/util/memory/blob.h index 20c02a68df..d13b2d3db4 100644 --- a/util/memory/blob.h +++ b/util/memory/blob.h @@ -74,12 +74,12 @@ public: Ref(); } - TBlob(TBlob&& r) noexcept - : TBlob() - { - this->Swap(r); - } - + TBlob(TBlob&& r) noexcept + : TBlob() + { + this->Swap(r); + } + inline TBlob(const void* data, size_t length, TBase* base) noexcept : S_(data, length, base) { diff --git a/util/memory/ut/ya.make b/util/memory/ut/ya.make index d3a988617d..69ec434d04 100644 --- a/util/memory/ut/ya.make +++ b/util/memory/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( memory/addstorage_ut.cpp diff --git a/util/memory/ya.make b/util/memory/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/memory/ya.make +++ b/util/memory/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/network/ut/ya.make b/util/network/ut/ya.make index 1ba03e167c..d7efebea81 100644 --- a/util/network/ut/ya.make +++ b/util/network/ut/ya.make @@ -3,7 +3,7 @@ UNITTEST_FOR(util) REQUIREMENTS(network:full) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PEERDIR( library/cpp/threading/future diff --git a/util/network/ya.make b/util/network/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/network/ya.make +++ b/util/network/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/random/benchmark/prng/metrics/ya.make b/util/random/benchmark/prng/metrics/ya.make index 1f56aac0bd..35f405950e 100644 --- a/util/random/benchmark/prng/metrics/ya.make +++ b/util/random/benchmark/prng/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/random/benchmark/prng/ya.make b/util/random/benchmark/prng/ya.make index 976977014f..7ba0dcee94 100644 --- a/util/random/benchmark/prng/ya.make +++ b/util/random/benchmark/prng/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) Y_BENCHMARK() diff --git a/util/random/benchmark/ya.make b/util/random/benchmark/ya.make index 7d753ae6e7..0836e6a93c 100644 --- a/util/random/benchmark/ya.make +++ b/util/random/benchmark/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) RECURSE( prng diff --git a/util/random/ut/ya.make b/util/random/ut/ya.make index 5080b339de..93e3923c11 100644 --- a/util/random/ut/ya.make +++ b/util/random/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( random/common_ops_ut.cpp diff --git a/util/random/ya.make b/util/random/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/random/ya.make +++ b/util/random/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/stream/ut/ya.make b/util/stream/ut/ya.make index f0176dd7b4..bf7e9a42c5 100644 --- a/util/stream/ut/ya.make +++ b/util/stream/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( stream/aligned_ut.cpp diff --git a/util/stream/ya.make b/util/stream/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/stream/ya.make +++ b/util/stream/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/string/benchmark/float_to_string/metrics/ya.make b/util/string/benchmark/float_to_string/metrics/ya.make index 4b8c4cc07d..37581c70bd 100644 --- a/util/string/benchmark/float_to_string/metrics/ya.make +++ b/util/string/benchmark/float_to_string/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/string/benchmark/join/metrics/ya.make b/util/string/benchmark/join/metrics/ya.make index 08ff3a149f..b990afb922 100644 --- a/util/string/benchmark/join/metrics/ya.make +++ b/util/string/benchmark/join/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( salmin g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/string/benchmark/join/ya.make b/util/string/benchmark/join/ya.make index dfcc1d264e..4ea53d87cb 100644 --- a/util/string/benchmark/join/ya.make +++ b/util/string/benchmark/join/ya.make @@ -4,7 +4,7 @@ OWNER( salmin g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( main.cpp diff --git a/util/string/benchmark/subst_global/metrics/ya.make b/util/string/benchmark/subst_global/metrics/ya.make index d8c30ad460..d1fd54176c 100644 --- a/util/string/benchmark/subst_global/metrics/ya.make +++ b/util/string/benchmark/subst_global/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/string/benchmark/ya.make b/util/string/benchmark/ya.make index 266b53c7b3..0627a50e3c 100644 --- a/util/string/benchmark/ya.make +++ b/util/string/benchmark/ya.make @@ -2,7 +2,7 @@ OWNER( g:util yazevnul ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) RECURSE( ascii diff --git a/util/string/fuzzing/collapse/ya.make b/util/string/fuzzing/collapse/ya.make index b8614f6411..9c3ee10b1d 100644 --- a/util/string/fuzzing/collapse/ya.make +++ b/util/string/fuzzing/collapse/ya.make @@ -4,7 +4,7 @@ OWNER( pg g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( main.cpp diff --git a/util/string/fuzzing/escape_c/ya.make b/util/string/fuzzing/escape_c/ya.make index 61e64ac9de..be1a25e43c 100644 --- a/util/string/fuzzing/escape_c/ya.make +++ b/util/string/fuzzing/escape_c/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) FUZZ() diff --git a/util/string/fuzzing/strtod/ya.make b/util/string/fuzzing/strtod/ya.make index b8614f6411..9c3ee10b1d 100644 --- a/util/string/fuzzing/strtod/ya.make +++ b/util/string/fuzzing/strtod/ya.make @@ -4,7 +4,7 @@ OWNER( pg g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( main.cpp diff --git a/util/string/fuzzing/ya.make b/util/string/fuzzing/ya.make index 617e0f2b1d..b08f4d2b6c 100644 --- a/util/string/fuzzing/ya.make +++ b/util/string/fuzzing/ya.make @@ -2,7 +2,7 @@ OWNER( g:util pg ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) RECURSE( collapse diff --git a/util/string/join.h b/util/string/join.h index b166fad1f3..62ace2fb17 100644 --- a/util/string/join.h +++ b/util/string/join.h @@ -169,9 +169,9 @@ TUtf32String JoinRange(wchar32 delim, const TIter beg, const TIter end) { template <typename TCharType, typename TContainer> inline TBasicString<TCharType> JoinSeq(std::basic_string_view<TCharType> delim, const TContainer& data) { - using std::begin; - using std::end; - return JoinRange(delim, begin(data), end(data)); + using std::begin; + using std::end; + return JoinRange(delim, begin(data), end(data)); } template <typename TCharType, typename TContainer> diff --git a/util/string/join_ut.cpp b/util/string/join_ut.cpp index 3ed2b2459c..645a235ad6 100644 --- a/util/string/join_ut.cpp +++ b/util/string/join_ut.cpp @@ -35,7 +35,7 @@ Y_UNIT_TEST_SUITE(JoinStringTest) { UNIT_ASSERT_EQUAL(JoinSeq(" ", {}), ""); UNIT_ASSERT_EQUAL(JoinSeq(" ", {42}), "42"); UNIT_ASSERT_EQUAL(JoinSeq(" ", {1, 2, 3}), "1 2 3"); - UNIT_ASSERT_VALUES_EQUAL(JoinSeq(" ", v), "1 2 3"); + UNIT_ASSERT_VALUES_EQUAL(JoinSeq(" ", v), "1 2 3"); } Y_UNIT_TEST(StrContainerItems) { @@ -143,9 +143,9 @@ Y_UNIT_TEST_SUITE(JoinStringTest) { stream << MakeRangeJoiner(" ", std::initializer_list<TString>{vstring[0], vstring[1], vstring[2]}); UNIT_ASSERT_EQUAL(stream.Str(), result); } - - // c-style array - UNIT_ASSERT_VALUES_EQUAL(JoinSeq(" ", v), result); + + // c-style array + UNIT_ASSERT_VALUES_EQUAL(JoinSeq(" ", v), result); } Y_UNIT_TEST(CustomToString) { diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..626ad69cda 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -508,11 +508,11 @@ namespace NStringSplitPrivate { *dst = src; } - template <class T> - inline void DoFromString(const T& src, decltype(std::ignore)* dst) noexcept { - *dst = src; - } - + template <class T> + inline void DoFromString(const T& src, decltype(std::ignore)* dst) noexcept { + *dst = src; + } + template <class Src, class Dst> inline Y_WARN_UNUSED_RESULT bool TryDoFromString(const Src& src, Dst* dst) noexcept { return ::TryFromString(src, *dst); @@ -524,12 +524,12 @@ namespace NStringSplitPrivate { return true; } - template <class T> - inline Y_WARN_UNUSED_RESULT bool TryDoFromString(const T& src, decltype(std::ignore)* dst) noexcept { - *dst = src; - return true; - } - + template <class T> + inline Y_WARN_UNUSED_RESULT bool TryDoFromString(const T& src, decltype(std::ignore)* dst) noexcept { + *dst = src; + return true; + } + /** * Consumer that places provided elements into a container. Not using * `emplace(iterator)` for efficiency. diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index 43e59f2d75..3ec9b302be 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -150,7 +150,7 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { TestDelimiterOnRange<TContainerConvertingConsumer>(good, data.data(), data.end(), delim); } - Y_UNIT_TEST(TestCharSkipEmpty) { + Y_UNIT_TEST(TestCharSkipEmpty) { TString data("qw ab qwabcab "); TString canonic[] = {"qw", "ab", "qwabcab"}; TVector<TString> good(canonic, canonic + 3); @@ -559,14 +559,14 @@ Y_UNIT_TEST_SUITE(StringSplitter) { UNIT_ASSERT_EXCEPTION(StringSplitter("1 2 3").Split(' ').CollectInto(&a, &a), yexception); } - Y_UNIT_TEST(TestSplitStringWithIgnore) { - TStringBuf s; - StringSplitter("x y z").Split(' ').CollectInto(&std::ignore, &s, &std::ignore); - UNIT_ASSERT_VALUES_EQUAL(s, "y"); - - UNIT_ASSERT_EXCEPTION(StringSplitter("ignored != non-requred").Split(':').CollectInto(&s, &std::ignore), yexception); - } - + Y_UNIT_TEST(TestSplitStringWithIgnore) { + TStringBuf s; + StringSplitter("x y z").Split(' ').CollectInto(&std::ignore, &s, &std::ignore); + UNIT_ASSERT_VALUES_EQUAL(s, "y"); + + UNIT_ASSERT_EXCEPTION(StringSplitter("ignored != non-requred").Split(':').CollectInto(&s, &std::ignore), yexception); + } + Y_UNIT_TEST(TestTryCollectInto) { int a, b, c; bool parsingSucceeded; diff --git a/util/string/ut/ya.make b/util/string/ut/ya.make index 6e80812825..654d053852 100644 --- a/util/string/ut/ya.make +++ b/util/string/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( string/builder_ut.cpp diff --git a/util/string/ya.make b/util/string/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/string/ya.make +++ b/util/string/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/system/atexit.cpp b/util/system/atexit.cpp index 74fb10b6b1..9f77f07a06 100644 --- a/util/system/atexit.cpp +++ b/util/system/atexit.cpp @@ -1,5 +1,5 @@ #include "atexit.h" -#include "atomic.h" +#include "atomic.h" #include "yassert.h" #include "spinlock.h" #include "thread.h" @@ -77,29 +77,29 @@ namespace { }; static TAtomic atExitLock = 0; - static TAtExit* volatile atExitPtr = nullptr; + static TAtExit* volatile atExitPtr = nullptr; alignas(TAtExit) static char atExitMem[sizeof(TAtExit)]; static void OnExit() { - if (TAtExit* const atExit = AtomicGet(atExitPtr)) { + if (TAtExit* const atExit = AtomicGet(atExitPtr)) { atExit->Finish(); atExit->~TAtExit(); - AtomicSet(atExitPtr, nullptr); + AtomicSet(atExitPtr, nullptr); } } static inline TAtExit* Instance() { - if (TAtExit* const atExit = AtomicGet(atExitPtr)) { - return atExit; - } + if (TAtExit* const atExit = AtomicGet(atExitPtr)) { + return atExit; + } with_lock (atExitLock) { - if (TAtExit* const atExit = AtomicGet(atExitPtr)) { - return atExit; + if (TAtExit* const atExit = AtomicGet(atExitPtr)) { + return atExit; } - atexit(OnExit); - TAtExit* const atExit = new (atExitMem) TAtExit; - AtomicSet(atExitPtr, atExit); - return atExit; + atexit(OnExit); + TAtExit* const atExit = new (atExitMem) TAtExit; + AtomicSet(atExitPtr, atExit); + return atExit; } } } @@ -109,10 +109,10 @@ void ManualRunAtExitFinalizers() { } bool ExitStarted() { - if (TAtExit* const atExit = AtomicGet(atExitPtr)) { - return atExit->FinishStarted(); + if (TAtExit* const atExit = AtomicGet(atExitPtr)) { + return atExit->FinishStarted(); } - return false; + return false; } void AtExit(TAtExitFunc func, void* ctx, size_t priority) { diff --git a/util/system/benchmark/cpu_id/metrics/ya.make b/util/system/benchmark/cpu_id/metrics/ya.make index 8c55def99b..f22decac96 100644 --- a/util/system/benchmark/cpu_id/metrics/ya.make +++ b/util/system/benchmark/cpu_id/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/system/benchmark/cpu_id/ya.make b/util/system/benchmark/cpu_id/ya.make index 976977014f..7ba0dcee94 100644 --- a/util/system/benchmark/cpu_id/ya.make +++ b/util/system/benchmark/cpu_id/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) Y_BENCHMARK() diff --git a/util/system/benchmark/create_destroy_thread/metrics/ya.make b/util/system/benchmark/create_destroy_thread/metrics/ya.make index d526487e1a..0576c4d9cf 100644 --- a/util/system/benchmark/create_destroy_thread/metrics/ya.make +++ b/util/system/benchmark/create_destroy_thread/metrics/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) PY2TEST() diff --git a/util/system/benchmark/rdtsc/ya.make b/util/system/benchmark/rdtsc/ya.make index 7059abc3a4..5628d4fb8a 100644 --- a/util/system/benchmark/rdtsc/ya.make +++ b/util/system/benchmark/rdtsc/ya.make @@ -1,7 +1,7 @@ Y_BENCHMARK() OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( main.cpp diff --git a/util/system/benchmark/ya.make b/util/system/benchmark/ya.make index 12fa9af9d6..dc009eea23 100644 --- a/util/system/benchmark/ya.make +++ b/util/system/benchmark/ya.make @@ -2,7 +2,7 @@ OWNER( yazevnul g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) RECURSE( cpu_id diff --git a/util/system/guard_ut.cpp b/util/system/guard_ut.cpp index 404ede99ab..6cb9079211 100644 --- a/util/system/guard_ut.cpp +++ b/util/system/guard_ut.cpp @@ -14,7 +14,7 @@ struct TTestGuard: public TTestBase { UNIT_TEST(TestUnguard) UNIT_TEST(TestTryReadGuard) UNIT_TEST(TestWithLock) - UNIT_TEST(TestWithLockScope); + UNIT_TEST(TestWithLockScope); UNIT_TEST_SUITE_END(); struct TGuardChecker { @@ -167,14 +167,14 @@ struct TTestGuard: public TTestBase { UNIT_ASSERT(!m.guarded); UNIT_ASSERT_EQUAL(n, 43); } - - void TestWithLockScope() { - auto Guard = [](auto) { UNIT_FAIL("Non global Guard used"); return 0; }; - TGuardChecker m; + + void TestWithLockScope() { + auto Guard = [](auto) { UNIT_FAIL("Non global Guard used"); return 0; }; + TGuardChecker m; with_lock (m) { - Y_UNUSED(Guard); - } - } + Y_UNUSED(Guard); + } + } }; UNIT_TEST_SUITE_REGISTRATION(TTestGuard) diff --git a/util/system/sanitizers.h b/util/system/sanitizers.h index 965e5c751e..501693535d 100644 --- a/util/system/sanitizers.h +++ b/util/system/sanitizers.h @@ -55,7 +55,7 @@ namespace NSan { } // Determines if asan present - inline constexpr static bool ASanIsOn() noexcept { + inline constexpr static bool ASanIsOn() noexcept { #if defined(_asan_enabled_) return true; #else @@ -64,7 +64,7 @@ namespace NSan { } // Determines if tsan present - inline constexpr static bool TSanIsOn() noexcept { + inline constexpr static bool TSanIsOn() noexcept { #if defined(_tsan_enabled_) return true; #else @@ -73,7 +73,7 @@ namespace NSan { } // Determines if msan present - inline constexpr static bool MSanIsOn() noexcept { + inline constexpr static bool MSanIsOn() noexcept { #if defined(_msan_enabled_) return true; #else diff --git a/util/system/src_location.h b/util/system/src_location.h index 12ba6e063e..0117cdebf8 100644 --- a/util/system/src_location.h +++ b/util/system/src_location.h @@ -15,11 +15,11 @@ struct TSourceLocation { int Line; }; -// __SOURCE_FILE__ should be used instead of __FILE__ -#if !defined(__NVCC__) +// __SOURCE_FILE__ should be used instead of __FILE__ +#if !defined(__NVCC__) #define __SOURCE_FILE__ (__SOURCE_FILE_IMPL__.As<TStringBuf>()) -#else +#else #define __SOURCE_FILE__ (__SOURCE_FILE_IMPL__.template As<TStringBuf>()) -#endif - +#endif + #define __LOCATION__ ::TSourceLocation(__SOURCE_FILE__, __LINE__) diff --git a/util/system/src_location_ut.cpp b/util/system/src_location_ut.cpp index 5b86cb86ef..5e880d950b 100644 --- a/util/system/src_location_ut.cpp +++ b/util/system/src_location_ut.cpp @@ -11,8 +11,8 @@ static inline TString GenLoc() { Y_UNIT_TEST_SUITE(TestLocation) { Y_UNIT_TEST(Test1) { UNIT_ASSERT_VALUES_EQUAL(GenLoc(), "util/system/src_location_ut.cpp:8"); - - static constexpr TSourceLocation location = __LOCATION__; - static_assert(location.Line >= 0, "__LOCATION__ can be used at compile time expressions"); + + static constexpr TSourceLocation location = __LOCATION__; + static_assert(location.Line >= 0, "__LOCATION__ can be used at compile time expressions"); } } diff --git a/util/system/src_root.h b/util/system/src_root.h index 4f2d9f5ee6..17bea82be5 100644 --- a/util/system/src_root.h +++ b/util/system/src_root.h @@ -3,8 +3,8 @@ #include "compiler.h" #include "defaults.h" -#include <type_traits> - +#include <type_traits> + namespace NPrivate { struct TStaticBuf { constexpr TStaticBuf(const char* data, unsigned len) noexcept @@ -32,37 +32,37 @@ namespace NPrivate { constexpr TStaticBuf ArcRoot = STATIC_BUF(Y_STRINGIZE(ARCADIA_ROOT)); constexpr TStaticBuf BuildRoot = STATIC_BUF(Y_STRINGIZE(ARCADIA_BUILD_ROOT)); - constexpr Y_FORCE_INLINE bool IsProperPrefix(const TStaticBuf prefix, const TStaticBuf string) noexcept { - if (prefix.Len < string.Len) { - for (unsigned i = prefix.Len; i-- > 0;) { - if (prefix.Data[i] != string.Data[i]) { - return false; - } - } - return true; - } else { - return false; - } - } - - constexpr unsigned RootPrefixLength(const TStaticBuf& f) noexcept { - if (IsProperPrefix(ArcRoot, f)) { - return ArcRoot.Len + 1; + constexpr Y_FORCE_INLINE bool IsProperPrefix(const TStaticBuf prefix, const TStaticBuf string) noexcept { + if (prefix.Len < string.Len) { + for (unsigned i = prefix.Len; i-- > 0;) { + if (prefix.Data[i] != string.Data[i]) { + return false; + } + } + return true; + } else { + return false; + } + } + + constexpr unsigned RootPrefixLength(const TStaticBuf& f) noexcept { + if (IsProperPrefix(ArcRoot, f)) { + return ArcRoot.Len + 1; } - if (IsProperPrefix(BuildRoot, f)) { - return BuildRoot.Len + 1; + if (IsProperPrefix(BuildRoot, f)) { + return BuildRoot.Len + 1; } - return 0; - } - - constexpr Y_FORCE_INLINE TStaticBuf StripRoot(const TStaticBuf& f, unsigned prefixLength) noexcept { - return TStaticBuf(f.Data + prefixLength, f.Len - prefixLength); - } - - //$(SRC_ROOT)/prj/blah.cpp -> prj/blah.cpp - constexpr Y_FORCE_INLINE TStaticBuf StripRoot(const TStaticBuf& f) noexcept { - return StripRoot(f, RootPrefixLength(f)); + return 0; } + + constexpr Y_FORCE_INLINE TStaticBuf StripRoot(const TStaticBuf& f, unsigned prefixLength) noexcept { + return TStaticBuf(f.Data + prefixLength, f.Len - prefixLength); + } + + //$(SRC_ROOT)/prj/blah.cpp -> prj/blah.cpp + constexpr Y_FORCE_INLINE TStaticBuf StripRoot(const TStaticBuf& f) noexcept { + return StripRoot(f, RootPrefixLength(f)); + } } -#define __SOURCE_FILE_IMPL__ ::NPrivate::StripRoot(STATIC_BUF(__FILE__), std::integral_constant<unsigned, ::NPrivate::RootPrefixLength(STATIC_BUF(__FILE__))>::value) +#define __SOURCE_FILE_IMPL__ ::NPrivate::StripRoot(STATIC_BUF(__FILE__), std::integral_constant<unsigned, ::NPrivate::RootPrefixLength(STATIC_BUF(__FILE__))>::value) diff --git a/util/system/src_root_ut.cpp b/util/system/src_root_ut.cpp index e9a675eb9a..852f9dd668 100644 --- a/util/system/src_root_ut.cpp +++ b/util/system/src_root_ut.cpp @@ -9,19 +9,19 @@ Y_UNIT_TEST_SUITE(TestSourceRoot) { const TString path = TPathSplit(__SOURCE_FILE_IMPL__.As<TStringBuf>()).Reconstruct(); UNIT_ASSERT_EQUAL(path, "util" LOCSLASH_S "system" LOCSLASH_S "src_root_ut.cpp"); } - - Y_UNIT_TEST(TestPrivateChopPrefixRoutine) { - static constexpr const char str[] = ":\0:\0: It's unlikely that this string has an ARCADIA_ROOT as its prefix :\0:\0:"; - static constexpr const auto strStaticBuf = STATIC_BUF(str); + + Y_UNIT_TEST(TestPrivateChopPrefixRoutine) { + static constexpr const char str[] = ":\0:\0: It's unlikely that this string has an ARCADIA_ROOT as its prefix :\0:\0:"; + static constexpr const auto strStaticBuf = STATIC_BUF(str); UNIT_ASSERT_VALUES_EQUAL(TStringBuf(str, sizeof(str) - 1), ::NPrivate::StripRoot(strStaticBuf).As<TStringBuf>()); - UNIT_ASSERT_VALUES_EQUAL(0, ::NPrivate::RootPrefixLength(strStaticBuf)); - - static_assert(::NPrivate::IsProperPrefix(STATIC_BUF("foo"), STATIC_BUF("foobar")), R"(IsProperPrefix("foo", "foobar") failed)"); - static_assert(!::NPrivate::IsProperPrefix(STATIC_BUF("foobar"), STATIC_BUF("foo")), R"(IsProperPrefix("foobar", "foo") failed)"); - static_assert(!::NPrivate::IsProperPrefix(STATIC_BUF("name"), STATIC_BUF("name")), R"(IsProperPrefix("name", "name") failed)"); - static_assert(::NPrivate::IsProperPrefix(STATIC_BUF("name"), STATIC_BUF("name/")), R"(IsProperPrefix("name", "name/") failed)"); - static_assert(::NPrivate::IsProperPrefix(STATIC_BUF(""), STATIC_BUF("foobar")), R"(IsProperPrefix("", "foobar") failed)"); - static_assert(!::NPrivate::IsProperPrefix(STATIC_BUF(""), STATIC_BUF("")), R"(IsProperPrefix("", "") failed)"); - static_assert(::NPrivate::IsProperPrefix(STATIC_BUF("dir"), STATIC_BUF("dir/file")), R"(IsProperPrefix("dir", "dir/file") failed)"); - } + UNIT_ASSERT_VALUES_EQUAL(0, ::NPrivate::RootPrefixLength(strStaticBuf)); + + static_assert(::NPrivate::IsProperPrefix(STATIC_BUF("foo"), STATIC_BUF("foobar")), R"(IsProperPrefix("foo", "foobar") failed)"); + static_assert(!::NPrivate::IsProperPrefix(STATIC_BUF("foobar"), STATIC_BUF("foo")), R"(IsProperPrefix("foobar", "foo") failed)"); + static_assert(!::NPrivate::IsProperPrefix(STATIC_BUF("name"), STATIC_BUF("name")), R"(IsProperPrefix("name", "name") failed)"); + static_assert(::NPrivate::IsProperPrefix(STATIC_BUF("name"), STATIC_BUF("name/")), R"(IsProperPrefix("name", "name/") failed)"); + static_assert(::NPrivate::IsProperPrefix(STATIC_BUF(""), STATIC_BUF("foobar")), R"(IsProperPrefix("", "foobar") failed)"); + static_assert(!::NPrivate::IsProperPrefix(STATIC_BUF(""), STATIC_BUF("")), R"(IsProperPrefix("", "") failed)"); + static_assert(::NPrivate::IsProperPrefix(STATIC_BUF("dir"), STATIC_BUF("dir/file")), R"(IsProperPrefix("dir", "dir/file") failed)"); + } } diff --git a/util/system/ut/stdin_osfhandle/ya.make b/util/system/ut/stdin_osfhandle/ya.make index d71ab22e69..5d3701adf0 100644 --- a/util/system/ut/stdin_osfhandle/ya.make +++ b/util/system/ut/stdin_osfhandle/ya.make @@ -1,7 +1,7 @@ PROGRAM() OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( main.cpp diff --git a/util/system/ut/ya.make b/util/system/ut/ya.make index 127e7c261e..6b758d2f48 100644 --- a/util/system/ut/ya.make +++ b/util/system/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) FORK_TESTS() diff --git a/util/system/ya.make b/util/system/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/system/ya.make +++ b/util/system/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/system/yassert.cpp b/util/system/yassert.cpp index 0f586648b7..60dbe4c04a 100644 --- a/util/system/yassert.cpp +++ b/util/system/yassert.cpp @@ -7,7 +7,7 @@ #include <util/datetime/base.h> #include <util/generic/singleton.h> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <util/generic/string.h> #include <util/stream/output.h> #include <util/stream/str.h> @@ -34,9 +34,9 @@ namespace { struct TPanicLockHolder: public TAdaptiveLock { }; } -namespace NPrivate { - [[noreturn]] Y_NO_INLINE void InternalPanicImpl(int line, const char* function, const char* expr, int, int, int, const TStringBuf file, const char* errorMessage, size_t errorMessageSize) noexcept; -} +namespace NPrivate { + [[noreturn]] Y_NO_INLINE void InternalPanicImpl(int line, const char* function, const char* expr, int, int, int, const TStringBuf file, const char* errorMessage, size_t errorMessageSize) noexcept; +} void ::NPrivate::Panic(const TStaticBuf& file, int line, const char* function, const char* expr, const char* format, ...) noexcept { try { @@ -51,18 +51,18 @@ void ::NPrivate::Panic(const TStaticBuf& file, int line, const char* function, c vsprintf(errorMsg, format[0] == ' ' ? format + 1 : format, args); va_end(args); - constexpr int abiPlaceholder = 0; - ::NPrivate::InternalPanicImpl(line, function, expr, abiPlaceholder, abiPlaceholder, abiPlaceholder, file.As<TStringBuf>(), errorMsg.c_str(), errorMsg.size()); - } catch (...) { - // ¯\_(ツ)_/¯ - } - - abort(); -} - -namespace NPrivate { - [[noreturn]] Y_NO_INLINE void InternalPanicImpl(int line, const char* function, const char* expr, int, int, int, const TStringBuf file, const char* errorMessage, size_t errorMessageSize) noexcept try { - TStringBuf errorMsg{errorMessage, errorMessageSize}; + constexpr int abiPlaceholder = 0; + ::NPrivate::InternalPanicImpl(line, function, expr, abiPlaceholder, abiPlaceholder, abiPlaceholder, file.As<TStringBuf>(), errorMsg.c_str(), errorMsg.size()); + } catch (...) { + // ¯\_(ツ)_/¯ + } + + abort(); +} + +namespace NPrivate { + [[noreturn]] Y_NO_INLINE void InternalPanicImpl(int line, const char* function, const char* expr, int, int, int, const TStringBuf file, const char* errorMessage, size_t errorMessageSize) noexcept try { + TStringBuf errorMsg{errorMessage, errorMessageSize}; const TString now = TInstant::Now().ToStringLocal(); TString r; @@ -72,7 +72,7 @@ namespace NPrivate { } else { o << "FAIL (" << now << "): " << errorMsg << Endl; } - o << " " << file << ":" << line << Endl; + o << " " << file << ":" << line << Endl; if (expr) { o << " " << function << "(): requirement " << expr << " failed" << Endl; } else { @@ -87,8 +87,8 @@ namespace NPrivate { Cerr << "Failed to dump clang coverage" << Endl; } #endif - abort(); + abort(); } catch (...) { - abort(); + abort(); } } diff --git a/util/tests/benchmark/ya.make b/util/tests/benchmark/ya.make index 134cbfabd1..17cd785b3e 100644 --- a/util/tests/benchmark/ya.make +++ b/util/tests/benchmark/ya.make @@ -1,5 +1,5 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) RECURSE_ROOT_RELATIVE( util/charset/benchmark diff --git a/util/tests/cython/ya.make b/util/tests/cython/ya.make index b928c19026..c54ab832f6 100644 --- a/util/tests/cython/ya.make +++ b/util/tests/cython/ya.make @@ -1,7 +1,7 @@ PY23_TEST() OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCDIR(util) diff --git a/util/tests/fuzzing/ya.make b/util/tests/fuzzing/ya.make index d9a8f9df9f..8b47fa9f61 100644 --- a/util/tests/fuzzing/ya.make +++ b/util/tests/fuzzing/ya.make @@ -1,5 +1,5 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) RECURSE_ROOT_RELATIVE( util/string/fuzzing diff --git a/util/tests/sym_versions/ya.make b/util/tests/sym_versions/ya.make index 3957c60fc9..73e2b3a70b 100644 --- a/util/tests/sym_versions/ya.make +++ b/util/tests/sym_versions/ya.make @@ -4,7 +4,7 @@ OWNER( pg g:util ) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) TEST_SRCS(test_glibc.py) diff --git a/util/tests/ut/ya.make b/util/tests/ut/ya.make index 94278cbde1..30fc35ce9c 100644 --- a/util/tests/ut/ya.make +++ b/util/tests/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( ysaveload_ut.cpp diff --git a/util/thread/lfqueue_ut.cpp b/util/thread/lfqueue_ut.cpp index 83bca100cf..25dd246d89 100644 --- a/util/thread/lfqueue_ut.cpp +++ b/util/thread/lfqueue_ut.cpp @@ -238,7 +238,7 @@ Y_UNIT_TEST_SUITE(TLockFreeQueueTests) { }); } - NThreading::WaitExceptionOrAll(futures).GetValueSync(); + NThreading::WaitExceptionOrAll(futures).GetValueSync(); p.Stop(); TVector<int> left; diff --git a/util/thread/ut/ya.make b/util/thread/ut/ya.make index 93198bfaf1..ff0e1f6970 100644 --- a/util/thread/ut/ya.make +++ b/util/thread/ut/ya.make @@ -1,7 +1,7 @@ UNITTEST_FOR(util) OWNER(g:util) -SUBSCRIBER(g:util-subscribers) +SUBSCRIBER(g:util-subscribers) SRCS( thread/factory_ut.cpp diff --git a/util/thread/ya.make b/util/thread/ya.make index 79c9498ddd..24723ab579 100644 --- a/util/thread/ya.make +++ b/util/thread/ya.make @@ -1,6 +1,6 @@ OWNER(g:util) -SUBSCRIBER(g:util-subscribers) - -RECURSE_FOR_TESTS( - ut -) +SUBSCRIBER(g:util-subscribers) + +RECURSE_FOR_TESTS( + ut +) diff --git a/util/ya.make b/util/ya.make index 6ebe7e40cf..fb0e134e7a 100644 --- a/util/ya.make +++ b/util/ya.make @@ -65,7 +65,7 @@ JOIN_SRCS( folder/dirut.cpp folder/filelist.cpp folder/fts.cpp - folder/fwd.cpp + folder/fwd.cpp folder/iterator.cpp folder/path.cpp folder/pathsplit.cpp @@ -119,7 +119,7 @@ JOIN_SRCS( generic/ptr.cpp generic/queue.cpp generic/refcount.cpp - generic/serialized_enum.cpp + generic/serialized_enum.cpp generic/set.cpp generic/singleton.cpp generic/size_literals.cpp @@ -381,7 +381,7 @@ JOIN_SRCS( ) END() - -RECURSE_FOR_TESTS( - tests/ut -) + +RECURSE_FOR_TESTS( + tests/ut +) diff --git a/util/ysaveload.cpp b/util/ysaveload.cpp index 1ae3acb01e..8472ad4e72 100644 --- a/util/ysaveload.cpp +++ b/util/ysaveload.cpp @@ -12,11 +12,11 @@ void TSerializer<TBuffer>::Load(IInputStream* rh, TBuffer& buf) { buf.Resize(s); ::LoadPodArray(rh, buf.Data(), buf.Size()); } - -[[noreturn]] void NPrivate::ThrowLoadEOFException(size_t typeSize, size_t realSize, TStringBuf structName) { - ythrow TLoadEOF() << "can not load " << structName << "(" << typeSize << ", " << realSize << " bytes)"; -} - -[[noreturn]] void NPrivate::ThrowUnexpectedVariantTagException(ui8 tagIndex) { - ythrow TLoadEOF() << "Unexpected tag value " << tagIndex << " while loading TVariant"; -} + +[[noreturn]] void NPrivate::ThrowLoadEOFException(size_t typeSize, size_t realSize, TStringBuf structName) { + ythrow TLoadEOF() << "can not load " << structName << "(" << typeSize << ", " << realSize << " bytes)"; +} + +[[noreturn]] void NPrivate::ThrowUnexpectedVariantTagException(ui8 tagIndex) { + ythrow TLoadEOF() << "Unexpected tag value " << tagIndex << " while loading TVariant"; +} diff --git a/util/ysaveload.h b/util/ysaveload.h index 02efb4049b..aaeb9159e1 100644 --- a/util/ysaveload.h +++ b/util/ysaveload.h @@ -1,7 +1,7 @@ #pragma once #include <util/generic/fwd.h> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <util/generic/string.h> #include <util/generic/yexception.h> #include <util/generic/typetraits.h> @@ -54,16 +54,16 @@ static inline void SavePodType(IOutputStream* rh, const T& t) { rh->Write(&t, sizeof(T)); } -namespace NPrivate { - [[noreturn]] void ThrowLoadEOFException(size_t typeSize, size_t realSize, TStringBuf structName); - [[noreturn]] void ThrowUnexpectedVariantTagException(ui8 tagIndex); -} - +namespace NPrivate { + [[noreturn]] void ThrowLoadEOFException(size_t typeSize, size_t realSize, TStringBuf structName); + [[noreturn]] void ThrowUnexpectedVariantTagException(ui8 tagIndex); +} + template <class T> static inline void LoadPodType(IInputStream* rh, T& t) { const size_t res = rh->Load(&t, sizeof(T)); - if (Y_UNLIKELY(res != sizeof(T))) { + if (Y_UNLIKELY(res != sizeof(T))) { ::NPrivate::ThrowLoadEOFException(sizeof(T), res, TStringBuf("pod type")); } } @@ -78,7 +78,7 @@ static inline void LoadPodArray(IInputStream* rh, T* arr, size_t count) { const size_t len = sizeof(T) * count; const size_t res = rh->Load(arr, len); - if (Y_UNLIKELY(res != len)) { + if (Y_UNLIKELY(res != len)) { ::NPrivate::ThrowLoadEOFException(len, res, TStringBuf("pod array")); } } @@ -666,8 +666,8 @@ struct TSerializer<std::variant<Args...>> { static void Load(IInputStream* is, TVar& v) { ui8 index; ::Load(is, index); - if (Y_UNLIKELY(index >= sizeof...(Args))) { - ::NPrivate::ThrowUnexpectedVariantTagException(index); + if (Y_UNLIKELY(index >= sizeof...(Args))) { + ::NPrivate::ThrowUnexpectedVariantTagException(index); } LoadImpl(is, v, index, std::index_sequence_for<Args...>{}); } @@ -720,17 +720,17 @@ static inline void LoadMany(S* s, Ts&... t) { void Load(IInputStream* s) override { \ ::LoadMany(s, __VA_ARGS__); \ } - -template <class T> -struct TNonVirtualSaver { - const T* Data; - void Save(IOutputStream* out) const { - Data->T::Save(out); - } -}; - -template <typename S, typename T, typename... R> -inline void LoadMany(S* s, TNonVirtualSaver<T> t, R&... r) { - const_cast<T*>(t.Data)->T::Load(s); - ::LoadMany(s, r...); -} + +template <class T> +struct TNonVirtualSaver { + const T* Data; + void Save(IOutputStream* out) const { + Data->T::Save(out); + } +}; + +template <typename S, typename T, typename... R> +inline void LoadMany(S* s, TNonVirtualSaver<T> t, R&... r) { + const_cast<T*>(t.Data)->T::Load(s); + ::LoadMany(s, r...); +} diff --git a/util/ysaveload_ut.cpp b/util/ysaveload_ut.cpp index 723c68f391..49bfbc3d7f 100644 --- a/util/ysaveload_ut.cpp +++ b/util/ysaveload_ut.cpp @@ -29,8 +29,8 @@ class TSaveLoadTest: public TTestBase { UNIT_TEST(TestList) UNIT_TEST(TestTuple) UNIT_TEST(TestVariant) - UNIT_TEST(TestInheritNonVirtualClass) - UNIT_TEST(TestInheritVirtualClass) + UNIT_TEST(TestInheritNonVirtualClass) + UNIT_TEST(TestInheritVirtualClass) UNIT_TEST_SUITE_END(); struct TSaveHelper { @@ -430,58 +430,58 @@ private: std::variant<char, bool> v2 = false; UNIT_ASSERT_EXCEPTION(::Load(&s, v2), TLoadEOF); } - - // tests serialization of class with three public string members - template <class TDerived, class TInterface = TDerived> - void TestInheritClassImpl() { - TBufferStream s; - { - TDerived v1; - v1.Str1 = "One"; - v1.Str2 = "Two"; - v1.Str3 = "Three"; - ::Save(&s, static_cast<const TInterface&>(v1)); - } - { - TDerived v2; - ::Load(&s, static_cast<TInterface&>(v2)); - UNIT_ASSERT_VALUES_EQUAL_C(v2.Str1, "One", TypeName<TDerived>() << " via " << TypeName<TInterface>()); - UNIT_ASSERT_VALUES_EQUAL_C(v2.Str2, "Two", TypeName<TDerived>() << " via " << TypeName<TInterface>()); - UNIT_ASSERT_VALUES_EQUAL_C(v2.Str3, "Three", TypeName<TDerived>() << " via " << TypeName<TInterface>()); - } - } - - void TestInheritNonVirtualClass() { - struct TBaseNonVirtual { - TString Str1; - Y_SAVELOAD_DEFINE(Str1); - }; - struct TDerivedNonVirtual: TBaseNonVirtual { - TString Str2; - TString Str3; - Y_SAVELOAD_DEFINE(TNonVirtualSaver<TBaseNonVirtual>{this}, Str2, Str3); - }; - TestInheritClassImpl<TDerivedNonVirtual>(); - } - - void TestInheritVirtualClass() { - struct IInterface { - virtual void Save(IOutputStream* out) const = 0; - virtual void Load(IInputStream* in) = 0; - }; - struct TBaseVirtual: IInterface { - TString Str1; - Y_SAVELOAD_DEFINE_OVERRIDE(Str1); - }; - struct TDerivedVirtual: TBaseVirtual { - TString Str2; - TString Str3; - Y_SAVELOAD_DEFINE_OVERRIDE(TNonVirtualSaver<TBaseVirtual>{this}, Str2, Str3); - }; - TestInheritClassImpl<TDerivedVirtual>(); - TestInheritClassImpl<TDerivedVirtual, TBaseVirtual>(); - TestInheritClassImpl<TDerivedVirtual, IInterface>(); - } + + // tests serialization of class with three public string members + template <class TDerived, class TInterface = TDerived> + void TestInheritClassImpl() { + TBufferStream s; + { + TDerived v1; + v1.Str1 = "One"; + v1.Str2 = "Two"; + v1.Str3 = "Three"; + ::Save(&s, static_cast<const TInterface&>(v1)); + } + { + TDerived v2; + ::Load(&s, static_cast<TInterface&>(v2)); + UNIT_ASSERT_VALUES_EQUAL_C(v2.Str1, "One", TypeName<TDerived>() << " via " << TypeName<TInterface>()); + UNIT_ASSERT_VALUES_EQUAL_C(v2.Str2, "Two", TypeName<TDerived>() << " via " << TypeName<TInterface>()); + UNIT_ASSERT_VALUES_EQUAL_C(v2.Str3, "Three", TypeName<TDerived>() << " via " << TypeName<TInterface>()); + } + } + + void TestInheritNonVirtualClass() { + struct TBaseNonVirtual { + TString Str1; + Y_SAVELOAD_DEFINE(Str1); + }; + struct TDerivedNonVirtual: TBaseNonVirtual { + TString Str2; + TString Str3; + Y_SAVELOAD_DEFINE(TNonVirtualSaver<TBaseNonVirtual>{this}, Str2, Str3); + }; + TestInheritClassImpl<TDerivedNonVirtual>(); + } + + void TestInheritVirtualClass() { + struct IInterface { + virtual void Save(IOutputStream* out) const = 0; + virtual void Load(IInputStream* in) = 0; + }; + struct TBaseVirtual: IInterface { + TString Str1; + Y_SAVELOAD_DEFINE_OVERRIDE(Str1); + }; + struct TDerivedVirtual: TBaseVirtual { + TString Str2; + TString Str3; + Y_SAVELOAD_DEFINE_OVERRIDE(TNonVirtualSaver<TBaseVirtual>{this}, Str2, Str3); + }; + TestInheritClassImpl<TDerivedVirtual>(); + TestInheritClassImpl<TDerivedVirtual, TBaseVirtual>(); + TestInheritClassImpl<TDerivedVirtual, IInterface>(); + } }; UNIT_TEST_SUITE_REGISTRATION(TSaveLoadTest); diff --git a/ydb/core/kqp/provider/yql_kikimr_datasource.cpp b/ydb/core/kqp/provider/yql_kikimr_datasource.cpp index 65ef7eb932..7b2d68a254 100644 --- a/ydb/core/kqp/provider/yql_kikimr_datasource.cpp +++ b/ydb/core/kqp/provider/yql_kikimr_datasource.cpp @@ -143,7 +143,7 @@ public: return TStatus::Ok; } - AsyncFuture = NThreading::WaitExceptionOrAll(futures); + AsyncFuture = NThreading::WaitExceptionOrAll(futures); return TStatus::Async; } diff --git a/ydb/core/kqp/ut/kqp_service_ut.cpp b/ydb/core/kqp/ut/kqp_service_ut.cpp index 37e178c810..81ab2966e6 100644 --- a/ydb/core/kqp/ut/kqp_service_ut.cpp +++ b/ydb/core/kqp/ut/kqp_service_ut.cpp @@ -151,7 +151,7 @@ Y_UNIT_TEST_SUITE(KqpService) { auto futures = simulateSessionBusy(10, session); - NThreading::WaitExceptionOrAll(futures).GetValueSync(); + NThreading::WaitExceptionOrAll(futures).GetValueSync(); for (auto& future : futures) { auto result = future.GetValue(); @@ -176,7 +176,7 @@ Y_UNIT_TEST_SUITE(KqpService) { auto futures = simulateSessionBusy(queriesCount, session); - NThreading::WaitExceptionOrAll(futures).GetValueSync(); + NThreading::WaitExceptionOrAll(futures).GetValueSync(); for (auto& future : futures) { auto result = future.GetValue(); @@ -208,7 +208,7 @@ Y_UNIT_TEST_SUITE(KqpService) { auto futures = simulateSessionBusy(queriesCount, session); - NThreading::WaitExceptionOrAll(futures).GetValueSync(); + NThreading::WaitExceptionOrAll(futures).GetValueSync(); for (auto& future : futures) { auto result = future.GetValue(); diff --git a/ydb/library/login/login.cpp b/ydb/library/login/login.cpp index b6fbc3c8f6..fe133d14f9 100644 --- a/ydb/library/login/login.cpp +++ b/ydb/library/login/login.cpp @@ -9,7 +9,7 @@ #include <openssl/pem.h> #include <openssl/rand.h> -#include <util/generic/singleton.h> +#include <util/generic/singleton.h> #include <util/string/cast.h> #include <util/string/hex.h> @@ -24,7 +24,7 @@ struct TLoginProvider::TImpl { THolder<NArgonish::IArgon2Base> ArgonHasher; TImpl() { - ArgonHasher = Default<NArgonish::TArgon2Factory>().Create( + ArgonHasher = Default<NArgonish::TArgon2Factory>().Create( NArgonish::EArgon2Type::Argon2id, // Mixed version of Argon2 2, // 2-pass computation (1<<11), // 2 mebibytes memory usage (in KiB) @@ -182,7 +182,7 @@ TLoginProvider::TRemoveGroupResponse TLoginProvider::RemoveGroup(const TRemoveGr response.Error = "Group not found"; return response; } - + auto itChildToParentIndex = ChildToParentIndex.find(request.Group); if (itChildToParentIndex != ChildToParentIndex.end()) { for (const TString& parent : itChildToParentIndex->second) { @@ -198,7 +198,7 @@ TLoginProvider::TRemoveGroupResponse TLoginProvider::RemoveGroup(const TRemoveGr for (const TString& member : itGroupModify->second.Members) { ChildToParentIndex[member].erase(request.Group); } - + Sids.erase(itGroupModify); return response; @@ -342,7 +342,7 @@ TLoginProvider::TValidateTokenResponse TLoginProvider::ValidateToken(const TVali response.Error = "Security state is empty"; response.ErrorRetryable = true; } else if (keyId < Keys.front().KeyId) { - response.Error = "The key of this token has expired"; + response.Error = "The key of this token has expired"; } else if (keyId > Keys.back().KeyId) { response.Error = "The key of this token is not available yet"; response.ErrorRetryable = true; @@ -388,7 +388,7 @@ std::chrono::system_clock::time_point TLoginProvider::GetTokenExpiresAt(const TS } bool TLoginProvider::IsItTimeToRotateKeys() const { - return Keys.empty() + return Keys.empty() || Keys.back().PrivateKey.empty() || KeysRotationTime + KEYS_ROTATION_PERIOD < std::chrono::system_clock::now(); } diff --git a/ydb/library/yql/core/facade/yql_facade.cpp b/ydb/library/yql/core/facade/yql_facade.cpp index b74abc1c34..2c77afbf52 100644 --- a/ydb/library/yql/core/facade/yql_facade.cpp +++ b/ydb/library/yql/core/facade/yql_facade.cpp @@ -1358,7 +1358,7 @@ TFuture<void> TProgram::OpenSession(const TString& username) } } - return WaitExceptionOrAll(openFutures); + return WaitExceptionOrAll(openFutures); } void TProgram::Print(IOutputStream* exprOut, IOutputStream* planOut, bool cleanPlan) { diff --git a/ydb/library/yql/core/type_ann/type_ann_expr.cpp b/ydb/library/yql/core/type_ann/type_ann_expr.cpp index f67d3b4120..4995f11e2b 100644 --- a/ydb/library/yql/core/type_ann/type_ann_expr.cpp +++ b/ydb/library/yql/core/type_ann/type_ann_expr.cpp @@ -71,7 +71,7 @@ public: futures.push_back(CallableTransformer->GetAsyncFuture(*callable)); } - return WaitExceptionOrAll(futures); + return WaitExceptionOrAll(futures); } TStatus DoApplyAsyncChanges(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) final { diff --git a/ydb/library/yql/core/user_data/yql_user_data.cpp b/ydb/library/yql/core/user_data/yql_user_data.cpp index 11db9c779e..ccc2a94e87 100644 --- a/ydb/library/yql/core/user_data/yql_user_data.cpp +++ b/ydb/library/yql/core/user_data/yql_user_data.cpp @@ -21,14 +21,14 @@ void TUserData::UserDataToLibraries( } void TUserData::FillFromFolder( - TFsPath root, + TFsPath root, EType type, TVector<TUserData>& userData ) { if (!root.Exists()) { return; } - root = root.RealPath(); + root = root.RealPath(); TDirIterator dir(root, TDirIterator::TOptions(FTS_LOGICAL)); for (auto file = dir.begin(), end = dir.end(); file != end; ++file) { if (file->fts_level == FTS_ROOTLEVEL) { @@ -36,7 +36,7 @@ void TUserData::FillFromFolder( } TFsPath filePath(file->fts_path); userData.push_back({ - type, EDisposition::FILESYSTEM, filePath.RelativeTo(root), filePath + type, EDisposition::FILESYSTEM, filePath.RelativeTo(root), filePath }); } } diff --git a/ydb/library/yql/core/user_data/yql_user_data.h b/ydb/library/yql/core/user_data/yql_user_data.h index 8153f8253e..2a4481e462 100644 --- a/ydb/library/yql/core/user_data/yql_user_data.h +++ b/ydb/library/yql/core/user_data/yql_user_data.h @@ -34,7 +34,7 @@ struct TUserData { ); static void FillFromFolder( - TFsPath root, + TFsPath root, EType type, TVector<TUserData>& userData ); diff --git a/ydb/library/yql/core/yql_expr_constraint.cpp b/ydb/library/yql/core/yql_expr_constraint.cpp index 78c8f68776..ffec4a0d68 100644 --- a/ydb/library/yql/core/yql_expr_constraint.cpp +++ b/ydb/library/yql/core/yql_expr_constraint.cpp @@ -2769,7 +2769,7 @@ public: futures.push_back(CallableTransformer->GetAsyncFuture(*callable)); } - return WaitExceptionOrAll(futures); + return WaitExceptionOrAll(futures); } TStatus DoApplyAsyncChanges(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) final { diff --git a/ydb/library/yql/core/yql_opt_proposed_by_data.cpp b/ydb/library/yql/core/yql_opt_proposed_by_data.cpp index 23a912303f..7348ea8bae 100644 --- a/ydb/library/yql/core/yql_opt_proposed_by_data.cpp +++ b/ydb/library/yql/core/yql_opt_proposed_by_data.cpp @@ -103,7 +103,7 @@ private: futures.push_back(GetTransformer(x).GetAsyncFuture(input)); } - return WaitExceptionOrAll(futures); + return WaitExceptionOrAll(futures); } TStatus DoApplyAsyncChanges(TExprNode::TPtr input, TExprNode::TPtr& output, TExprContext& ctx) final { diff --git a/ydb/library/yql/core/yql_user_data_storage.cpp b/ydb/library/yql/core/yql_user_data_storage.cpp index 1a9d725d27..a3653c64d4 100644 --- a/ydb/library/yql/core/yql_user_data_storage.cpp +++ b/ydb/library/yql/core/yql_user_data_storage.cpp @@ -350,7 +350,7 @@ NThreading::TFuture<std::function<TUserDataTable()>> FreezeUserDataTableIfNeeded voidFutures.push_back(f.IgnoreResult()); } - return NThreading::WaitExceptionOrAll(voidFutures).Apply([files = files, futures = std::move(futures)](NThreading::TFuture<void> f) mutable { + return NThreading::WaitExceptionOrAll(voidFutures).Apply([files = files, futures = std::move(futures)](NThreading::TFuture<void> f) mutable { std::function<TUserDataTable()> result = [f, files, futures]() mutable { // rethrow exception if any f.GetValue(); diff --git a/ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp b/ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp index 57599acb64..f1105996ab 100644 --- a/ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp +++ b/ydb/library/yql/minikql/comp_nodes/mkql_factory.cpp @@ -120,159 +120,159 @@ IComputationNode* WrapWideFlowArg(TCallable& callable, const TComputationNodeFac using TCallableComputationNodeBuilderPtr = IComputationNode* (*const)(TCallable& callable, const TComputationNodeFactoryContext& ctx); using TCallableComputationNodeBuilderMap = std::unordered_map<std::string_view, TCallableComputationNodeBuilderPtr>; -namespace { - +namespace { + struct TCallableComputationNodeBuilderFuncMapFiller { const TCallableComputationNodeBuilderMap Map; TCallableComputationNodeBuilderFuncMapFiller() : Map(InitList) {} - + static constexpr std::initializer_list<TCallableComputationNodeBuilderMap::value_type> InitList = { - {"Append", &WrapAppend}, - {"Prepend", &WrapPrepend}, - {"Extend", &WrapExtend}, - {"Arg", &WrapArg}, - {"Null", &WrapNull}, - {"Fold", &WrapFold}, - {"Condense", &WrapCondense}, - {"Condense1", &WrapCondense1}, - {"Squeeze", &WrapSqueeze}, - {"Squeeze1", &WrapSqueeze1}, - {"Discard", &WrapDiscard}, - {"Fold1", &WrapFold1}, - {"Map", &WrapMap}, - {"OrderedMap", &WrapMap}, + {"Append", &WrapAppend}, + {"Prepend", &WrapPrepend}, + {"Extend", &WrapExtend}, + {"Arg", &WrapArg}, + {"Null", &WrapNull}, + {"Fold", &WrapFold}, + {"Condense", &WrapCondense}, + {"Condense1", &WrapCondense1}, + {"Squeeze", &WrapSqueeze}, + {"Squeeze1", &WrapSqueeze1}, + {"Discard", &WrapDiscard}, + {"Fold1", &WrapFold1}, + {"Map", &WrapMap}, + {"OrderedMap", &WrapMap}, {"MultiMap", &WrapMultiMap}, - {"FlatMap", &WrapFlatMap}, - {"OrderedFlatMap", &WrapFlatMap}, + {"FlatMap", &WrapFlatMap}, + {"OrderedFlatMap", &WrapFlatMap}, {"ChainMap", &WrapChainMap}, {"Chain1Map", &WrapChain1Map}, - {"Filter", &WrapFilter}, - {"OrderedFilter", &WrapFilter}, - {"TakeWhile", &WrapTakeWhile}, - {"SkipWhile", &WrapSkipWhile}, - {"TakeWhileInclusive", &WrapTakeWhileInclusive}, - {"SkipWhileInclusive", &WrapSkipWhileInclusive}, - {"AddMember", &WrapAddMember}, - {"Member", &WrapMember}, - {"RemoveMember", &WrapRemoveMember}, - {"Exists", &WrapExists}, - {"Contains", &WrapContains}, - {"Lookup", &WrapLookup}, - {"ToSortedDict", &WrapToSortedDict}, - {"ToHashedDict", &WrapToHashedDict}, + {"Filter", &WrapFilter}, + {"OrderedFilter", &WrapFilter}, + {"TakeWhile", &WrapTakeWhile}, + {"SkipWhile", &WrapSkipWhile}, + {"TakeWhileInclusive", &WrapTakeWhileInclusive}, + {"SkipWhileInclusive", &WrapSkipWhileInclusive}, + {"AddMember", &WrapAddMember}, + {"Member", &WrapMember}, + {"RemoveMember", &WrapRemoveMember}, + {"Exists", &WrapExists}, + {"Contains", &WrapContains}, + {"Lookup", &WrapLookup}, + {"ToSortedDict", &WrapToSortedDict}, + {"ToHashedDict", &WrapToHashedDict}, {"SqueezeToList", &WrapSqueezeToList}, {"SqueezeToSortedDict", &WrapSqueezeToSortedDict}, {"SqueezeToHashedDict", &WrapSqueezeToHashedDict}, {"NarrowSqueezeToSortedDict", &WrapSqueezeToSortedDict}, {"NarrowSqueezeToHashedDict", &WrapSqueezeToHashedDict}, - {"Coalesce", &WrapCoalesce}, - {"ToOptional", &WrapHead}, - {"Head", &WrapHead}, + {"Coalesce", &WrapCoalesce}, + {"ToOptional", &WrapHead}, + {"Head", &WrapHead}, {"Last", &WrapLast}, - {"Unwrap", &WrapUnwrap}, - {"Ensure", &WrapEnsure}, - {"If", &WrapIf}, - {"IfPresent", &WrapIfPresent}, - {"And", &WrapAnd}, - {"Or", &WrapOr}, - {"Xor", &WrapXor}, - {"Not", &WrapNot}, - {"Zip", &WrapZip<false>}, - {"ZipAll", &WrapZip<true>}, - {"Reduce", &WrapReduce}, - {"Length", &WrapLength}, + {"Unwrap", &WrapUnwrap}, + {"Ensure", &WrapEnsure}, + {"If", &WrapIf}, + {"IfPresent", &WrapIfPresent}, + {"And", &WrapAnd}, + {"Or", &WrapOr}, + {"Xor", &WrapXor}, + {"Not", &WrapNot}, + {"Zip", &WrapZip<false>}, + {"ZipAll", &WrapZip<true>}, + {"Reduce", &WrapReduce}, + {"Length", &WrapLength}, {"Iterable", &WrapIterable}, - {"Iterator", &WrapIterator}, - {"EmptyIterator", &WrapEmptyIterator}, - {"ForwardList", &WrapForwardList}, - {"Switch", &WrapSwitch}, - {"Collect", &WrapCollect}, - {"ListFromRange", &WrapListFromRange}, - {"HasItems", &WrapHasItems}, - {"Reverse", &WrapReverse}, - {"Skip", &WrapSkip}, - {"Take", &WrapTake}, - {"Replicate", &WrapReplicate}, - {"Invoke", &WrapInvoke}, - {"Udf", &WrapUdf}, - {"ScriptUdf", &WrapScriptUdf}, - {"Apply", &WrapApply}, + {"Iterator", &WrapIterator}, + {"EmptyIterator", &WrapEmptyIterator}, + {"ForwardList", &WrapForwardList}, + {"Switch", &WrapSwitch}, + {"Collect", &WrapCollect}, + {"ListFromRange", &WrapListFromRange}, + {"HasItems", &WrapHasItems}, + {"Reverse", &WrapReverse}, + {"Skip", &WrapSkip}, + {"Take", &WrapTake}, + {"Replicate", &WrapReplicate}, + {"Invoke", &WrapInvoke}, + {"Udf", &WrapUdf}, + {"ScriptUdf", &WrapScriptUdf}, + {"Apply", &WrapApply}, {"Apply2", &WrapApply}, - {"Callable", &WrapCallable}, - {"Size", &WrapSize}, - {"ToString", &WrapToString}, - {"FromString", &WrapFromString}, - {"StrictFromString", &WrapStrictFromString}, - {"Enumerate", &WrapEnumerate}, - {"Sort", &WrapSort}, + {"Callable", &WrapCallable}, + {"Size", &WrapSize}, + {"ToString", &WrapToString}, + {"FromString", &WrapFromString}, + {"StrictFromString", &WrapStrictFromString}, + {"Enumerate", &WrapEnumerate}, + {"Sort", &WrapSort}, {"UnstableSort", &WrapUnstableSort}, - {"DictItems", &WrapDictItems}, + {"DictItems", &WrapDictItems}, {"DictKeys", &WrapDictKeys}, {"DictPayloads", &WrapDictPayloads}, - {"Nth", &WrapNth}, - {"ToIndexDict", &WrapToIndexDict}, - {"JoinDict", &WrapJoinDict}, - {"MapJoinCore", &WrapMapJoinCore}, - {"CommonJoinCore", &WrapCommonJoinCore}, - {"CombineCore", &WrapCombineCore}, - {"GroupingCore", &WrapGroupingCore}, - {"HoppingCore", &WrapHoppingCore}, + {"Nth", &WrapNth}, + {"ToIndexDict", &WrapToIndexDict}, + {"JoinDict", &WrapJoinDict}, + {"MapJoinCore", &WrapMapJoinCore}, + {"CommonJoinCore", &WrapCommonJoinCore}, + {"CombineCore", &WrapCombineCore}, + {"GroupingCore", &WrapGroupingCore}, + {"HoppingCore", &WrapHoppingCore}, {"MultiHoppingCore", &WrapMultiHoppingCore}, - {"ToBytes", &WrapToBytes}, - {"FromBytes", &WrapFromBytes}, - {"NewMTRand", &WrapNewMTRand}, - {"NextMTRand", &WrapNextMTRand}, - {"Random", &WrapRandom<ERandom::Double>}, - {"RandomNumber", &WrapRandom<ERandom::Number>}, - {"RandomUuid", &WrapRandom<ERandom::Uuid>}, - {"Now", &WrapNow}, - {"Pickle", &WrapPickle}, - {"StablePickle", &WrapStablePickle}, - {"Unpickle", &WrapUnpickle}, - {"Ascending", &WrapAscending}, - {"Descending", &WrapDescending}, - {"Guess", &WrapGuess}, - {"VariantItem", &WrapVariantItem}, - {"Way", &WrapWay}, - {"VisitAll", &WrapVisitAll}, - {"AggrCountInit", &WrapAggrCountInit}, - {"AggrCountUpdate", &WrapAggrCountUpdate}, - {"QueueCreate", &WrapQueueCreate}, - {"QueuePush", &WrapQueuePush}, - {"QueuePop", &WrapQueuePop}, - {"QueuePeek", &WrapQueuePeek}, + {"ToBytes", &WrapToBytes}, + {"FromBytes", &WrapFromBytes}, + {"NewMTRand", &WrapNewMTRand}, + {"NextMTRand", &WrapNextMTRand}, + {"Random", &WrapRandom<ERandom::Double>}, + {"RandomNumber", &WrapRandom<ERandom::Number>}, + {"RandomUuid", &WrapRandom<ERandom::Uuid>}, + {"Now", &WrapNow}, + {"Pickle", &WrapPickle}, + {"StablePickle", &WrapStablePickle}, + {"Unpickle", &WrapUnpickle}, + {"Ascending", &WrapAscending}, + {"Descending", &WrapDescending}, + {"Guess", &WrapGuess}, + {"VariantItem", &WrapVariantItem}, + {"Way", &WrapWay}, + {"VisitAll", &WrapVisitAll}, + {"AggrCountInit", &WrapAggrCountInit}, + {"AggrCountUpdate", &WrapAggrCountUpdate}, + {"QueueCreate", &WrapQueueCreate}, + {"QueuePush", &WrapQueuePush}, + {"QueuePop", &WrapQueuePop}, + {"QueuePeek", &WrapQueuePeek}, {"QueueRange", &WrapQueueRange}, {"Seq", &WrapSeq}, - {"PreserveStream", &WrapPreserveStream}, - {"FromYsonSimpleType", &WrapFromYsonSimpleType}, - {"TryWeakMemberFromDict", &WrapTryWeakMemberFromDict}, - {"TimezoneId", &WrapTimezoneId}, - {"TimezoneName", &WrapTimezoneName}, - {"AddTimezone", &WrapAddTimezone}, - {"DecimalDiv", &WrapDecimalDiv}, - {"DecimalMod", &WrapDecimalMod}, - {"DecimalMul", &WrapDecimalMul}, - {"ToFlow", &WrapToFlow}, - {"FromFlow", &WrapFromFlow}, + {"PreserveStream", &WrapPreserveStream}, + {"FromYsonSimpleType", &WrapFromYsonSimpleType}, + {"TryWeakMemberFromDict", &WrapTryWeakMemberFromDict}, + {"TimezoneId", &WrapTimezoneId}, + {"TimezoneName", &WrapTimezoneName}, + {"AddTimezone", &WrapAddTimezone}, + {"DecimalDiv", &WrapDecimalDiv}, + {"DecimalMod", &WrapDecimalMod}, + {"DecimalMul", &WrapDecimalMul}, + {"ToFlow", &WrapToFlow}, + {"FromFlow", &WrapFromFlow}, {"ToBlocks", &WrapToBlocks}, {"WideToBlocks", &WrapWideToBlocks}, {"BlockAdd", &WrapBlockAdd}, {"FromBlocks", &WrapFromBlocks}, {"AsSingle", &WrapAsSingle}, - {"MakeHeap", &WrapMakeHeap}, - {"PushHeap", &WrapPushHeap}, - {"PopHeap", &WrapPopHeap}, - {"SortHeap", &WrapSortHeap}, - {"StableSort", &WrapStableSort}, - {"NthElement", &WrapNthElement}, - {"PartialSort", &WrapPartialSort}, - {"KeepTop", &WrapKeepTop}, - {"Top", &WrapTop}, + {"MakeHeap", &WrapMakeHeap}, + {"PushHeap", &WrapPushHeap}, + {"PopHeap", &WrapPopHeap}, + {"SortHeap", &WrapSortHeap}, + {"StableSort", &WrapStableSort}, + {"NthElement", &WrapNthElement}, + {"PartialSort", &WrapPartialSort}, + {"KeepTop", &WrapKeepTop}, + {"Top", &WrapTop}, {"TopSort", &WrapTopSort}, - {"SourceOf", &WrapSourceOf}, + {"SourceOf", &WrapSourceOf}, {"LazyList", &WrapLazyList}, {"Chopper", &WrapChopper}, {"ExpandMap", &WrapExpandMap}, @@ -300,11 +300,11 @@ struct TCallableComputationNodeBuilderFuncMapFiller { {"RoundUp", &WrapRound}, {"RoundDown", &WrapRound}, {"NextValue", &WrapNextValue}, - }; + }; }; -} - +} + TComputationNodeFactory GetBuiltinFactory() { return [](TCallable& callable, const TComputationNodeFactoryContext& ctx) -> IComputationNode* { const auto& map = Singleton<TCallableComputationNodeBuilderFuncMapFiller>()->Map; diff --git a/ydb/library/yql/public/udf/udf_allocator.cpp b/ydb/library/yql/public/udf/udf_allocator.cpp index 31402b7c54..2250c0bf5a 100644 --- a/ydb/library/yql/public/udf/udf_allocator.cpp +++ b/ydb/library/yql/public/udf/udf_allocator.cpp @@ -1 +1 @@ -#include "udf_allocator.h" +#include "udf_allocator.h" diff --git a/ydb/library/yql/public/udf/udf_registrator.cpp b/ydb/library/yql/public/udf/udf_registrator.cpp index a8567e07e4..8588d59456 100644 --- a/ydb/library/yql/public/udf/udf_registrator.cpp +++ b/ydb/library/yql/public/udf/udf_registrator.cpp @@ -1 +1 @@ -#include "udf_registrator.h" +#include "udf_registrator.h" diff --git a/ydb/library/yql/public/udf/udf_string.cpp b/ydb/library/yql/public/udf/udf_string.cpp index f5b1a4031c..f4fe5adb0c 100644 --- a/ydb/library/yql/public/udf/udf_string.cpp +++ b/ydb/library/yql/public/udf/udf_string.cpp @@ -1 +1 @@ -#include "udf_string.h" +#include "udf_string.h" diff --git a/ydb/library/yql/public/udf/udf_value.cpp b/ydb/library/yql/public/udf/udf_value.cpp index d80ef72fb9..5a22b940f9 100644 --- a/ydb/library/yql/public/udf/udf_value.cpp +++ b/ydb/library/yql/public/udf/udf_value.cpp @@ -1 +1 @@ -#include "udf_value.h" +#include "udf_value.h" diff --git a/ydb/library/yql/utils/multi_resource_lock_ut.cpp b/ydb/library/yql/utils/multi_resource_lock_ut.cpp index 0af9cea3ff..2906acffd8 100644 --- a/ydb/library/yql/utils/multi_resource_lock_ut.cpp +++ b/ydb/library/yql/utils/multi_resource_lock_ut.cpp @@ -38,7 +38,7 @@ Y_UNIT_TEST_SUITE(TMultiResourceLock) { startEvent.Signal(); - NThreading::TFuture<void> all = NThreading::WaitExceptionOrAll(workers); + NThreading::TFuture<void> all = NThreading::WaitExceptionOrAll(workers); all.GetValueSync(); queue.Stop(); diff --git a/ydb/public/lib/idx_test/idx_test_upload.cpp b/ydb/public/lib/idx_test/idx_test_upload.cpp index 7c7252e34d..4193075d7c 100644 --- a/ydb/public/lib/idx_test/idx_test_upload.cpp +++ b/ydb/public/lib/idx_test/idx_test_upload.cpp @@ -131,7 +131,7 @@ private: resultFutures.push_back(RunUploadTask(dataProvider, shard, uploadFn).Apply(checker)); } - NThreading::WaitExceptionOrAll(resultFutures).Wait(); + NThreading::WaitExceptionOrAll(resultFutures).Wait(); if (errStatus) ThrowOnError(errStatus.GetRef()); } diff --git a/ydb/public/sdk/cpp/client/ydb_table/table.cpp b/ydb/public/sdk/cpp/client/ydb_table/table.cpp index 610fec3884..93dcc88645 100644 --- a/ydb/public/sdk/cpp/client/ydb_table/table.cpp +++ b/ydb/public/sdk/cpp/client/ydb_table/table.cpp @@ -1529,7 +1529,7 @@ public: } } sessions.clear(); - return NThreading::WaitExceptionOrAll(closeResults); + return NThreading::WaitExceptionOrAll(closeResults); } NThreading::TFuture<void> Stop() { diff --git a/ydb/services/ydb/ydb_table_ut.cpp b/ydb/services/ydb/ydb_table_ut.cpp index 4861c06b92..a6c2209fdd 100644 --- a/ydb/services/ydb/ydb_table_ut.cpp +++ b/ydb/services/ydb/ydb_table_ut.cpp @@ -276,7 +276,7 @@ Y_UNIT_TEST_SUITE(YdbYqlClient) { TTxControl::BeginTx(TTxSettings::SerializableRW()).CommitTx())); } - NThreading::WaitExceptionOrAll(results).Wait(); + NThreading::WaitExceptionOrAll(results).Wait(); UNIT_ASSERT_VALUES_EQUAL(client.GetActiveSessionCount(), 10); for (auto& result : results) { @@ -319,7 +319,7 @@ Y_UNIT_TEST_SUITE(YdbYqlClient) { } } - NThreading::WaitExceptionOrAll(results).Wait(); + NThreading::WaitExceptionOrAll(results).Wait(); UNIT_ASSERT_VALUES_EQUAL(client.GetActiveSessionCount(), 10); for (size_t i = 0; i < results.size(); i++) { @@ -527,7 +527,7 @@ Y_UNIT_TEST_SUITE(YdbYqlClient) { } for (auto& r : results) { - NThreading::WaitExceptionOrAll(r).Wait(); + NThreading::WaitExceptionOrAll(r).Wait(); } for (auto& r : results) { if (!r.empty()) { |