diff options
author | dobrokot <dobrokot@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:07 +0300 |
commit | 25d83bf841d8b3ce3886525078f1964ac3c293c5 (patch) | |
tree | bd52fa16c8dd727890b2ef9d87d1a402bd0d3a9a | |
parent | 1d2e8a8e9976488ea69a7e4763aa749244f82612 (diff) | |
download | ydb-25d83bf841d8b3ce3886525078f1964ac3c293c5.tar.gz |
Restoring authorship annotation for <dobrokot@yandex-team.ru>. Commit 1 of 2.
75 files changed, 1036 insertions, 1036 deletions
diff --git a/library/cpp/bit_io/bitoutput.h b/library/cpp/bit_io/bitoutput.h index 2b886c1f02..8df893b9f2 100644 --- a/library/cpp/bit_io/bitoutput.h +++ b/library/cpp/bit_io/bitoutput.h @@ -123,7 +123,7 @@ namespace NBitIO { public: void WriteData(const char* begin, const char* end) { - NAccessors::Append(*Data, begin, end); + NAccessors::Append(*Data, begin, end); } TBitOutputVectorImpl(TVec* data) diff --git a/library/cpp/bucket_quoter/ya.make b/library/cpp/bucket_quoter/ya.make index 49c407b502..ebf87e4606 100644 --- a/library/cpp/bucket_quoter/ya.make +++ b/library/cpp/bucket_quoter/ya.make @@ -1,11 +1,11 @@ -LIBRARY() - -OWNER(serxa) - -SRCS( - bucket_quoter.cpp -) - -END() +LIBRARY() + +OWNER(serxa) + +SRCS( + bucket_quoter.cpp +) + +END() RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/cgiparam/cgiparam.cpp b/library/cpp/cgiparam/cgiparam.cpp index f3277b8e4b..bdd012d6d3 100644 --- a/library/cpp/cgiparam/cgiparam.cpp +++ b/library/cpp/cgiparam/cgiparam.cpp @@ -90,7 +90,7 @@ static inline TString DoUnescape(const TStringBuf s) { } void TCgiParameters::InsertEscaped(const TStringBuf name, const TStringBuf value) { - InsertUnescaped(DoUnescape(name), DoUnescape(value)); + InsertUnescaped(DoUnescape(name), DoUnescape(value)); } template <bool addAll, class F> @@ -102,17 +102,17 @@ struct TAddEscaped { TCgiParameters* C; inline void operator()(const TStringBuf key, const TStringBuf val) { - C->InsertEscaped(key, val); + C->InsertEscaped(key, val); } }; void TCgiParameters::Scan(const TStringBuf query, bool form) { Flush(); - form ? ScanAdd(query) : ScanAddAll(query); + form ? ScanAdd(query) : ScanAddAll(query); } void TCgiParameters::ScanAdd(const TStringBuf query) { - TAddEscaped f = {this}; + TAddEscaped f = {this}; DoScan<false>(query, f); } @@ -134,7 +134,7 @@ void TCgiParameters::ScanAddAllUnescaped(const TStringBuf query) { } void TCgiParameters::ScanAddAll(const TStringBuf query) { - TAddEscaped f = {this}; + TAddEscaped f = {this}; DoScan<true>(query, f); } diff --git a/library/cpp/charset/codepage_ut.cpp b/library/cpp/charset/codepage_ut.cpp index c3ac3ac478..8d2f8f6989 100644 --- a/library/cpp/charset/codepage_ut.cpp +++ b/library/cpp/charset/codepage_ut.cpp @@ -121,43 +121,43 @@ void TCodepageTest::TestUTF() { } } const char* badStrings[] = { - "\xfe", - "\xff", - "\xcc\xc0", + "\xfe", + "\xff", + "\xcc\xc0", "\xf4\x90\x80\x80", - //overlong: - "\xfe\xfe\xff\xff", - "\xc0\xaf", - "\xe0\x80\xaf", - "\xf0\x80\x80\xaf", - "\xf8\x80\x80\x80\xaf", - "\xfc\x80\x80\x80\x80\xaf", - "\xc1\xbf", - "\xe0\x9f\xbf", - "\xf0\x8f\xbf\xbf", - "\xf8\x87\xbf\xbf\xbf", - "\xfc\x83\xbf\xbf\xbf\xbf", - "\xc0\x80", - "\xe0\x80\x80", - "\xf0\x80\x80\x80", - "\xf8\x80\x80\x80\x80", - "\xfc\x80\x80\x80\x80\x80", - //UTF-16 surrogate (not covered): - //"\xed\xa0\x80", - //"\xed\xad\xbf", - //"\xed\xae\x80", - //"\xed\xaf\xbf", - //"\xed\xb0\x80", - //"\xed\xbe\x80", - //"\xed\xbf\xbf", - }; + //overlong: + "\xfe\xfe\xff\xff", + "\xc0\xaf", + "\xe0\x80\xaf", + "\xf0\x80\x80\xaf", + "\xf8\x80\x80\x80\xaf", + "\xfc\x80\x80\x80\x80\xaf", + "\xc1\xbf", + "\xe0\x9f\xbf", + "\xf0\x8f\xbf\xbf", + "\xf8\x87\xbf\xbf\xbf", + "\xfc\x83\xbf\xbf\xbf\xbf", + "\xc0\x80", + "\xe0\x80\x80", + "\xf0\x80\x80\x80", + "\xf8\x80\x80\x80\x80", + "\xfc\x80\x80\x80\x80\x80", + //UTF-16 surrogate (not covered): + //"\xed\xa0\x80", + //"\xed\xad\xbf", + //"\xed\xae\x80", + //"\xed\xaf\xbf", + //"\xed\xb0\x80", + //"\xed\xbe\x80", + //"\xed\xbf\xbf", + }; for (size_t i = 0; i < Y_ARRAY_SIZE(badStrings); ++i) { - wchar32 rune; + wchar32 rune; const ui8* p = (const ui8*)badStrings[i]; - size_t len; + size_t len; RECODE_RESULT res = SafeReadUTF8Char(rune, len, p, p + strlen(badStrings[i])); - UNIT_ASSERT(res == RECODE_BROKENSYMBOL); - } + UNIT_ASSERT(res == RECODE_BROKENSYMBOL); + } } void TCodepageTest::TestBrokenMultibyte() { diff --git a/library/cpp/containers/comptrie/comptrie_builder.inl b/library/cpp/containers/comptrie/comptrie_builder.inl index f273fa6571..850d84121c 100644 --- a/library/cpp/containers/comptrie/comptrie_builder.inl +++ b/library/cpp/containers/comptrie/comptrie_builder.inl @@ -377,7 +377,7 @@ public: case DATA_MALLOCED: case DATA_IN_MEMPOOL: return PayloadAsPtr(); - case DATA_ABSENT: + case DATA_ABSENT: default: abort(); } diff --git a/library/cpp/containers/comptrie/comptrie_trie.h b/library/cpp/containers/comptrie/comptrie_trie.h index 40ec1e52b3..0ddc04c058 100644 --- a/library/cpp/containers/comptrie/comptrie_trie.h +++ b/library/cpp/containers/comptrie/comptrie_trie.h @@ -110,10 +110,10 @@ public: return Skipper; } - TPacker GetPacker() const { - return Packer; - } - + TPacker GetPacker() const { + return Packer; + } + bool HasCorrectSkipper() const { return Skipper.GetPacker() == &Packer; } @@ -175,9 +175,9 @@ public: }; TConstIterator Begin() const; - TConstIterator begin() const; + TConstIterator begin() const; TConstIterator End() const; - TConstIterator end() const; + TConstIterator end() const; // Returns an iterator pointing to the smallest key in the trie >= the argument. // TODO: misleading name. Should be called LowerBound for consistency with stl. @@ -422,22 +422,22 @@ typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::Begin() co } template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::begin() const { - return Begin(); -} - -template <class T, class D, class S> +typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::begin() const { + return Begin(); +} + +template <class T, class D, class S> typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::End() const { NCompactTrie::TOpaqueTrie self(DataHolder.AsCharPtr(), DataHolder.Length(), Skipper); return TConstIterator(self, EmptyValue, true, Packer); } template <class T, class D, class S> -typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::end() const { - return End(); -} - -template <class T, class D, class S> +typename TCompactTrie<T, D, S>::TConstIterator TCompactTrie<T, D, S>::end() const { + return End(); +} + +template <class T, class D, class S> size_t TCompactTrie<T, D, S>::Size() const { size_t res = 0; for (TConstIterator it = Begin(); it != End(); ++it) diff --git a/library/cpp/containers/comptrie/comptrie_ut.cpp b/library/cpp/containers/comptrie/comptrie_ut.cpp index 74bee09b5d..cfc820592c 100644 --- a/library/cpp/containers/comptrie/comptrie_ut.cpp +++ b/library/cpp/containers/comptrie/comptrie_ut.cpp @@ -445,11 +445,11 @@ void TCompactTrieTest::CheckIterator(const char* data, size_t datalen) { } TMap<TKey, ui64> received2; for (std::pair<TKey, ui64> x : trie) { - received2.insert(x); - } + received2.insert(x); + } UNIT_ASSERT(entry_count == stored.size()); UNIT_ASSERT(received == stored); - UNIT_ASSERT(received2 == stored); + UNIT_ASSERT(received2 == stored); std::reverse(items.begin(), items.end()); typename TCompactTrie<T>::TConstIterator revIt = trie.End(); diff --git a/library/cpp/deprecated/accessors/accessors.h b/library/cpp/deprecated/accessors/accessors.h index 6d4b1da3ad..ab7c0cfb83 100644 --- a/library/cpp/deprecated/accessors/accessors.h +++ b/library/cpp/deprecated/accessors/accessors.h @@ -37,44 +37,44 @@ namespace NAccessors { inline size_t Size(const T& t) { return End(t) - Begin(t); } - - /** - * This gives some unification in terms of memory manipulation. - */ - - template <typename T> - inline void Reserve(T& t, size_t sz) { - NPrivate::TReserve<T>::Do(t, sz); - } - - template <typename T> - inline void Resize(T& t, size_t sz) { - NPrivate::TResize<T>::Do(t, sz); - } - - template <typename T> - inline void Clear(T& t) { - NPrivate::TClear<T, false>::Do(t); - } - - template <typename T> - inline void Init(T& t) { - NPrivate::TClear<T, true>::Do(t); - } - - template <typename T> - inline void Append(T& t, const typename TMemoryTraits<T>::TElementType& v) { - NPrivate::TAppend<T>::Do(t, v); - } - - template <typename T> - inline void Append(T& t, - const typename TMemoryTraits<T>::TElementType* beg, - const typename TMemoryTraits<T>::TElementType* end) { - NPrivate::TAppendRegion<T>::Do(t, beg, end); - } - + + /** + * This gives some unification in terms of memory manipulation. + */ + template <typename T> + inline void Reserve(T& t, size_t sz) { + NPrivate::TReserve<T>::Do(t, sz); + } + + template <typename T> + inline void Resize(T& t, size_t sz) { + NPrivate::TResize<T>::Do(t, sz); + } + + template <typename T> + inline void Clear(T& t) { + NPrivate::TClear<T, false>::Do(t); + } + + template <typename T> + inline void Init(T& t) { + NPrivate::TClear<T, true>::Do(t); + } + + template <typename T> + inline void Append(T& t, const typename TMemoryTraits<T>::TElementType& v) { + NPrivate::TAppend<T>::Do(t, v); + } + + template <typename T> + inline void Append(T& t, + const typename TMemoryTraits<T>::TElementType* beg, + const typename TMemoryTraits<T>::TElementType* end) { + NPrivate::TAppendRegion<T>::Do(t, beg, end); + } + + template <typename T> inline void Assign(T& t, const typename TMemoryTraits<T>::TElementType* beg, const typename TMemoryTraits<T>::TElementType* end) { diff --git a/library/cpp/deprecated/accessors/accessors_impl.h b/library/cpp/deprecated/accessors/accessors_impl.h index 6b2b987351..61d1956a1f 100644 --- a/library/cpp/deprecated/accessors/accessors_impl.h +++ b/library/cpp/deprecated/accessors/accessors_impl.h @@ -113,236 +113,236 @@ namespace NAccessors { return TGet::Get(b); } }; - - template <typename Ta, bool Init> - struct TClear: public TMemoryAccessorBase<Ta> { - template <typename Tb> - struct TNoMemoryIndirectionClear { - static void Do(Tb& b) { - Zero(b); - } - }; - - template <typename Tb> - struct TIndirectMemoryRegionClear { + + template <typename Ta, bool Init> + struct TClear: public TMemoryAccessorBase<Ta> { + template <typename Tb> + struct TNoMemoryIndirectionClear { + static void Do(Tb& b) { + Zero(b); + } + }; + + template <typename Tb> + struct TIndirectMemoryRegionClear { Y_HAS_MEMBER(Clear); Y_HAS_MEMBER(clear); - - template <typename Tc> - struct TByClear { - static void Do(Tc& b) { - b.Clear(); - } - }; - - template <typename Tc> - struct TByclear { - static void Do(Tc& b) { - b.clear(); - } - }; - - template <typename Tc> - struct TByNone { - static void Do(Tc& b) { - if (!Init) - b = Tc(); - } - }; - + + template <typename Tc> + struct TByClear { + static void Do(Tc& b) { + b.Clear(); + } + }; + + template <typename Tc> + struct TByclear { + static void Do(Tc& b) { + b.clear(); + } + }; + + template <typename Tc> + struct TByNone { + static void Do(Tc& b) { + if (!Init) + b = Tc(); + } + }; + using TDo = std::conditional_t< THasClear<Tb>::value, - TByClear<Tb>, + TByClear<Tb>, std::conditional_t< THasclear<Tb>::value, - TByclear<Tb>, - TByNone<Tb>>>; - - static void Do(Tb& b) { - TDo::Do(b); - } - }; - + TByclear<Tb>, + TByNone<Tb>>>; + + static void Do(Tb& b) { + TDo::Do(b); + } + }; + using TDo = std::conditional_t<TMemoryAccessorBase<Ta>::SimpleMemory, TNoMemoryIndirectionClear<Ta>, TIndirectMemoryRegionClear<Ta>>; - - static void Do(Ta& b) { - TDo::Do(b); - } - }; - - template <typename Tb> - struct TReserve { + + static void Do(Ta& b) { + TDo::Do(b); + } + }; + + template <typename Tb> + struct TReserve { Y_HAS_MEMBER(Reserve); Y_HAS_MEMBER(reserve); - - template <typename Tc> - struct TByReserve { - static void Do(Tc& b, size_t sz) { - b.Reserve(sz); - } - }; - - template <typename Tc> - struct TByreserve { - static void Do(Tc& b, size_t sz) { - b.reserve(sz); - } - }; - - template <typename Tc> - struct TByNone { - static void Do(Tc&, size_t) { - } - }; - + + template <typename Tc> + struct TByReserve { + static void Do(Tc& b, size_t sz) { + b.Reserve(sz); + } + }; + + template <typename Tc> + struct TByreserve { + static void Do(Tc& b, size_t sz) { + b.reserve(sz); + } + }; + + template <typename Tc> + struct TByNone { + static void Do(Tc&, size_t) { + } + }; + using TDo = std::conditional_t< THasReserve<Tb>::value, - TByReserve<Tb>, + TByReserve<Tb>, std::conditional_t< THasreserve<Tb>::value, - TByreserve<Tb>, - TByNone<Tb>>>; - - static void Do(Tb& b, size_t sz) { - TDo::Do(b, sz); - } - }; - - template <typename Tb> - struct TResize { + TByreserve<Tb>, + TByNone<Tb>>>; + + static void Do(Tb& b, size_t sz) { + TDo::Do(b, sz); + } + }; + + template <typename Tb> + struct TResize { Y_HAS_MEMBER(Resize); Y_HAS_MEMBER(resize); - - template <typename Tc> - struct TByResize { - static void Do(Tc& b, size_t sz) { - b.Resize(sz); - } - }; - - template <typename Tc> - struct TByresize { - static void Do(Tc& b, size_t sz) { - b.resize(sz); - } - }; - + + template <typename Tc> + struct TByResize { + static void Do(Tc& b, size_t sz) { + b.Resize(sz); + } + }; + + template <typename Tc> + struct TByresize { + static void Do(Tc& b, size_t sz) { + b.resize(sz); + } + }; + using TDo = std::conditional_t<THasResize<Tb>::value, TByResize<Tb>, TByresize<Tb>>; - - static void Do(Tb& b, size_t sz) { - TDo::Do(b, sz); - } - }; - - template <typename Tb> - struct TAppend { + + static void Do(Tb& b, size_t sz) { + TDo::Do(b, sz); + } + }; + + template <typename Tb> + struct TAppend { Y_HAS_MEMBER(Append); Y_HAS_MEMBER(append); Y_HAS_MEMBER(push_back); - - template <typename Tc> - struct TByAppend { - using TElementType = typename TMemoryTraits<Tc>::TElementType; - - static void Do(Tc& b, const TElementType& val) { - b.Append(val); - } - }; - - template <typename Tc> - struct TByappend { - using TElementType = typename TMemoryTraits<Tc>::TElementType; - - static void Do(Tc& b, const TElementType& val) { - b.append(val); - } - }; - - template <typename Tc> - struct TBypush_back { - using TElementType = typename TMemoryTraits<Tc>::TElementType; - - static void Do(Tc& b, const TElementType& val) { - b.push_back(val); - } - }; - + + template <typename Tc> + struct TByAppend { + using TElementType = typename TMemoryTraits<Tc>::TElementType; + + static void Do(Tc& b, const TElementType& val) { + b.Append(val); + } + }; + + template <typename Tc> + struct TByappend { + using TElementType = typename TMemoryTraits<Tc>::TElementType; + + static void Do(Tc& b, const TElementType& val) { + b.append(val); + } + }; + + template <typename Tc> + struct TBypush_back { + using TElementType = typename TMemoryTraits<Tc>::TElementType; + + static void Do(Tc& b, const TElementType& val) { + b.push_back(val); + } + }; + using TDo = std::conditional_t< THasAppend<Tb>::value, - TByAppend<Tb>, + TByAppend<Tb>, std::conditional_t< THasappend<Tb>::value, - TByappend<Tb>, - TBypush_back<Tb>>>; - - using TElementType = typename TMemoryTraits<Tb>::TElementType; - - static void Do(Tb& b, const TElementType& val) { - TDo::Do(b, val); - } - }; - - template <typename Tb> - struct TAppendRegion { + TByappend<Tb>, + TBypush_back<Tb>>>; + + using TElementType = typename TMemoryTraits<Tb>::TElementType; + + static void Do(Tb& b, const TElementType& val) { + TDo::Do(b, val); + } + }; + + template <typename Tb> + struct TAppendRegion { Y_HAS_MEMBER(Append); Y_HAS_MEMBER(append); Y_HAS_MEMBER(insert); - - template <typename Tc> - struct TByAppend { - using TElementType = typename TMemoryTraits<Tc>::TElementType; - - static void Do(Tc& b, const TElementType* beg, const TElementType* end) { - b.Append(beg, end); - } - }; - - template <typename Tc> - struct TByappend { - using TElementType = typename TMemoryTraits<Tc>::TElementType; - - static void Do(Tc& b, const TElementType* beg, const TElementType* end) { - b.append(beg, end); - } - }; - - template <typename Tc> - struct TByinsert { - using TElementType = typename TMemoryTraits<Tc>::TElementType; - - static void Do(Tc& b, const TElementType* beg, const TElementType* end) { - b.insert(b.end(), beg, end); - } - }; - - template <typename Tc> - struct TByNone { - using TElementType = typename TMemoryTraits<Tc>::TElementType; - - static void Do(Tc& b, const TElementType* beg, const TElementType* end) { - for (const TElementType* it = beg; it != end; ++it) - TAppend<Tc>::Do(b, *it); - } - }; - + + template <typename Tc> + struct TByAppend { + using TElementType = typename TMemoryTraits<Tc>::TElementType; + + static void Do(Tc& b, const TElementType* beg, const TElementType* end) { + b.Append(beg, end); + } + }; + + template <typename Tc> + struct TByappend { + using TElementType = typename TMemoryTraits<Tc>::TElementType; + + static void Do(Tc& b, const TElementType* beg, const TElementType* end) { + b.append(beg, end); + } + }; + + template <typename Tc> + struct TByinsert { + using TElementType = typename TMemoryTraits<Tc>::TElementType; + + static void Do(Tc& b, const TElementType* beg, const TElementType* end) { + b.insert(b.end(), beg, end); + } + }; + + template <typename Tc> + struct TByNone { + using TElementType = typename TMemoryTraits<Tc>::TElementType; + + static void Do(Tc& b, const TElementType* beg, const TElementType* end) { + for (const TElementType* it = beg; it != end; ++it) + TAppend<Tc>::Do(b, *it); + } + }; + using TDo = std::conditional_t< THasAppend<Tb>::value, - TByAppend<Tb>, + TByAppend<Tb>, std::conditional_t< THasappend<Tb>::value, - TByappend<Tb>, + TByappend<Tb>, std::conditional_t< THasinsert<Tb>::value, - TByinsert<Tb>, - TByNone<Tb>>>>; - - using TElementType = typename TMemoryTraits<Tb>::TElementType; - - static void Do(Tb& b, const TElementType* beg, const TElementType* end) { - TDo::Do(b, beg, end); - } - }; - + TByinsert<Tb>, + TByNone<Tb>>>>; + + using TElementType = typename TMemoryTraits<Tb>::TElementType; + + static void Do(Tb& b, const TElementType* beg, const TElementType* end) { + TDo::Do(b, beg, end); + } + }; + template <typename Ta> struct TAssign: public TMemoryAccessorBase<Ta> { using TElementType = typename TMemoryTraits<Ta>::TElementType; diff --git a/library/cpp/deprecated/accessors/accessors_ut.cpp b/library/cpp/deprecated/accessors/accessors_ut.cpp index a9bdc9fcc4..794efbf25a 100644 --- a/library/cpp/deprecated/accessors/accessors_ut.cpp +++ b/library/cpp/deprecated/accessors/accessors_ut.cpp @@ -22,30 +22,30 @@ private: UNIT_ASSERT_VALUES_EQUAL_C(end - beg, sz, comm); } - template <typename T> - void TestWrite(const char* comm) { - typename TMemoryTraits<T>::TElementType val[4] = {'t', 'e', 's', 't'}; - T t; - NAccessors::Init(t); - NAccessors::Reserve(t, 6); - - size_t sz = NAccessors::Size(t); - UNIT_ASSERT_VALUES_EQUAL_C(0u, sz, comm); - - NAccessors::Append(t, 'a'); - sz = NAccessors::Size(t); - UNIT_ASSERT_VALUES_EQUAL_C(1u, sz, comm); - - NAccessors::Append(t, val, val + 4); - sz = NAccessors::Size(t); - UNIT_ASSERT_VALUES_EQUAL_C(5u, sz, comm); - - NAccessors::Clear(t); - - sz = NAccessors::Size(t); - UNIT_ASSERT_VALUES_EQUAL_C(0u, sz, comm); - } - + template <typename T> + void TestWrite(const char* comm) { + typename TMemoryTraits<T>::TElementType val[4] = {'t', 'e', 's', 't'}; + T t; + NAccessors::Init(t); + NAccessors::Reserve(t, 6); + + size_t sz = NAccessors::Size(t); + UNIT_ASSERT_VALUES_EQUAL_C(0u, sz, comm); + + NAccessors::Append(t, 'a'); + sz = NAccessors::Size(t); + UNIT_ASSERT_VALUES_EQUAL_C(1u, sz, comm); + + NAccessors::Append(t, val, val + 4); + sz = NAccessors::Size(t); + UNIT_ASSERT_VALUES_EQUAL_C(5u, sz, comm); + + NAccessors::Clear(t); + + sz = NAccessors::Size(t); + UNIT_ASSERT_VALUES_EQUAL_C(0u, sz, comm); + } + void TestAccessors() { TestRead('a', "char"); TestRead(1, "int"); @@ -74,17 +74,17 @@ private: TestWrite<TString>("TString"); TestWrite<TVector<char>>("TVector<char>"); - TestWrite<TBuffer>("TBuffer"); + TestWrite<TBuffer>("TBuffer"); TestWrite<TVector<ui64>>("TVector<ui64>"); TestWrite<TUtf16String>("TUtf16String"); - + std::array<TString, 10> sarr; - NAccessors::Init(sarr); - NAccessors::Clear(sarr); - + NAccessors::Init(sarr); + NAccessors::Clear(sarr); + std::array<char, 10> carr; - NAccessors::Init(carr); - NAccessors::Clear(carr); + NAccessors::Init(carr); + NAccessors::Clear(carr); TestRead(carr, "std::array<char, 10>"); } }; diff --git a/library/cpp/deprecated/split/delim_string_iter.h b/library/cpp/deprecated/split/delim_string_iter.h index 8e4ca171a0..5bf1348bcc 100644 --- a/library/cpp/deprecated/split/delim_string_iter.h +++ b/library/cpp/deprecated/split/delim_string_iter.h @@ -136,26 +136,26 @@ private: TStringBuf Delim; }; -//example: for (TStringBuf field: TDelimStroka(line, "@@")) { ... } +//example: for (TStringBuf field: TDelimStroka(line, "@@")) { ... } struct TDelimStroka { - TStringBuf S; - TStringBuf Delim; - + TStringBuf S; + TStringBuf Delim; + inline TDelimStroka(TStringBuf s, TStringBuf delim) - : S(s) - , Delim(delim) + : S(s) + , Delim(delim) { } - + inline TDelimStringIter begin() const { return TDelimStringIter(S, Delim); - } - + } + inline TDelimStringIter end() const { return TDelimStringIter(); - } -}; - + } +}; + inline TDelimStringIter begin_delim(const TString& str, TStringBuf delim) { return TDelimStringIter(str, delim); } diff --git a/library/cpp/deprecated/split/delim_string_iter_ut.cpp b/library/cpp/deprecated/split/delim_string_iter_ut.cpp index 18a8b2a160..c9d94b4a1d 100644 --- a/library/cpp/deprecated/split/delim_string_iter_ut.cpp +++ b/library/cpp/deprecated/split/delim_string_iter_ut.cpp @@ -38,17 +38,17 @@ Y_UNIT_TEST_SUITE(TDelimStrokaIterTestSuite) { ++it; UNIT_ASSERT_STRINGS_EQUAL(it.Cdr(), ""); } - + Y_UNIT_TEST(ForIter) { TVector<TStringBuf> expected = {"1", "", "3@4", ""}; TVector<TStringBuf> got; - + for (TStringBuf x : TDelimStroka("1@@@@3@4@@", "@@")) { - got.push_back(x); - } - - UNIT_ASSERT_EQUAL(got, expected); - } + got.push_back(x); + } + + UNIT_ASSERT_EQUAL(got, expected); + } } static void AssertKeyValueStringSplit( diff --git a/library/cpp/getopt/small/opt.h b/library/cpp/getopt/small/opt.h index ecb57439bc..6bd81e62cb 100644 --- a/library/cpp/getopt/small/opt.h +++ b/library/cpp/getopt/small/opt.h @@ -94,9 +94,9 @@ public: } TVector<TString> GetFreeArgs() const { - return NLastGetopt::TOptsParseResult(&*Opts_, GetArgC(), GetArgV()).GetFreeArgs(); - } - + return NLastGetopt::TOptsParseResult(&*Opts_, GetArgC(), GetArgV()).GetFreeArgs(); + } + // obsolete, use GetArg() instead char* Arg; /* option argument if any or NULL */ diff --git a/library/cpp/getopt/ut/opt_ut.cpp b/library/cpp/getopt/ut/opt_ut.cpp index 441aa493a0..0148831799 100644 --- a/library/cpp/getopt/ut/opt_ut.cpp +++ b/library/cpp/getopt/ut/opt_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/getopt/opt.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/string/vector.h> +#include <util/string/vector.h> Y_UNIT_TEST_SUITE(OptTest) { Y_UNIT_TEST(TestSimple) { @@ -15,38 +15,38 @@ Y_UNIT_TEST_SUITE(OptTest) { UNIT_ASSERT_VALUES_EQUAL(EOF, opt.Get()); UNIT_ASSERT_VALUES_EQUAL(EOF, opt.Get()); } - + Y_UNIT_TEST(TestFreeArguments) { - Opt::Ion options[] = { + Opt::Ion options[] = { {"some-option", Opt::WithArg, nullptr, 123}, {nullptr, Opt::WithoutArg, nullptr, 0}}; const char* argv[] = {"cmd", "ARG1", "-some-option", "ARG2", "ARG3", nullptr}; - int argc = 5; - Opt opts(argc, argv, "", options); - + int argc = 5; + Opt opts(argc, argv, "", options); + UNIT_ASSERT_VALUES_EQUAL(JoinStrings(opts.GetFreeArgs(), ", "), "ARG1, ARG3"); - } - + } + Y_UNIT_TEST(TestLongOption) { - const int SOME_OPTION_ID = 12345678; - Opt::Ion options[] = { + const int SOME_OPTION_ID = 12345678; + Opt::Ion options[] = { {"some-option", Opt::WithArg, nullptr, SOME_OPTION_ID}, {nullptr, Opt::WithoutArg, nullptr, 0}}; - for (int doubleDash = 0; doubleDash <= 1; ++doubleDash) { + for (int doubleDash = 0; doubleDash <= 1; ++doubleDash) { const char* argv[] = {"cmd", "ARG1", (doubleDash ? "--some-option" : "-some-option"), "ARG2", "ARG3", nullptr}; - int argc = 5; - Opt opts(argc, argv, "", options); - + int argc = 5; + Opt opts(argc, argv, "", options); + TString optionValue = ""; - int optlet = 0; - while ((optlet = opts.Get()) != EOF) { - if (optlet == SOME_OPTION_ID) { - optionValue = opts.GetArg(); + int optlet = 0; + while ((optlet = opts.Get()) != EOF) { + if (optlet == SOME_OPTION_ID) { + optionValue = opts.GetArg(); } else { - UNIT_FAIL("don't expected any options, except -some-option"); - } - } - UNIT_ASSERT_VALUES_EQUAL(optionValue, "ARG2"); - } - } + UNIT_FAIL("don't expected any options, except -some-option"); + } + } + UNIT_ASSERT_VALUES_EQUAL(optionValue, "ARG2"); + } + } } diff --git a/library/cpp/html/pcdata/pcdata.cpp b/library/cpp/html/pcdata/pcdata.cpp index 740c240fd2..3a8ded72d4 100644 --- a/library/cpp/html/pcdata/pcdata.cpp +++ b/library/cpp/html/pcdata/pcdata.cpp @@ -47,15 +47,15 @@ static void EncodeHtmlPcdataAppendInternal(const TStringBuf str, TString& strout break; } } -} +} void EncodeHtmlPcdataAppend(const TStringBuf str, TString& strout) { - EncodeHtmlPcdataAppendInternal(str, strout, true); -} - + EncodeHtmlPcdataAppendInternal(str, strout, true); +} + TString EncodeHtmlPcdata(const TStringBuf str, bool qAmp) { TString strout; - EncodeHtmlPcdataAppendInternal(str, strout, qAmp); + EncodeHtmlPcdataAppendInternal(str, strout, qAmp); return strout; } diff --git a/library/cpp/html/pcdata/pcdata_ut.cpp b/library/cpp/html/pcdata/pcdata_ut.cpp index 5833f8bc59..8bd59351cc 100644 --- a/library/cpp/html/pcdata/pcdata_ut.cpp +++ b/library/cpp/html/pcdata/pcdata_ut.cpp @@ -31,18 +31,18 @@ Y_UNIT_TEST_SUITE(TPcdata) { Y_UNIT_TEST(Test2) { UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("&qqq"), "&qqq"); } - + Y_UNIT_TEST(TestEncodeHtmlPcdataAppend) { TString s; - EncodeHtmlPcdataAppend("m&m", s); - EncodeHtmlPcdataAppend("'s", s); - UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's"), s); - UNIT_ASSERT_VALUES_EQUAL("m&m's", s); - } - + EncodeHtmlPcdataAppend("m&m", s); + EncodeHtmlPcdataAppend("'s", s); + UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's"), s); + UNIT_ASSERT_VALUES_EQUAL("m&m's", s); + } + Y_UNIT_TEST(TestStrangeAmpParameter) { UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's", true), "m&m's"); UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's"), "m&m's"); //default - UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's", false), "m&m's"); - } + UNIT_ASSERT_VALUES_EQUAL(EncodeHtmlPcdata("m&m's", false), "m&m's"); + } } diff --git a/library/cpp/json/ut/json_writer_ut.cpp b/library/cpp/json/ut/json_writer_ut.cpp index ca11d34dad..bcb1af0f24 100644 --- a/library/cpp/json/ut/json_writer_ut.cpp +++ b/library/cpp/json/ut/json_writer_ut.cpp @@ -179,14 +179,14 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) { UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected); } } - + Y_UNIT_TEST(Callback) { - NJsonWriter::TBuf json; - json.WriteString("A"); - UNIT_ASSERT_VALUES_EQUAL(json.Str(), "\"A\""); - UNIT_ASSERT_VALUES_EQUAL(WrapJsonToCallback(json, ""), "\"A\""); - UNIT_ASSERT_VALUES_EQUAL(WrapJsonToCallback(json, "Foo"), "Foo(\"A\")"); - } + NJsonWriter::TBuf json; + json.WriteString("A"); + UNIT_ASSERT_VALUES_EQUAL(json.Str(), "\"A\""); + UNIT_ASSERT_VALUES_EQUAL(WrapJsonToCallback(json, ""), "\"A\""); + UNIT_ASSERT_VALUES_EQUAL(WrapJsonToCallback(json, "Foo"), "Foo(\"A\")"); + } Y_UNIT_TEST(FloatPrecision) { const double value = 1517933989.4242; diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index 02370c2d79..85642e6d8e 100644 --- a/library/cpp/json/writer/json.cpp +++ b/library/cpp/json/writer/json.cpp @@ -506,8 +506,8 @@ namespace NJsonWriter { NeedComma = from.NeedComma; NeedNewline = from.NeedNewline; Stack = from.Stack; - } - + } + void TBuf::Reset(TBufState&& from) { NeedComma = from.NeedComma; NeedNewline = from.NeedNewline; diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h index 0aae2531b9..64ec7a4253 100644 --- a/library/cpp/json/writer/json.h +++ b/library/cpp/json/writer/json.h @@ -284,6 +284,6 @@ namespace NJsonWriter { TPairContext TValueWriter<TOutContext>::BeginObject() { return Buf.BeginObject(); } - + TString WrapJsonToCallback(const TBuf& buf, TStringBuf callback); } diff --git a/library/cpp/lwtrace/signature.h b/library/cpp/lwtrace/signature.h index 868bd9bcf2..b263fe5298 100644 --- a/library/cpp/lwtrace/signature.h +++ b/library/cpp/lwtrace/signature.h @@ -545,9 +545,9 @@ namespace NLWTrace { STORE_TYPE_AS(i32, i64); STORE_TYPE_AS(bool, ui64); STORE_TYPE_AS(float, double); -#define FOREACH_PARAMTYPE_MACRO(n, t, v) STORE_TYPE_AS(t, t) +#define FOREACH_PARAMTYPE_MACRO(n, t, v) STORE_TYPE_AS(t, t) FOREACH_PARAMTYPE(FOREACH_PARAMTYPE_MACRO) -#undef STORE_TYPE_AS +#undef STORE_TYPE_AS #undef FOREACH_PARAMTYPE_MACRO // Nil type staits. diff --git a/library/cpp/lwtrace/tests/test_all_parallel.sh b/library/cpp/lwtrace/tests/test_all_parallel.sh index 8020783d67..5351bef969 100755 --- a/library/cpp/lwtrace/tests/test_all_parallel.sh +++ b/library/cpp/lwtrace/tests/test_all_parallel.sh @@ -1,29 +1,29 @@ - -mkdir -p out - -echo " - LogIntModFilter - SleepCheck - MultipleActionsCheck - KillCheck - InMemoryLog - InMemoryLogCheck - NoExec - Log - LogTs - FalseIntFilter - LogIntAfterFilter - LogInt - FalseStringFilter - FalseStringFilterPartialMatch - LogStringAfterFilter - LogString - LogCheck -" | awk NF | ( while read l; do ./tests --unsafe-lwtrace 1 $l > out/out_$l.txt 2>out/err_$l.txt && echo done $l & done ; wait ) - - -grep . out/out_*.txt -grep . out/err_*.txt --color=always - - - + +mkdir -p out + +echo " + LogIntModFilter + SleepCheck + MultipleActionsCheck + KillCheck + InMemoryLog + InMemoryLogCheck + NoExec + Log + LogTs + FalseIntFilter + LogIntAfterFilter + LogInt + FalseStringFilter + FalseStringFilterPartialMatch + LogStringAfterFilter + LogString + LogCheck +" | awk NF | ( while read l; do ./tests --unsafe-lwtrace 1 $l > out/out_$l.txt 2>out/err_$l.txt && echo done $l & done ; wait ) + + +grep . out/out_*.txt +grep . out/err_*.txt --color=always + + + diff --git a/library/cpp/lwtrace/trace.cpp b/library/cpp/lwtrace/trace.cpp index 3c974c85a0..76c77312fd 100644 --- a/library/cpp/lwtrace/trace.cpp +++ b/library/cpp/lwtrace/trace.cpp @@ -196,28 +196,28 @@ namespace NLWTrace { const TString Get(const TParams&) { return Dummy; } - + void Set(const TString&) { } }; - + template <> class TOperand<TSymbol, OT_VARIABLE> { private: TSymbol Dummy; - + public: TOperand(TSession::TTraceVariables&, const TString&, const TString&, size_t) { } - + const TSymbol Get(const TParams&) { return Dummy; } - + void Set(const TSymbol&) { } }; - + // IOperandGetter: hide concrete EOperandType, to save compilation time template <class T> struct IOperandGetter { @@ -330,7 +330,7 @@ namespace NLWTrace { Func(Receiver, Param.Get(params)); return true; } - + public: TBinaryInplaceStatementExecutor(TReceiver<TP>& receiver, const TOperand<TP, TParam>& param) : Receiver(receiver) @@ -516,7 +516,7 @@ namespace NLWTrace { return y; } }; - + void TSession::InsertExecutor( TTraceVariables& traceVariables, size_t bi, const TPredicate* pred, const NProtoBuf::RepeatedPtrField<TAction>& actions, TProbe* probe, @@ -547,16 +547,16 @@ namespace NLWTrace { TArgumentDescription arg0 = arguments.at(0); TArgumentDescription arg1 = arguments.at(1); - + const char* tName0 = arg0.ParamIdx == size_t(-1) ? nullptr : probe->Event.Signature.ParamTypes[arg0.ParamIdx]; const char* tName1 = arg1.ParamIdx == size_t(-1) ? nullptr : probe->Event.Signature.ParamTypes[arg1.ParamIdx]; - + TString var0 = op.GetArgument(0).GetVariable(); TString var1 = op.GetArgument(1).GetVariable(); - + TString val0 = op.GetArgument(0).GetValue(); TString val1 = op.GetArgument(1).GetValue(); - + #define FOREACH_OPERAND_TYPE_RT(n, t, v, fn, lt, rt) \ if (rt == arg1.Type) { \ TOperand<t, rt> rhs(traceVariables, var1, val1, arg1.ParamIdx); \ @@ -574,9 +574,9 @@ namespace NLWTrace { if ((arg0.ParamIdx == size_t(-1) || strcmp(tName0, n) == 0) && (arg1.ParamIdx == size_t(-1) || strcmp(tName1, n) == 0)) { \ FOREACH_LEFT_TYPE(FOREACH_OPERAND_TYPE_LT, n, t, v, fn); \ } - + bool invertCompare = EqualToOneOf(op.GetType(), OT_NE, OT_GE, OT_LE); - + switch (op.GetType()) { case OT_EQ: case OT_NE: @@ -595,8 +595,8 @@ namespace NLWTrace { << " has not supported operator type #" << int(op.GetType()); } -#undef FOREACH_OPERAND_TYPE_RT -#undef FOREACH_OPERAND_TYPE_LT +#undef FOREACH_OPERAND_TYPE_RT +#undef FOREACH_OPERAND_TYPE_LT #undef FOREACH_PARAMTYPE_MACRO if (!opExec) { @@ -731,13 +731,13 @@ namespace NLWTrace { actExec.Reset(new TExec(receiver, firstParam)); \ break; \ } - + #define PARSE_BINARY_INPLACE_STATEMENT_MACRO(n, t, v, fn) \ if (arg1.ParamIdx == size_t(-1) || strcmp(tName1, n) == 0) { \ TReceiver<t> receiver(traceVariables, var0); \ FOREACH_RIGHT_TYPE(PARSE_BINARY_INPLACE_STATEMENT_MACRO2, n, t, v, fn); \ } - + #define PARSE_BINARY_STATEMENT_MACRO2(n, t, v, fn, ft) \ if (arg1.Type == ft) { \ typedef TBinaryStatementExecutor<t, fn<t, t>, ft> TExec; \ @@ -745,20 +745,20 @@ namespace NLWTrace { actExec.Reset(new TExec(receiver, firstParam)); \ break; \ } - + #define PARSE_BINARY_STATEMENT_MACRO(n, t, v, fn) \ if (arg1.ParamIdx == size_t(-1) || strcmp(tName1, n) == 0) { \ TReceiver<t> receiver(traceVariables, var0); \ FOREACH_RIGHT_TYPE(PARSE_BINARY_STATEMENT_MACRO2, n, t, v, fn); \ } - + #define CREATE_OPERAND_GETTER_N(N, type, arg_type) \ if (arg##N.Type == arg_type) { \ - operand##N.Reset(new TOperandGetter<type, arg_type>(TOperand<type, arg_type>(traceVariables, var##N, val##N, arg##N.ParamIdx))); \ - } - + operand##N.Reset(new TOperandGetter<type, arg_type>(TOperand<type, arg_type>(traceVariables, var##N, val##N, arg##N.ParamIdx))); \ + } + #define TERNARY_ON_TYPE(n, t, v, fn) \ - if ((arg1.ParamIdx == size_t(-1) || strcmp(tName1, n) == 0) && (arg2.ParamIdx == size_t(-1) || strcmp(tName2, n) == 0)) { \ + if ((arg1.ParamIdx == size_t(-1) || strcmp(tName1, n) == 0) && (arg2.ParamIdx == size_t(-1) || strcmp(tName2, n) == 0)) { \ TAutoPtr<IOperandGetter<t>> operand1, operand2; \ FOREACH_LEFT_TYPE(CREATE_OPERAND_GETTER_N, 1, t); \ FOREACH_RIGHT_TYPE(CREATE_OPERAND_GETTER_N, 2, t); \ @@ -769,10 +769,10 @@ namespace NLWTrace { operand2)); \ } \ break; \ - } - -#define IMPLEMENT_TERNARY_STATEMENT(fn) FOR_MATH_PARAMTYPE(TERNARY_ON_TYPE, fn) - + } + +#define IMPLEMENT_TERNARY_STATEMENT(fn) FOR_MATH_PARAMTYPE(TERNARY_ON_TYPE, fn) + case ST_INC: FOR_MATH_PARAMTYPE(PARSE_UNARY_INPLACE_STATEMENT_MACRO, TInc); break; @@ -807,13 +807,13 @@ namespace NLWTrace { ythrow yexception() << "block #" << bi + 1 << " action #" << i + 1 << " has not supported statement type #" << int(statement.GetType()); } - } + } if (!actExec) { - ythrow yexception() << "block #" << bi + 1 << " action #" << i + 1 - << " can't create action"; + ythrow yexception() << "block #" << bi + 1 << " action #" << i + 1 + << " can't create action"; } -#undef CREATE_OPERAND_GETTER_N -#undef TERNARY_ON_TYPE +#undef CREATE_OPERAND_GETTER_N +#undef TERNARY_ON_TYPE #undef IMPLEMENT_TERNARY_STATEMENT #undef PARSE_TERNARY_STATEMENT_MACRO #undef PARSE_BINARY_STATEMENT_MACRO diff --git a/library/cpp/messagebus/actor/ring_buffer.h b/library/cpp/messagebus/actor/ring_buffer.h index ec5706f7c7..8b63149f4f 100644 --- a/library/cpp/messagebus/actor/ring_buffer.h +++ b/library/cpp/messagebus/actor/ring_buffer.h @@ -34,7 +34,7 @@ private: return; ui32 newCapacityPow = CapacityPow; - while ((1u << newCapacityPow) < sz + ui32(Size()) + 1u) { + while ((1u << newCapacityPow) < sz + ui32(Size()) + 1u) { ++newCapacityPow; } ui32 newCapacity = 1u << newCapacityPow; diff --git a/library/cpp/messagebus/remote_client_session.h b/library/cpp/messagebus/remote_client_session.h index 7160d0dae9..bde90a90b0 100644 --- a/library/cpp/messagebus/remote_client_session.h +++ b/library/cpp/messagebus/remote_client_session.h @@ -6,10 +6,10 @@ #include <util/generic/array_ref.h> #include <util/generic/object_counter.h> -#ifdef _MSC_VER -#pragma warning(push) +#ifdef _MSC_VER +#pragma warning(push) #pragma warning(disable : 4250) // 'NBus::NPrivate::TRemoteClientSession' : inherits 'NBus::NPrivate::TBusSessionImpl::NBus::NPrivate::TBusSessionImpl::GetConfig' via dominance -#endif +#endif namespace NBus { namespace NPrivate { @@ -51,9 +51,9 @@ namespace NBus { TBusClientConnectionPtr GetConnection(const TNetAddr&) override; }; -#ifdef _MSC_VER -#pragma warning(pop) -#endif - +#ifdef _MSC_VER +#pragma warning(pop) +#endif + } } diff --git a/library/cpp/messagebus/remote_server_session.h b/library/cpp/messagebus/remote_server_session.h index f5c266a7f7..3970a31aa6 100644 --- a/library/cpp/messagebus/remote_server_session.h +++ b/library/cpp/messagebus/remote_server_session.h @@ -3,10 +3,10 @@ #include "remote_server_session_semaphore.h" #include "session_impl.h" -#ifdef _MSC_VER -#pragma warning(push) +#ifdef _MSC_VER +#pragma warning(push) #pragma warning(disable : 4250) // 'NBus::NPrivate::TRemoteClientSession' : inherits 'NBus::NPrivate::TBusSessionImpl::NBus::NPrivate::TBusSessionImpl::GetConfig' via dominance -#endif +#endif namespace NBus { namespace NPrivate { @@ -46,9 +46,9 @@ namespace NBus { void ConvertInWork(TBusIdentity& req, TBusMessage* reply); }; -#ifdef _MSC_VER -#pragma warning(pop) -#endif - +#ifdef _MSC_VER +#pragma warning(pop) +#endif + } } diff --git a/library/cpp/messagebus/synchandler.cpp b/library/cpp/messagebus/synchandler.cpp index 8e891d66b3..821b778d30 100644 --- a/library/cpp/messagebus/synchandler.cpp +++ b/library/cpp/messagebus/synchandler.cpp @@ -91,11 +91,11 @@ private: namespace NBus { namespace NPrivate { -#ifdef _MSC_VER -#pragma warning(push) +#ifdef _MSC_VER +#pragma warning(push) #pragma warning(disable : 4250) // 'NBus::NPrivate::TRemoteClientSession' : inherits 'NBus::NPrivate::TBusSessionImpl::NBus::NPrivate::TBusSessionImpl::GetConfig' via dominance -#endif - +#endif + /////////////////////////////////////////////////////////////////////////// class TBusSyncSourceSessionImpl : private TSyncHandler @@ -147,12 +147,12 @@ namespace NBus { } }; -#ifdef _MSC_VER -#pragma warning(pop) -#endif +#ifdef _MSC_VER +#pragma warning(pop) +#endif } } - + TBusSyncSourceSession::TBusSyncSourceSession(TIntrusivePtr< ::NBus::NPrivate::TBusSyncSourceSessionImpl> session) : Session(session) { diff --git a/library/cpp/regex/pcre/regexp.h b/library/cpp/regex/pcre/regexp.h index bc610bd2f3..d91084eddd 100644 --- a/library/cpp/regex/pcre/regexp.h +++ b/library/cpp/regex/pcre/regexp.h @@ -9,7 +9,7 @@ #include <contrib/libs/pcre/pcre.h> #include <contrib/libs/pcre/pcreposix.h> -//THIS CODE LOOKS LIKE A TRASH, BUT WORKS. +//THIS CODE LOOKS LIKE A TRASH, BUT WORKS. #define NMATCHES 100 #define REGEXP_GLOBAL 0x0080 // use this if you want to find all occurences diff --git a/library/cpp/resource/registry.h b/library/cpp/resource/registry.h index fe67702cbc..336402ebe6 100644 --- a/library/cpp/resource/registry.h +++ b/library/cpp/resource/registry.h @@ -21,8 +21,8 @@ namespace NResource { 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() { - } + virtual ~IStore() { + } }; IStore* CommonStore(); diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp index e523350b80..a445636fd6 100644 --- a/library/cpp/string_utils/quote/quote.cpp +++ b/library/cpp/string_utils/quote/quote.cpp @@ -77,9 +77,9 @@ static inline const char* FixZero(const char* s) noexcept { // '%', '&', '+', ',', // '#', '<', '=', '>', // '[', '\\',']', '?', -// ':', '{', '}', +// ':', '{', '}', // all below ' ' (0x20) and above '~' (0x7E). -// ' ' converted to '+' +// ' ' converted to '+' static const bool chars_to_url_escape[256] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, //0 @@ -111,7 +111,7 @@ static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = cha *to++ = d2x((unsigned char)*from >> 4); *to++ = d2x((unsigned char)*from & 0xF); } else { - *to++ = (*from == ' ' ? '+' : *from); + *to++ = (*from == ' ' ? '+' : *from); } ++from; @@ -123,7 +123,7 @@ static inline It1 Escape(It1 to, It2 from, It3 end, const bool* escape_map = cha } template <class It1, class It2, class It3, class FromHex> -static inline It1 Unescape(It1 to, It2 from, It3 end, FromHex fromHex) { +static inline It1 Unescape(It1 to, It2 from, It3 end, FromHex fromHex) { (void)fromHex; while (from != end) { @@ -167,8 +167,8 @@ TString CGIEscapeRet(const TStringBuf url) { to.ReserveAndResize(CgiEscapeBufLen(url.size())); to.resize(CGIEscape(to.begin(), url.data(), url.size()) - to.data()); return to; -} - +} + TString& AppendCgiEscaped(const TStringBuf value, TString& to) { const size_t origLength = to.length(); to.ReserveAndResize(origLength + CgiEscapeBufLen(value.size())); @@ -215,11 +215,11 @@ void Quote(TString& url, const char* safe) { } char* CGIUnescape(char* to, const char* from) { - return Unescape(to, FixZero(from), TCStringEndIterator(), TFromHexZeroTerm()); + return Unescape(to, FixZero(from), TCStringEndIterator(), TFromHexZeroTerm()); } -char* CGIUnescape(char* to, const char* from, size_t len) { - return Unescape(to, from, from + len, TFromHexLenLimited(from + len)); +char* CGIUnescape(char* to, const char* from, size_t len) { + return Unescape(to, from, from + len, TFromHexLenLimited(from + len)); } void CGIUnescape(TString& url) { @@ -240,8 +240,8 @@ TString CGIUnescapeRet(const TStringBuf from) { to.ReserveAndResize(CgiUnescapeBufLen(from.size())); to.resize(CGIUnescape(to.begin(), from.data(), from.size()) - to.data()); return to; -} - +} + char* UrlUnescape(char* to, TStringBuf from) { while (!from.empty()) { char ch = from[0]; diff --git a/library/cpp/string_utils/quote/quote.h b/library/cpp/string_utils/quote/quote.h index 3b7221154e..55150d31f6 100644 --- a/library/cpp/string_utils/quote/quote.h +++ b/library/cpp/string_utils/quote/quote.h @@ -3,11 +3,11 @@ #include <util/generic/strbuf.h> #include <util/generic/string.h> -//CGIEscape*: -// ' ' converted to '+', -// Some punctuation and chars outside [32, 126] range are converted to %xx -// Use function CgiEscapeBufLen to determine number of characters needed for 'char* to' parameter. -// Returns pointer to the end of the result string +//CGIEscape*: +// ' ' converted to '+', +// Some punctuation and chars outside [32, 126] range are converted to %xx +// Use function CgiEscapeBufLen to determine number of characters needed for 'char* to' parameter. +// Returns pointer to the end of the result string char* CGIEscape(char* to, const char* from); char* CGIEscape(char* to, const char* from, size_t len); inline char* CGIEscape(char* to, const TStringBuf from) { @@ -24,12 +24,12 @@ inline TStringBuf CgiEscape(void* tmp, const TStringBuf s) { return CgiEscapeBuf(static_cast<char*>(tmp), s); } -//CgiUnescape*: -// Decodes '%xx' to bytes, '+' to space. -// Use function CgiUnescapeBufLen to determine number of characters needed for 'char* to' parameter. -// If pointer returned, then this is pointer to the end of the result string. -char* CGIUnescape(char* to, const char* from); -char* CGIUnescape(char* to, const char* from, size_t len); +//CgiUnescape*: +// Decodes '%xx' to bytes, '+' to space. +// Use function CgiUnescapeBufLen to determine number of characters needed for 'char* to' parameter. +// If pointer returned, then this is pointer to the end of the result string. +char* CGIUnescape(char* to, const char* from); +char* CGIUnescape(char* to, const char* from, size_t len); void CGIUnescape(TString& url); TString CGIUnescapeRet(const TStringBuf from); @@ -40,29 +40,29 @@ inline TStringBuf CgiUnescape(void* tmp, const TStringBuf s) { return CgiUnescapeBuf(static_cast<char*>(tmp), s); } -//Quote: -// Is like CGIEscape, also skips encoding of user-supplied 'safe' characters. +//Quote: +// Is like CGIEscape, also skips encoding of user-supplied 'safe' characters. char* Quote(char* to, const char* from, const char* safe = "/"); char* Quote(char* to, const TStringBuf s, const char* safe = "/"); void Quote(TString& url, const char* safe = "/"); -//UrlEscape: -// Can't be used for cgi parameters ('&' character is not escaped)! +//UrlEscape: +// Can't be used for cgi parameters ('&' character is not escaped)! // escapes only '%' not followed by two hex-digits or if forceEscape set to ture, // and chars outside [32, 126] range. // Can't handle '\0'-chars in TString. char* UrlEscape(char* to, const char* from, bool forceEscape = false); void UrlEscape(TString& url, bool forceEscape = false); TString UrlEscapeRet(const TStringBuf from, bool forceEscape = false); - -//UrlUnescape: -// '+' is NOT converted to space! -// %xx converted to bytes, other characters are copied unchanged. + +//UrlUnescape: +// '+' is NOT converted to space! +// %xx converted to bytes, other characters are copied unchanged. char* UrlUnescape(char* to, TStringBuf from); void UrlUnescape(TString& url); TString UrlUnescapeRet(const TStringBuf from); -//*BufLen: how much characters you should allocate for 'char* to' buffers. +//*BufLen: how much characters you should allocate for 'char* to' buffers. constexpr size_t CgiEscapeBufLen(const size_t len) noexcept { return 3 * len + 1; } diff --git a/library/cpp/string_utils/quote/quote_ut.cpp b/library/cpp/string_utils/quote/quote_ut.cpp index 6c552b279e..056589b3eb 100644 --- a/library/cpp/string_utils/quote/quote_ut.cpp +++ b/library/cpp/string_utils/quote/quote_ut.cpp @@ -24,10 +24,10 @@ Y_UNIT_TEST_SUITE(TCGIEscapeTest) { UNIT_ASSERT_VALUES_EQUAL(CgiEscape(tmp, "!@#$%^&*(){}[]\" "), TStringBuf("!@%23$%25^%26*%28%29%7B%7D%5B%5D%22+")); } - + Y_UNIT_TEST(StrokaRet) { UNIT_ASSERT_VALUES_EQUAL(CGIEscapeRet("!@#$%^&*(){}[]\" "), TString("!@%23$%25^%26*%28%29%7B%7D%5B%5D%22+")); - } + } Y_UNIT_TEST(StrokaAppendRet) { TString param; @@ -82,7 +82,7 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { CGIUnescape(r, "12%3g34"); UNIT_ASSERT_VALUES_EQUAL(r, "12%3g34"); - CGIUnescape(r, "%3u123"); + CGIUnescape(r, "%3u123"); UNIT_ASSERT_VALUES_EQUAL(r, "%3u123"); } @@ -114,13 +114,13 @@ Y_UNIT_TEST_SUITE(TCGIUnescapeTest) { CGIUnescape(r, "12%3g345678", 7); UNIT_ASSERT_VALUES_EQUAL(r, "12%3g34"); - CGIUnescape(r, "%3u1234", 2); + CGIUnescape(r, "%3u1234", 2); UNIT_ASSERT_VALUES_EQUAL(r, "%3"); - CGIUnescape(r, "%3u1234", 3); + CGIUnescape(r, "%3u1234", 3); UNIT_ASSERT_VALUES_EQUAL(r, "%3u"); - CGIUnescape(r, "%3u1234", 4); + CGIUnescape(r, "%3u1234", 4); UNIT_ASSERT_VALUES_EQUAL(r, "%3u1"); } diff --git a/library/cpp/string_utils/url/url.cpp b/library/cpp/string_utils/url/url.cpp index 85f4ac5d69..82887bd3a0 100644 --- a/library/cpp/string_utils/url/url.cpp +++ b/library/cpp/string_utils/url/url.cpp @@ -241,11 +241,11 @@ TStringBuf GetOnlyHost(const TStringBuf url) noexcept { TStringBuf GetPathAndQuery(const TStringBuf url, bool trimFragment) noexcept { const size_t off = url.find('/', GetHttpPrefixSize(url)); - TStringBuf hostUnused, path; - if (!url.TrySplitAt(off, hostUnused, path)) + TStringBuf hostUnused, path; + if (!url.TrySplitAt(off, hostUnused, path)) return "/"; - - return trimFragment ? path.Before('#') : path; + + return trimFragment ? path.Before('#') : path; } // this strange creature returns 2nd level domain, possibly with port @@ -311,15 +311,15 @@ TStringBuf CutMPrefix(const TStringBuf url) noexcept { } static inline bool IsSchemeChar(char c) noexcept { - return IsAsciiAlnum(c); //what about '+' ?.. + return IsAsciiAlnum(c); //what about '+' ?.. } static bool HasPrefix(const TStringBuf url) noexcept { - TStringBuf scheme, unused; + TStringBuf scheme, unused; if (!url.TrySplit(TStringBuf("://"), scheme, unused)) return false; - return AllOf(scheme, IsSchemeChar); + return AllOf(scheme, IsSchemeChar); } TString AddSchemePrefix(const TString& url) { diff --git a/library/cpp/xml/document/node-attr.h b/library/cpp/xml/document/node-attr.h index 6e74403943..1d187573bb 100644 --- a/library/cpp/xml/document/node-attr.h +++ b/library/cpp/xml/document/node-attr.h @@ -1,12 +1,12 @@ #pragma once -#include "xml-document-decl.h" +#include "xml-document-decl.h" #include "libxml-guards.h" #include <util/stream/str.h> #include <util/string/cast.h> namespace NXml { -#define THROW(x, y) ythrow yexception() << #x << ": " << y +#define THROW(x, y) ythrow yexception() << #x << ": " << y // libxml defines unsigned char -> xmlChar, // and all functions use xmlChar. @@ -40,7 +40,7 @@ namespace NXml { } T t; - AttrInternal(value, t, name); + AttrInternal(value, t, name); return t; } @@ -52,7 +52,7 @@ namespace NXml { } T t; - AttrInternal(attr, t, name); + AttrInternal(attr, t, name); return t; } @@ -63,7 +63,7 @@ namespace NXml { THROW(AttributeNotFound, Path() << name); } - AttrInternal(attr, value, name); + AttrInternal(attr, value, name); } template <class T> @@ -73,7 +73,7 @@ namespace NXml { if (!attr) { value = defvalue; } else { - AttrInternal(attr, value, name); + AttrInternal(attr, value, name); } } @@ -85,7 +85,7 @@ namespace NXml { TCharPtr val(xmlNodeGetContent(NodePointer)); T t; - AttrInternal(val, t, this->Name()); + AttrInternal(val, t, this->Name()); return t; } @@ -97,7 +97,7 @@ namespace NXml { TCharPtr val(xmlNodeGetContent(NodePointer)); T t; - AttrInternal(val, t, this->Name()); + AttrInternal(val, t, this->Name()); return t; } diff --git a/library/cpp/xml/document/xml-document-decl.h b/library/cpp/xml/document/xml-document-decl.h index bfda1fb7e6..db57ab1180 100644 --- a/library/cpp/xml/document/xml-document-decl.h +++ b/library/cpp/xml/document/xml-document-decl.h @@ -4,8 +4,8 @@ #include <util/generic/string.h> #include <util/generic/vector.h> -#include <util/stream/output.h> -#include <util/stream/str.h> +#include <util/stream/output.h> +#include <util/stream/str.h> #include <algorithm> #include "libxml-guards.h" @@ -48,20 +48,20 @@ namespace NXml { TConstNode Root() const; void Save(IOutputStream& stream, TZtStringBuf enc = "", bool shouldFormat = true) const { - int bufferSize = 0; - xmlChar* xmlBuff = nullptr; + int bufferSize = 0; + xmlChar* xmlBuff = nullptr; const char* encoding = enc.size() ? enc.data() : Doc->encoding ? nullptr : "UTF-8"; xmlDocDumpFormatMemoryEnc(Doc.Get(), &xmlBuff, &bufferSize, encoding, shouldFormat); - TCharPtr xmlCharBuffPtr(xmlBuff); - stream.Write(xmlBuff, bufferSize); - } + TCharPtr xmlCharBuffPtr(xmlBuff); + stream.Write(xmlBuff, bufferSize); + } TString ToString(TZtStringBuf enc = "", bool shouldFormat = true) const { - TStringStream s; + TStringStream s; Save(s, enc, shouldFormat); return s.Str(); - } - + } + void Swap(TDocument& that) { std::swap(this->Doc, that.Doc); } diff --git a/util/charset/generated/unidata.cpp b/util/charset/generated/unidata.cpp index 6f5adbbc0a..f8344a9724 100644 --- a/util/charset/generated/unidata.cpp +++ b/util/charset/generated/unidata.cpp @@ -5340,7 +5340,7 @@ namespace { namespace NUnidataTableGenerated { }, // P[614] }; // static const NUnicode::NPrivate::TUnidataTable::TValuePtr P[][32] - static const NUnicode::NPrivate::TUnidataTable::TValuePtr* const Indexes[] = { + static const NUnicode::NPrivate::TUnidataTable::TValuePtr* const Indexes[] = { P[0], P[1], P[2], P[3], P[4], P[5], P[6], P[7], P[8], P[9], P[10], P[11], P[12], P[13], P[14], P[15], P[16], P[17], P[18], P[19], P[20], P[21], P[22], P[23], P[24], P[25], P[26], P[27], P[28], P[29], P[30], P[31], P[32], P[33], P[34], P[35], P[36], P[37], P[38], P[39], P[37], P[40], P[41], P[42], P[43], P[44], P[45], P[46], @@ -7517,7 +7517,7 @@ namespace { namespace NUnidataTableGenerated { P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[360], P[614], - }; // static const NUnicode::NPrivate::TUnidataTable::TValuePtr* const Indexes[] + }; // static const NUnicode::NPrivate::TUnidataTable::TValuePtr* const Indexes[] static const size_t Size = 1114110; }} // namespace NUnidataTableGenerated diff --git a/util/charset/ut/ya.make b/util/charset/ut/ya.make index 6526815e92..de47f72202 100644 --- a/util/charset/ut/ya.make +++ b/util/charset/ut/ya.make @@ -7,7 +7,7 @@ DATA(arcadia/util/charset/ut/utf8) SRCS( utf8_ut.cpp - wide_ut.cpp + wide_ut.cpp ) INCLUDE(${ARCADIA_ROOT}/util/tests/ya_util_tests.inc) diff --git a/util/charset/utf8_ut.cpp b/util/charset/utf8_ut.cpp index 9e68881cca..115dac8271 100644 --- a/util/charset/utf8_ut.cpp +++ b/util/charset/utf8_ut.cpp @@ -1,22 +1,22 @@ #include "utf8.h" -#include "wide.h" - +#include "wide.h" + #include <util/stream/file.h> #include <util/ysaveload.h> #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/env.h> - + Y_UNIT_TEST_SUITE(TUtfUtilTest) { Y_UNIT_TEST(TestUTF8Len) { UNIT_ASSERT_EQUAL(GetNumberOfUTF8Chars("привет!"), 7); - } - + } + Y_UNIT_TEST(TestToLowerUtfString) { - UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8("xyz XYZ ПРИВЕТ!"), "xyz xyz привет!"); - + UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8("xyz XYZ ПРИВЕТ!"), "xyz xyz привет!"); + UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8(TStringBuf("xyz")), "xyz"); - + { TString s = "привет!"; TString q = "ПРИВЕТ!"; @@ -24,7 +24,7 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) { UNIT_ASSERT(ToLowerUTF8Impl(s.data(), s.size(), tmp) == false); UNIT_ASSERT(ToLowerUTF8Impl(q.data(), q.size(), tmp) == true); } - + { const char* weird = "\xC8\xBE"; // 'Ⱦ', U+023E. strlen(weird)==2, strlen(tolower_utf8(weird)) is 3 const char* turkI = "İ"; //strlen("İ") == 2, strlen(tolower_utf8("İ") == 1 @@ -41,16 +41,16 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) { s += chars[k % N]; k /= N; } - + TUtf16String tmp = UTF8ToWide(s); tmp.to_lower(); - + UNIT_ASSERT_VALUES_EQUAL(ToLowerUTF8(s), WideToUTF8(tmp)); } numberOfVariants *= N; - } - } - } + } + } + } Y_UNIT_TEST(TestToUpperUtfString) { UNIT_ASSERT_VALUES_EQUAL(ToUpperUTF8("xyz XYZ привет!"), "XYZ XYZ ПРИВЕТ!"); @@ -123,4 +123,4 @@ Y_UNIT_TEST_SUITE(TUtfUtilTest) { wtextScalar.remove(wtextSSE.size()); UNIT_ASSERT(wtextScalar == wtextSSE); } -} +} diff --git a/util/charset/wide.h b/util/charset/wide.h index 04e6928aab..d9402f5f05 100644 --- a/util/charset/wide.h +++ b/util/charset/wide.h @@ -811,21 +811,21 @@ TUtf32String ToTitleRet(const TUtf32StringBuf text, size_t pos = 0, size_t count // insertBr=true - replace '\r' and '\n' with "<BR>" template <bool insertBr> void EscapeHtmlChars(TUtf16String& str); - -//! returns number of characters in range. Handle surrogate pairs as one character. -inline size_t CountWideChars(const wchar16* b, const wchar16* e) { - size_t count = 0; + +//! returns number of characters in range. Handle surrogate pairs as one character. +inline size_t CountWideChars(const wchar16* b, const wchar16* e) { + size_t count = 0; Y_ENSURE(b <= e, TStringBuf("invalid iterators")); - while (b < e) { - b = SkipSymbol(b, e); + while (b < e) { + b = SkipSymbol(b, e); ++count; - } - return count; -} - + } + return count; +} + inline size_t CountWideChars(const TWtringBuf str) { - return CountWideChars(str.begin(), str.end()); -} + return CountWideChars(str.begin(), str.end()); +} //! checks whether the range is valid UTF-16 sequence inline bool IsValidUTF16(const wchar16* b, const wchar16* e) { diff --git a/util/charset/wide_ut.cpp b/util/charset/wide_ut.cpp index d8f3233e73..6612d59aa0 100644 --- a/util/charset/wide_ut.cpp +++ b/util/charset/wide_ut.cpp @@ -545,8 +545,8 @@ void TConversionTest::TestGetNumOfUTF8Chars() { result = GetNumberOfUTF8Chars(utext, 1, n); UNIT_ASSERT(!result); UNIT_ASSERT(n == 0); - - UNIT_ASSERT_EQUAL(GetNumberOfUTF8Chars("привет!"), 7); + + UNIT_ASSERT_EQUAL(GetNumberOfUTF8Chars("привет!"), 7); } void TConversionTest::TestSubstrUTF8() { diff --git a/util/datetime/systime.cpp b/util/datetime/systime.cpp index 6ee7e8fc6e..9944642dad 100644 --- a/util/datetime/systime.cpp +++ b/util/datetime/systime.cpp @@ -61,7 +61,7 @@ char* ctime_r(const time_t* clock, char* buf) { //! @note this code adopted from //! http://osdir.com/ml/web.wget.patches/2005-07/msg00010.html //! Subject: A more robust timegm - msg#00010 -time_t TimeGM(const struct tm* t) { +time_t TimeGM(const struct tm* t) { static const unsigned short int month_to_days[][13] = { {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}, {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}}; diff --git a/util/datetime/systime.h b/util/datetime/systime.h index 491d36e802..a498ed7ab2 100644 --- a/util/datetime/systime.h +++ b/util/datetime/systime.h @@ -6,7 +6,7 @@ #include <ctime> // timegm and gmtime_r versions that don't need access to filesystem or a big stack -time_t TimeGM(const struct tm* t); +time_t TimeGM(const struct tm* t); struct tm* GmTimeR(const time_t* timer, struct tm* tmbuf); // safe version of ctime, convinient version of ctime_r TString CTimeR(const time_t* timer); diff --git a/util/digest/city.cpp b/util/digest/city.cpp index c25f175d54..566b66aa48 100644 --- a/util/digest/city.cpp +++ b/util/digest/city.cpp @@ -311,13 +311,13 @@ uint128 CityHash128(const char* s, size_t len) noexcept { } // TODO(yazevnul): move this function to unittests -void TestCompilationOfCityHashTemplates() { +void TestCompilationOfCityHashTemplates() { TStringBuf s; CityHash64(s); CityHash64WithSeed(s, 1); CityHash64WithSeeds(s, 1, 2); CityHash128(s); CityHash128WithSeed(s, uint128(1, 2)); -} - +} + #endif diff --git a/util/digest/city.h b/util/digest/city.h index 675a798074..77ecba67a2 100644 --- a/util/digest/city.h +++ b/util/digest/city.h @@ -1,7 +1,7 @@ #pragma once #include <util/generic/utility.h> -#include <util/generic/strbuf.h> +#include <util/generic/strbuf.h> #include <utility> @@ -18,9 +18,9 @@ constexpr ui64 Uint128High64(const uint128& x) { return x.second; } -// Hash functions for a byte array. -// http://en.wikipedia.org/wiki/CityHash - +// Hash functions for a byte array. +// http://en.wikipedia.org/wiki/CityHash + Y_PURE_FUNCTION ui64 CityHash64(const char* buf, size_t len) noexcept; Y_PURE_FUNCTION ui64 CityHash64WithSeed(const char* buf, size_t len, ui64 seed) noexcept; @@ -43,41 +43,41 @@ inline ui64 Hash128to64(const uint128& x) { b *= kMul; return b; } - + namespace NPrivateCityHash { template <class TStringType> inline TStringBuf GetBufFromStr(const TStringType& str) { static_assert(std::is_integral<std::remove_reference_t<decltype(*str.data())>>::value, "invalid type passed to hash function"); return TStringBuf(reinterpret_cast<const char*>(str.data()), (str.size()) * sizeof(*str.data())); } -} - +} + template <class TStringType> inline ui64 CityHash64(const TStringType& str) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash64(buf.data(), buf.size()); -} - +} + template <class TStringType> inline ui64 CityHash64WithSeeds(const TStringType& str, ui64 seed0, ui64 seed1) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash64WithSeeds(buf.data(), buf.size(), seed0, seed1); -} - +} + template <class TStringType> inline ui64 CityHash64WithSeed(const TStringType& str, ui64 seed) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash64WithSeed(buf.data(), buf.size(), seed); -} - +} + template <class TStringType> inline uint128 CityHash128(const TStringType& str) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash128(buf.data(), buf.size()); -} - +} + template <class TStringType> inline uint128 CityHash128WithSeed(const TStringType& str, uint128 seed) { TStringBuf buf = NPrivateCityHash::GetBufFromStr(str); return CityHash128WithSeed(buf.data(), buf.size(), seed); -} +} diff --git a/util/digest/murmur.cpp b/util/digest/murmur.cpp index b041d3e5f2..22ef50014e 100644 --- a/util/digest/murmur.cpp +++ b/util/digest/murmur.cpp @@ -1,5 +1,5 @@ -#include "murmur.h" - +#include "murmur.h" + #include <util/system/unaligned_mem.h> namespace NMurmurPrivate { diff --git a/util/digest/murmur.h b/util/digest/murmur.h index 6b519b430a..87ad2c2d4c 100644 --- a/util/digest/murmur.h +++ b/util/digest/murmur.h @@ -36,7 +36,7 @@ static inline T MurmurHash(const void* buf, size_t len, T init) noexcept { template <class T> static inline T MurmurHash(const void* buf, size_t len) noexcept { - return MurmurHash<T>(buf, len, (T)0); + return MurmurHash<T>(buf, len, (T)0); } //non-inline version diff --git a/util/digest/murmur_ut.cpp b/util/digest/murmur_ut.cpp index 29287668bc..0316264e72 100644 --- a/util/digest/murmur_ut.cpp +++ b/util/digest/murmur_ut.cpp @@ -1,4 +1,4 @@ - + #include "murmur.h" #include <library/cpp/testing/unittest/registar.h> diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h index badfb88993..cbfb41ff04 100644 --- a/util/generic/algorithm.h +++ b/util/generic/algorithm.h @@ -3,9 +3,9 @@ #include "is_in.h" #include "utility.h" -#include <util/system/defaults.h> +#include <util/system/defaults.h> #include <util/generic/fwd.h> - + #include <numeric> #include <algorithm> #include <iterator> @@ -154,51 +154,51 @@ static inline auto FindIf(C&& c, P p) { } template <class I, class P> -static inline bool AllOf(I f, I l, P pred) { +static inline bool AllOf(I f, I l, P pred) { return std::all_of(f, l, pred); -} - +} + template <class C, class P> -static inline bool AllOf(const C& c, P pred) { +static inline bool AllOf(const C& c, P pred) { using std::begin; using std::end; return AllOf(begin(c), end(c), pred); -} - +} + template <class I, class P> -static inline bool AnyOf(I f, I l, P pred) { +static inline bool AnyOf(I f, I l, P pred) { return std::any_of(f, l, pred); -} - +} + template <class C, class P> -static inline bool AnyOf(const C& c, P pred) { +static inline bool AnyOf(const C& c, P 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 +} + +// FindIfPtr - return NULL if not found. Works for arrays, containers, iterators template <class I, class P> static inline auto FindIfPtr(I f, I l, P pred) -> decltype(&*f) { - I found = FindIf(f, l, pred); + I found = FindIf(f, l, pred); return (found != l) ? &*found : nullptr; -} - +} + 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); -} - -template <class C, class T> +} + +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)); -} - +} + template <class C, class P> static inline size_t FindIndexIf(C&& c, P p) { using std::begin; @@ -207,17 +207,17 @@ static inline size_t FindIndexIf(C&& c, P p) { return it == end(c) ? NPOS : (it - begin(c)); } -//EqualToOneOf(x, "apple", "orange") means (x == "apple" || x == "orange") +//EqualToOneOf(x, "apple", "orange") means (x == "apple" || x == "orange") template <typename T> inline bool EqualToOneOf(const T&) { - return false; -} + return false; +} template <typename T, typename U, typename... Other> inline bool EqualToOneOf(const T& x, const U& y, const Other&... other) { - return x == y || EqualToOneOf(x, other...); -} - + return x == y || EqualToOneOf(x, other...); +} + template <typename T> static inline size_t CountOf(const T&) { return 0; @@ -342,11 +342,11 @@ void Erase(C& c, const TValue& value) { c.erase(std::remove(c.begin(), c.end(), value), c.end()); } -template <class C, class P> -void EraseIf(C& c, P p) { +template <class C, class P> +void EraseIf(C& c, P p) { c.erase(std::remove_if(c.begin(), c.end(), p), c.end()); -} - +} + template <class C, class P> void EraseNodesIf(C& c, P p) { for (auto iter = c.begin(), last = c.end(); iter != last;) { @@ -643,18 +643,18 @@ static inline auto Count(const TContainer& container, const TValue& value) { return Count(std::cbegin(container), std::cend(container), value); } -template <class It, class P> +template <class It, class P> static inline auto CountIf(It first, It last, P p) { return std::count_if(first, last, 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); -} - +} + template <class I1, class I2> static inline std::pair<I1, I2> Mismatch(I1 b1, I1 e1, I2 b2) { return std::mismatch(b1, e1, b2); diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 8d732fcc0c..8db678f3cb 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -1,11 +1,11 @@ #include <library/cpp/testing/unittest/registar.h> - + #include "algorithm.h" #include "strbuf.h" #include "string.h" - -static auto isOne = [](char c) { return c == '1'; }; - + +static auto isOne = [](char c) { return c == '1'; }; + Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(AnyTest) { UNIT_ASSERT(0 == AnyOf(TStringBuf("00"), isOne)); @@ -18,8 +18,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(0 == AnyOf(array00, isOne)); const char array01[]{'0', '1'}; UNIT_ASSERT(1 == AnyOf(array01, isOne)); - } - + } + Y_UNIT_TEST(AllOfTest) { UNIT_ASSERT(0 == AllOf(TStringBuf("00"), isOne)); UNIT_ASSERT(0 == AllOf(TStringBuf("01"), isOne)); @@ -31,8 +31,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(0 == AllOf(array01, isOne)); const char array11[]{'1', '1'}; UNIT_ASSERT(1 == AllOf(array11, isOne)); - } - + } + Y_UNIT_TEST(CountIfTest) { UNIT_ASSERT(3 == CountIf(TStringBuf("____1________1____1_______"), isOne)); UNIT_ASSERT(5 == CountIf(TStringBuf("1____1________1____1_______1"), isOne)); @@ -42,8 +42,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { const char array[] = "____1________1____1_______"; UNIT_ASSERT(3 == CountIf(array, isOne)); - } - + } + Y_UNIT_TEST(CountTest) { UNIT_ASSERT(3 == Count("____1________1____1_______", '1')); UNIT_ASSERT(3 == Count(TStringBuf("____1________1____1_______"), '1')); @@ -66,15 +66,15 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { private: TStrokaNoCopy(const TStrokaNoCopy&); void operator=(const TStrokaNoCopy&); - }; - + }; + Y_UNIT_TEST(CountOfTest) { UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 2), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(1, 1), 1); UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 5), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(2, 4, 2), 1); UNIT_ASSERT_VALUES_EQUAL(CountOf(3, 3, 3), 2); - + // Checking comparison of different types. UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'x', 'y', 'z'), 0); UNIT_ASSERT_VALUES_EQUAL(CountOf(0x61, 'a', 'b', 'c', 0x61), 2); @@ -102,32 +102,32 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } Y_UNIT_TEST(EqualToOneOfTest) { - UNIT_ASSERT(1 == EqualToOneOf(1, 1, 2)); - UNIT_ASSERT(1 == EqualToOneOf(2, 1, 2)); - UNIT_ASSERT(0 == EqualToOneOf(3, 1, 2)); - UNIT_ASSERT(1 == EqualToOneOf(1, 1)); - UNIT_ASSERT(0 == EqualToOneOf(1, 2)); - UNIT_ASSERT(0 == EqualToOneOf(3)); - - //test, that EqualToOneOf can compare different types, and don't copy objects: - TStrokaNoCopy x("x"); - TStrokaNoCopy y("y"); - TStrokaNoCopy z("z"); + UNIT_ASSERT(1 == EqualToOneOf(1, 1, 2)); + UNIT_ASSERT(1 == EqualToOneOf(2, 1, 2)); + UNIT_ASSERT(0 == EqualToOneOf(3, 1, 2)); + UNIT_ASSERT(1 == EqualToOneOf(1, 1)); + UNIT_ASSERT(0 == EqualToOneOf(1, 2)); + UNIT_ASSERT(0 == EqualToOneOf(3)); + + //test, that EqualToOneOf can compare different types, and don't copy objects: + TStrokaNoCopy x("x"); + TStrokaNoCopy y("y"); + TStrokaNoCopy z("z"); const char* px = "x"; const char* py = "y"; const char* pz = "z"; - - UNIT_ASSERT(1 == EqualToOneOf(x, px, py)); - UNIT_ASSERT(1 == EqualToOneOf(y, px, py)); - UNIT_ASSERT(1 == EqualToOneOf(y, px, y)); - UNIT_ASSERT(1 == EqualToOneOf(y, x, py)); - UNIT_ASSERT(0 == EqualToOneOf(z, px, py)); - UNIT_ASSERT(1 == EqualToOneOf(px, x, y)); - UNIT_ASSERT(1 == EqualToOneOf(py, x, y)); - UNIT_ASSERT(0 == EqualToOneOf(pz, x, y)); - } - - template <class TTestConstPtr> + + UNIT_ASSERT(1 == EqualToOneOf(x, px, py)); + UNIT_ASSERT(1 == EqualToOneOf(y, px, py)); + UNIT_ASSERT(1 == EqualToOneOf(y, px, y)); + UNIT_ASSERT(1 == EqualToOneOf(y, x, py)); + UNIT_ASSERT(0 == EqualToOneOf(z, px, py)); + UNIT_ASSERT(1 == EqualToOneOf(px, x, y)); + UNIT_ASSERT(1 == EqualToOneOf(py, x, y)); + UNIT_ASSERT(0 == EqualToOneOf(pz, x, y)); + } + + template <class TTestConstPtr> void TestFindPtrFoundValue(int j, TTestConstPtr root) { if (j == 3) { UNIT_ASSERT(root && *root == 3); @@ -139,35 +139,35 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { } template <class TTestConstPtr> - void TestFindIfPtrFoundValue(int j, TTestConstPtr root) { - if (j == 3) { + void TestFindIfPtrFoundValue(int j, TTestConstPtr root) { + if (j == 3) { UNIT_ASSERT(root == nullptr); - } else if (j == 4) { - UNIT_ASSERT(root && *root == 2); - } else { - ythrow yexception() << "invalid param " << j; - } - } - + } else if (j == 4) { + UNIT_ASSERT(root && *root == 2); + } else { + ythrow yexception() << "invalid param " << j; + } + } + struct TVectorNoCopy: std::vector<int> { - public: + public: TVectorNoCopy() = default; - private: - TVectorNoCopy(const TVectorNoCopy&); - void operator=(const TVectorNoCopy&); - }; - + private: + TVectorNoCopy(const TVectorNoCopy&); + void operator=(const TVectorNoCopy&); + }; + Y_UNIT_TEST(FindPtrTest) { - TVectorNoCopy v; - v.push_back(1); - v.push_back(2); - v.push_back(3); - + TVectorNoCopy v; + v.push_back(1); + v.push_back(2); + v.push_back(3); + int array[3] = {1, 2, 3}; const int array_const[3] = {1, 2, 3}; - - //test (const, non-const) * (iterator, vector, array) * (found, not found) variants. + + //test (const, non-const) * (iterator, vector, array) * (found, not found) variants. // value '3' is in container, value '4' is not for (int j = 3; j <= 4; ++j) { TestFindPtrFoundValue<int*>(j, FindPtr(v, j)); @@ -190,40 +190,40 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { const int array_const[3] = {1, 2, 3}; //test (const, non-const) * (iterator, vector, array) * (found, not found) variants. - // search, that 2*2 == 4, but there is no value 'x' in array that (x*x == 3) - for (int j = 3; j <= 4; ++j) { + // search, that 2*2 == 4, but there is no value 'x' in array that (x*x == 3) + for (int j = 3; j <= 4; ++j) { TestFindIfPtrFoundValue<int*>(j, FindIfPtr(v, [j](int i) { return i * i == j; })); TestFindIfPtrFoundValue<int*>(j, FindIfPtr(v.begin(), v.end(), [j](int i) { return i * i == j; })); const TVectorNoCopy& q = v; TestFindIfPtrFoundValue<const int*>(j, FindIfPtr(q, [j](int i) { return i * i == j; })); - + TestFindIfPtrFoundValue<const int*>(j, FindIfPtr(q.begin(), q.end(), [j](int i) { return i * i == j; })); TestFindIfPtrFoundValue<int*>(j, FindIfPtr(array, [j](int i) { return i * i == j; })); TestFindIfPtrFoundValue<const int*>(j, FindIfPtr(array_const, [j](int i) { return i * i == j; })); - } - } - + } + } + Y_UNIT_TEST(FindIndexTest) { - TVectorNoCopy v; - v.push_back(1); - v.push_back(2); - v.push_back(3); - - UNIT_ASSERT_EQUAL(0, FindIndex(v, 1)); - UNIT_ASSERT_EQUAL(1, FindIndex(v, 2)); - UNIT_ASSERT_EQUAL(2, FindIndex(v, 3)); - UNIT_ASSERT_EQUAL(NPOS, FindIndex(v, 42)); - + TVectorNoCopy v; + v.push_back(1); + v.push_back(2); + v.push_back(3); + + UNIT_ASSERT_EQUAL(0, FindIndex(v, 1)); + UNIT_ASSERT_EQUAL(1, FindIndex(v, 2)); + UNIT_ASSERT_EQUAL(2, FindIndex(v, 3)); + UNIT_ASSERT_EQUAL(NPOS, FindIndex(v, 42)); + int array[3] = {1, 2, 3}; - - UNIT_ASSERT_EQUAL(0, FindIndex(array, 1)); - UNIT_ASSERT_EQUAL(1, FindIndex(array, 2)); - UNIT_ASSERT_EQUAL(2, FindIndex(array, 3)); - UNIT_ASSERT_EQUAL(NPOS, FindIndex(array, 42)); - + + UNIT_ASSERT_EQUAL(0, FindIndex(array, 1)); + UNIT_ASSERT_EQUAL(1, FindIndex(array, 2)); + UNIT_ASSERT_EQUAL(2, FindIndex(array, 3)); + UNIT_ASSERT_EQUAL(NPOS, FindIndex(array, 42)); + TVector<int> empty; - UNIT_ASSERT_EQUAL(NPOS, FindIndex(empty, 0)); - } + UNIT_ASSERT_EQUAL(NPOS, FindIndex(empty, 0)); + } Y_UNIT_TEST(FindIndexIfTest) { TVectorNoCopy v; @@ -276,10 +276,10 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { Y_UNIT_TEST(EraseIfTest) { TVector<int> data = {5, 4, 3, 2, 1, 0}; TVector<int> expected = {2, 1, 0}; - EraseIf(data, [](int i) { return i >= 3; }); - UNIT_ASSERT_EQUAL(data, expected); - } - + EraseIf(data, [](int i) { return i >= 3; }); + UNIT_ASSERT_EQUAL(data, expected); + } + Y_UNIT_TEST(EraseNodesIfTest) { TMap<int, int> map{{1, 1}, {2, 2}, {3, 5}}; TMap<int, int> expectedMap{{1, 1}}; diff --git a/util/generic/cast.h b/util/generic/cast.h index 0d4a41f385..268b79baf4 100644 --- a/util/generic/cast.h +++ b/util/generic/cast.h @@ -53,7 +53,7 @@ static inline T CheckedCast(F f) { } return static_cast<T>(f); -#endif // USE_DEBUG_CHECKED_CAST +#endif // USE_DEBUG_CHECKED_CAST } /* diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..1f2ae2ca38 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1,7 +1,7 @@ #pragma once #include "fwd.h" -#include "mapfindptr.h" +#include "mapfindptr.h" #include <util/memory/alloc.h> #include <util/system/type_name.h> diff --git a/util/generic/map.h b/util/generic/map.h index b5001b56c0..92e79ad9af 100644 --- a/util/generic/map.h +++ b/util/generic/map.h @@ -1,7 +1,7 @@ #pragma once #include "fwd.h" -#include "mapfindptr.h" +#include "mapfindptr.h" #include <util/str_stl.h> #include <util/memory/alloc.h> diff --git a/util/generic/mapfindptr.h b/util/generic/mapfindptr.h index bc10cac60f..fdacd9e997 100644 --- a/util/generic/mapfindptr.h +++ b/util/generic/mapfindptr.h @@ -1,41 +1,41 @@ -#pragma once - +#pragma once + #include <type_traits> -/** MapFindPtr usage: - -if (T* value = MapFindPtr(myMap, someKey) { - Cout << *value; -} - -*/ - +/** MapFindPtr usage: + +if (T* value = MapFindPtr(myMap, someKey) { + Cout << *value; +} + +*/ + template <class Map, class K> inline auto MapFindPtr(Map& map, const K& key) { auto i = map.find(key); return (i == map.end() ? nullptr : &i->second); -} - +} + template <class Map, class K> inline auto MapFindPtr(const Map& map, const K& key) { auto i = map.find(key); return (i == map.end() ? nullptr : &i->second); -} - +} + /** helper for THashMap/TMap */ template <class Derived> -struct TMapOps { +struct TMapOps { template <class K> inline auto FindPtr(const K& key) { - return MapFindPtr(static_cast<Derived&>(*this), key); - } + return MapFindPtr(static_cast<Derived&>(*this), key); + } template <class K> inline auto FindPtr(const K& key) const { - return MapFindPtr(static_cast<const Derived&>(*this), key); - } + return MapFindPtr(static_cast<const Derived&>(*this), key); + } template <class K, class DefaultValue> inline auto Value(const K& key, const DefaultValue& defaultValue) const -> std::remove_reference_t<decltype(*this->FindPtr(key))> { @@ -57,4 +57,4 @@ struct TMapOps { template <class K, class V> inline const V& ValueRef(const K& key, V&& defaultValue) const = delete; -}; +}; diff --git a/util/generic/mapfindptr_ut.cpp b/util/generic/mapfindptr_ut.cpp index 613da7a96b..e78817425b 100644 --- a/util/generic/mapfindptr_ut.cpp +++ b/util/generic/mapfindptr_ut.cpp @@ -2,26 +2,26 @@ #include "hash.h" #include <library/cpp/testing/unittest/registar.h> - + #include <map> #include "mapfindptr.h" Y_UNIT_TEST_SUITE(TMapFindPtrTest) { struct TTestMap: std::map<int, TString>, TMapOps<TTestMap> {}; - + Y_UNIT_TEST(TestDerivedClass) { TTestMap a; - + a[42] = "cat"; UNIT_ASSERT(a.FindPtr(42)); UNIT_ASSERT_EQUAL(*a.FindPtr(42), "cat"); UNIT_ASSERT_EQUAL(a.FindPtr(0), nullptr); - + //test mutation if (TString* p = a.FindPtr(42)) { *p = "dog"; - } + } UNIT_ASSERT(a.FindPtr(42)); UNIT_ASSERT_EQUAL(*a.FindPtr(42), "dog"); diff --git a/util/generic/ptr.h b/util/generic/ptr.h index 19db0e3ec5..2af6603934 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -17,13 +17,13 @@ using TGuardConversion = typename std::enable_if_t<std::is_convertible<U*, T*>:: template <class T> inline void AssertTypeComplete() { - // If compiler triggers this error from destructor of your class with - // smart pointer, then may be you should move the destructor definition - // to the .cpp file, where type T have full definition. - // - // 'delete' called on pointer to incomplete type is - // undefined behavior (missing destructor call/corrupted memory manager). - // 'sizeof' is used to trigger compile-time error. + // If compiler triggers this error from destructor of your class with + // smart pointer, then may be you should move the destructor definition + // to the .cpp file, where type T have full definition. + // + // 'delete' called on pointer to incomplete type is + // undefined behavior (missing destructor call/corrupted memory manager). + // 'sizeof' is used to trigger compile-time error. static_assert(sizeof(T) != 0, "Type must be complete"); } diff --git a/util/generic/refcount.h b/util/generic/refcount.h index 966e853b77..3f37e76cd7 100644 --- a/util/generic/refcount.h +++ b/util/generic/refcount.h @@ -63,9 +63,9 @@ protected: }; #if defined(SIMPLE_COUNTER_THREAD_CHECK) - + #include <util/system/thread.i> - + class TCheckPolicy { public: inline TCheckPolicy() { diff --git a/util/generic/strbase.h b/util/generic/strbase.h index ab39fc7537..eed24a1615 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -475,18 +475,18 @@ public: return AsStringView().rfind(str.data(), pos, str.size()); } - //~~~~Contains~~~~ + //~~~~Contains~~~~ /** * @returns Whether this string contains the provided substring. */ inline bool Contains(const TStringView s, size_t pos = 0) const noexcept { return !s.length() || find(s, pos) != npos; - } - + } + inline bool Contains(TChar c, size_t pos = 0) const noexcept { - return find(c, pos) != npos; - } - + return find(c, pos) != npos; + } + inline void Contains(std::enable_if<std::is_unsigned<TCharType>::value, char> c, size_t pos = 0) const noexcept { return find(ui8(c), pos) != npos; } diff --git a/util/generic/strbuf.h b/util/generic/strbuf.h index 70b9360d58..ab463595a9 100644 --- a/util/generic/strbuf.h +++ b/util/generic/strbuf.h @@ -321,19 +321,19 @@ public: inline bool AfterPrefix(const TdSelf& prefix, TdSelf& result) const noexcept { if (this->StartsWith(prefix)) { result = Tail(prefix.size()); - return true; - } - return false; - } - + return true; + } + return false; + } + inline bool BeforeSuffix(const TdSelf& suffix, TdSelf& result) const noexcept { if (this->EndsWith(suffix)) { result = Head(size() - suffix.size()); - return true; - } - return false; - } - + return true; + } + return false; + } + // returns true if string started with `prefix`, false otherwise inline bool SkipPrefix(const TdSelf& prefix) noexcept { return AfterPrefix(prefix, *this); diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 69cde785af..195b7b1b5d 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -82,19 +82,19 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { } Y_UNIT_TEST(TestAfterPrefix) { - TStringBuf str("cat_dog"); - - TStringBuf r = "the_same"; - UNIT_ASSERT(!str.AfterPrefix("dog", r)); - UNIT_ASSERT_EQUAL(r, "the_same"); - UNIT_ASSERT(str.AfterPrefix("cat_", r)); - UNIT_ASSERT_EQUAL(r, "dog"); - - //example: - str = "http://ya.ru"; - if (str.AfterPrefix("http://", r)) { - UNIT_ASSERT_EQUAL(r, "ya.ru"); - } + TStringBuf str("cat_dog"); + + TStringBuf r = "the_same"; + UNIT_ASSERT(!str.AfterPrefix("dog", r)); + UNIT_ASSERT_EQUAL(r, "the_same"); + UNIT_ASSERT(str.AfterPrefix("cat_", r)); + UNIT_ASSERT_EQUAL(r, "dog"); + + //example: + str = "http://ya.ru"; + if (str.AfterPrefix("http://", r)) { + UNIT_ASSERT_EQUAL(r, "ya.ru"); + } // SkipPrefix() TStringBuf a = "abcdef"; @@ -106,22 +106,22 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT(a.SkipPrefix("def") && a == ""); UNIT_ASSERT(a.SkipPrefix("") && a == ""); UNIT_ASSERT(!a.SkipPrefix("def") && a == ""); - } - + } + Y_UNIT_TEST(TestBeforeSuffix) { - TStringBuf str("cat_dog"); - - TStringBuf r = "the_same"; - UNIT_ASSERT(!str.BeforeSuffix("cat", r)); - UNIT_ASSERT_EQUAL(r, "the_same"); - UNIT_ASSERT(str.BeforeSuffix("_dog", r)); - UNIT_ASSERT_EQUAL(r, "cat"); - - //example: - str = "maps.yandex.com.ua"; - if (str.BeforeSuffix(".ru", r)) { - UNIT_ASSERT_EQUAL(r, "maps.yandex"); - } + TStringBuf str("cat_dog"); + + TStringBuf r = "the_same"; + UNIT_ASSERT(!str.BeforeSuffix("cat", r)); + UNIT_ASSERT_EQUAL(r, "the_same"); + UNIT_ASSERT(str.BeforeSuffix("_dog", r)); + UNIT_ASSERT_EQUAL(r, "cat"); + + //example: + str = "maps.yandex.com.ua"; + if (str.BeforeSuffix(".ru", r)) { + UNIT_ASSERT_EQUAL(r, "maps.yandex"); + } // ChopSuffix() TStringBuf a = "abcdef"; @@ -133,8 +133,8 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT(a.ChopSuffix("abc") && a == ""); UNIT_ASSERT(a.ChopSuffix("") && a == ""); UNIT_ASSERT(!a.ChopSuffix("abc") && a == ""); - } - + } + Y_UNIT_TEST(TestEmpty) { UNIT_ASSERT(TStringBuf().empty()); UNIT_ASSERT(!TStringBuf("q").empty()); diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index 44bb10bdeb..5ac2cef731 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -725,20 +725,20 @@ public: void TestContains() { const TStringType s(Data._0123456_12345()); const TStringType s2(Data._0123()); - - UNIT_ASSERT(s.Contains(Data._345())); - UNIT_ASSERT(!s2.Contains(Data._345())); - - UNIT_ASSERT(s.Contains('1')); - UNIT_ASSERT(!s.Contains('*')); - + + UNIT_ASSERT(s.Contains(Data._345())); + UNIT_ASSERT(!s2.Contains(Data._345())); + + UNIT_ASSERT(s.Contains('1')); + UNIT_ASSERT(!s.Contains('*')); + TStringType empty; - UNIT_ASSERT(s.Contains(empty)); - UNIT_ASSERT(!empty.Contains(s)); - UNIT_ASSERT(empty.Contains(empty)); + UNIT_ASSERT(s.Contains(empty)); + UNIT_ASSERT(!empty.Contains(s)); + UNIT_ASSERT(empty.Contains(empty)); UNIT_ASSERT(s.Contains(empty, s.length())); - } - + } + // Operators void TestOperators() { diff --git a/util/random/entropy.cpp b/util/random/entropy.cpp index 3617edb83d..bd34c0faed 100644 --- a/util/random/entropy.cpp +++ b/util/random/entropy.cpp @@ -26,7 +26,7 @@ #include <util/generic/buffer.h> #include <util/generic/singleton.h> -#include <util/digest/murmur.h> +#include <util/digest/murmur.h> #include <util/digest/city.h> #include <util/ysaveload.h> diff --git a/util/string/ascii.h b/util/string/ascii.h index 10344384d3..5b743029a8 100644 --- a/util/string/ascii.h +++ b/util/string/ascii.h @@ -4,13 +4,13 @@ #include <util/system/compat.h> #include <util/generic/string.h> -// ctype.h-like functions, locale-independent: -// IsAscii{Upper,Lower,Digit,Alpha,Alnum,Space} and -// AsciiTo{Upper,Lower} -// -// standard functions from <ctype.h> are locale dependent, -// and cause undefined behavior when called on chars outside [0..127] range - +// ctype.h-like functions, locale-independent: +// IsAscii{Upper,Lower,Digit,Alpha,Alnum,Space} and +// AsciiTo{Upper,Lower} +// +// standard functions from <ctype.h> are locale dependent, +// and cause undefined behavior when called on chars outside [0..127] range + namespace NPrivate { enum ECharClass { CC_SPACE = 1, @@ -61,9 +61,9 @@ namespace NPrivate { } constexpr bool IsAscii(const int c) noexcept { - return !(c & ~0x7f); -} - + return !(c & ~0x7f); +} + inline bool IsAsciiSpace(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_SPACE; } @@ -71,27 +71,27 @@ inline bool IsAsciiSpace(unsigned char c) { inline bool IsAsciiUpper(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_UPPER; } - + inline bool IsAsciiLower(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_LOWER; -} - +} + inline bool IsAsciiDigit(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_DIGIT; -} - +} + inline bool IsAsciiAlpha(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_ALPHA; -} - +} + inline bool IsAsciiAlnum(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_ALNUM; -} - +} + inline bool IsAsciiHex(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_ISHEX; -} - +} + inline bool IsAsciiPunct(unsigned char c) { return ::NPrivate::ASCII_CLASS[c] & ::NPrivate::CC_PUNCT; } @@ -101,9 +101,9 @@ inline bool IsAsciiPunct(unsigned char c) { template <class T> inline bool IsAsciiSpace(T c) { return ::NPrivate::RangeOk(c) && IsAsciiSpace(static_cast<unsigned char>(c)); -} - -template <class T> +} + +template <class T> inline bool IsAsciiUpper(T c) { return ::NPrivate::RangeOk(c) && IsAsciiUpper(static_cast<unsigned char>(c)); } @@ -150,12 +150,12 @@ inline char AsciiToLower(char c) noexcept { template <class T> inline ::NPrivate::TDereferenced<T> AsciiToLower(T c) noexcept { return (c >= 0 && c <= 127) ? (::NPrivate::TDereferenced<T>)AsciiToLower((ui8)c) : c; -} - -template <class T> +} + +template <class T> inline ::NPrivate::TDereferenced<T> AsciiToUpper(T c) noexcept { - return IsAsciiLower(c) ? (c + ('A' - 'a')) : c; -} + return IsAsciiLower(c) ? (c + ('A' - 'a')) : c; +} /** * ASCII case-insensitive string comparison (for proper UTF8 strings diff --git a/util/string/ascii_ut.cpp b/util/string/ascii_ut.cpp index 89069fee50..4108302622 100644 --- a/util/string/ascii_ut.cpp +++ b/util/string/ascii_ut.cpp @@ -1,42 +1,42 @@ -#include "ascii.h" -#include <ctype.h> - +#include "ascii.h" +#include <ctype.h> + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TAsciiTest) { Y_UNIT_TEST(TestAscii) { - UNIT_ASSERT(IsAsciiDigit('3')); - UNIT_ASSERT(!IsAsciiDigit('x')); - - UNIT_ASSERT(IsAsciiAlpha('r')); - UNIT_ASSERT(IsAsciiAlpha('R')); - UNIT_ASSERT(!IsAsciiAlpha('3')); - - UNIT_ASSERT_EQUAL(AsciiToLower('3'), '3'); - UNIT_ASSERT_EQUAL(AsciiToLower('A'), 'a'); - UNIT_ASSERT_EQUAL(AsciiToLower('a'), 'a'); - - UNIT_ASSERT_EQUAL(AsciiToUpper('3'), '3'); - UNIT_ASSERT_EQUAL(AsciiToUpper('A'), 'A'); - UNIT_ASSERT_EQUAL(AsciiToUpper('a'), 'A'); - - UNIT_ASSERT(IsAscii('a')); - UNIT_ASSERT(!IsAscii(-100)); - UNIT_ASSERT(!IsAscii(+200)); - UNIT_ASSERT(!IsAscii(int('a') + 256)); - - for (int i = 0; i < 128; ++i) { - UNIT_ASSERT_VALUES_EQUAL((bool)isxdigit(i), IsAsciiHex(i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isalnum(i), IsAsciiAlnum((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isalpha(i), IsAsciiAlpha((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isupper(i), IsAsciiUpper((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)islower(i), IsAsciiLower((char)i)); - UNIT_ASSERT_VALUES_EQUAL((bool)isdigit(i), IsAsciiDigit((char)i)); + UNIT_ASSERT(IsAsciiDigit('3')); + UNIT_ASSERT(!IsAsciiDigit('x')); + + UNIT_ASSERT(IsAsciiAlpha('r')); + UNIT_ASSERT(IsAsciiAlpha('R')); + UNIT_ASSERT(!IsAsciiAlpha('3')); + + UNIT_ASSERT_EQUAL(AsciiToLower('3'), '3'); + UNIT_ASSERT_EQUAL(AsciiToLower('A'), 'a'); + UNIT_ASSERT_EQUAL(AsciiToLower('a'), 'a'); + + UNIT_ASSERT_EQUAL(AsciiToUpper('3'), '3'); + UNIT_ASSERT_EQUAL(AsciiToUpper('A'), 'A'); + UNIT_ASSERT_EQUAL(AsciiToUpper('a'), 'A'); + + UNIT_ASSERT(IsAscii('a')); + UNIT_ASSERT(!IsAscii(-100)); + UNIT_ASSERT(!IsAscii(+200)); + UNIT_ASSERT(!IsAscii(int('a') + 256)); + + for (int i = 0; i < 128; ++i) { + UNIT_ASSERT_VALUES_EQUAL((bool)isxdigit(i), IsAsciiHex(i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isspace(i), IsAsciiSpace((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isalnum(i), IsAsciiAlnum((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isalpha(i), IsAsciiAlpha((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isupper(i), IsAsciiUpper((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)islower(i), IsAsciiLower((char)i)); + UNIT_ASSERT_VALUES_EQUAL((bool)isdigit(i), IsAsciiDigit((char)i)); UNIT_ASSERT_VALUES_EQUAL((bool)ispunct(i), IsAsciiPunct((char)i)); - } - } + } + } Y_UNIT_TEST(Test1) { for (int i = 128; i < 1000; ++i) { @@ -95,4 +95,4 @@ Y_UNIT_TEST_SUITE(TAsciiTest) { UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "asD"), true); UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "ast"), false); } -} +} diff --git a/util/string/cast.cpp b/util/string/cast.cpp index aa1e65a8e9..7f5f8c6b01 100644 --- a/util/string/cast.cpp +++ b/util/string/cast.cpp @@ -522,11 +522,11 @@ TString FromStringImpl<TString>(const char* data, size_t len) { } template <> -TStringBuf FromStringImpl<TStringBuf>(const char* data, size_t len) { - return TStringBuf(data, len); -} - -template <> +TStringBuf FromStringImpl<TStringBuf>(const char* data, size_t len) { + return TStringBuf(data, len); +} + +template <> std::string FromStringImpl<std::string>(const char* data, size_t len) { return std::string(data, len); } @@ -536,11 +536,11 @@ TUtf16String FromStringImpl<TUtf16String>(const wchar16* data, size_t len) { return TUtf16String(data, len); } -template <> -TWtringBuf FromStringImpl<TWtringBuf>(const wchar16* data, size_t len) { - return TWtringBuf(data, len); -} - +template <> +TWtringBuf FromStringImpl<TWtringBuf>(const wchar16* data, size_t len) { + return TWtringBuf(data, len); +} + // Try-versions template <> bool TryFromStringImpl<TStringBuf>(const char* data, size_t len, TStringBuf& result) { diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 033450c38c..e0da29e1b9 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -19,7 +19,7 @@ #define EPS 10E-7 -#define HEX_MACROS_MAP(mac, type, val) mac(type, val, 2) mac(type, val, 8) mac(type, val, 10) mac(type, val, 16) +#define HEX_MACROS_MAP(mac, type, val) mac(type, val, 2) mac(type, val, 8) mac(type, val, 10) mac(type, val, 16) #define OK_HEX_CHECK(type, val, base) UNIT_ASSERT_EQUAL((IntFromStringForCheck<base>(IntToString<base>(val))), val); #define EXC_HEX_CHECK(type, val, base) UNIT_ASSERT_EXCEPTION((IntFromString<type, base>(IntToString<base>(val))), yexception); @@ -326,7 +326,7 @@ Y_UNIT_TEST_SUITE(TCastTest) { UNIT_ASSERT_VALUES_EQUAL(a, b); UNIT_ASSERT_VALUES_EQUAL((void*)a.data(), (void*)b.data()); } - + #if 0 Y_UNIT_TEST(TestBufferOverflow) { CheckConvertToBuffer<float>(1.f, 5, "1"); diff --git a/util/string/hex.cpp b/util/string/hex.cpp index 667397987f..deea4e3ba7 100644 --- a/util/string/hex.cpp +++ b/util/string/hex.cpp @@ -1,5 +1,5 @@ -#include "hex.h" - +#include "hex.h" + const char* const Char2DigitTable = ("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" @@ -16,48 +16,48 @@ const char* const Char2DigitTable = ("\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"); - -char* HexEncode(const void* in, size_t len, char* out) { - const unsigned char* b = (const unsigned char*)in; - const unsigned char* e = b + len; - - while (b != e) { - *out++ = DigitToChar(*b / 16); - *out++ = DigitToChar(*b++ % 16); - } - - return out; -} - -void* HexDecode(const void* in, size_t len, void* ptr) { - const char* b = (const char*)in; - const char* e = b + len; + +char* HexEncode(const void* in, size_t len, char* out) { + const unsigned char* b = (const unsigned char*)in; + const unsigned char* e = b + len; + + while (b != e) { + *out++ = DigitToChar(*b / 16); + *out++ = DigitToChar(*b++ % 16); + } + + return out; +} + +void* HexDecode(const void* in, size_t len, void* ptr) { + const char* b = (const char*)in; + const char* e = b + len; Y_ENSURE(!(len & 1), TStringBuf("Odd buffer length passed to HexDecode")); - - char* out = (char*)ptr; - - while (b != e) { + + char* out = (char*)ptr; + + while (b != e) { *out++ = (char)String2Byte(b); - b += 2; - } - - return out; -} - + b += 2; + } + + return out; +} + TString HexEncode(const void* in, size_t len) { TString ret; - - ret.ReserveAndResize(len << 1); - HexEncode(in, len, ret.begin()); - - return ret; -} - + + ret.ReserveAndResize(len << 1); + HexEncode(in, len, ret.begin()); + + return ret; +} + TString HexDecode(const void* in, size_t len) { TString ret; - + ret.ReserveAndResize(len >> 1); HexDecode(in, len, ret.begin()); - - return ret; -} + + return ret; +} diff --git a/util/string/hex.h b/util/string/hex.h index af3d2d528f..5e9fdcbbbb 100644 --- a/util/string/hex.h +++ b/util/string/hex.h @@ -13,11 +13,11 @@ inline static char DigitToChar(unsigned char digit) { } extern const char* const Char2DigitTable; - + inline static int Char2Digit(char ch) { - char result = Char2DigitTable[(unsigned char)ch]; + char result = Char2DigitTable[(unsigned char)ch]; Y_ENSURE(result != '\xff', "invalid hex character " << (int)ch); - return result; + return result; } //! Convert a hex string of exactly 2 chars to int @@ -26,7 +26,7 @@ inline static int String2Byte(const char* s) { return Char2Digit(*s) * 16 + Char2Digit(*(s + 1)); } -char* HexEncode(const void* in, size_t len, char* out); +char* HexEncode(const void* in, size_t len, char* out); TString HexEncode(const void* in, size_t len); diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..6852f0600f 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -441,7 +441,7 @@ void GetNext(TStringBuf& s, D delim, TMaybe<P>& param) { } } -// example: +// example: // Split(TStringBuf("Sherlock,2014,36.6"), ',', name, year, temperature); template <class D, class P1, class P2> void Split(TStringBuf s, D delim, P1& p1, P2& p2) { @@ -451,9 +451,9 @@ void Split(TStringBuf s, D delim, P1& p1, P2& p2) { } template <class D, class P1, class P2, class... Other> -void Split(TStringBuf s, D delim, P1& p1, P2& p2, Other&... other) { +void Split(TStringBuf s, D delim, P1& p1, P2& p2, Other&... other) { GetNext(s, delim, p1); - Split(s, delim, p2, other...); + Split(s, delim, p2, other...); } /** diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index 43e59f2d75..cd8b8fccdc 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -254,10 +254,10 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { Y_UNIT_TEST(ConvenientSplitTest) { TString data("abc 22 33.5 xyz"); TString str; - int num1 = 0; - double num2 = 0; - TStringBuf strBuf; - Split(data, ' ', str, num1, num2, strBuf); + int num1 = 0; + double num2 = 0; + TStringBuf strBuf; + Split(data, ' ', str, num1, num2, strBuf); UNIT_ASSERT_VALUES_EQUAL(str, "abc"); UNIT_ASSERT_VALUES_EQUAL(num1, 22); UNIT_ASSERT_VALUES_EQUAL(num2, 33.5); diff --git a/util/system/defaults.h b/util/system/defaults.h index dcd7abea38..0a363b5949 100644 --- a/util/system/defaults.h +++ b/util/system/defaults.h @@ -151,5 +151,5 @@ constexpr bool Y_IS_DEBUG_BUILD = true; #if !defined(Y_GENERATE_UNIQUE_ID) #define Y_GENERATE_UNIQUE_ID(N) Y_CAT(N, __LINE__) #endif - -#define NPOS ((size_t)-1) + +#define NPOS ((size_t)-1) diff --git a/util/system/mutex.cpp b/util/system/mutex.cpp index 4041402db9..22fdf39a0b 100644 --- a/util/system/mutex.cpp +++ b/util/system/mutex.cpp @@ -1,7 +1,7 @@ #include "mutex.h" #include <util/generic/yexception.h> -#include <errno.h> +#include <errno.h> #if defined(_win_) #include "winint.h" diff --git a/util/system/shmat.cpp b/util/system/shmat.cpp index 07ff0d6caa..151dc5ba1b 100644 --- a/util/system/shmat.cpp +++ b/util/system/shmat.cpp @@ -89,12 +89,12 @@ namespace { } #endif -TSharedMemory::TSharedMemory() +TSharedMemory::TSharedMemory() : Handle(INVALID_FHANDLE) , Data(nullptr) - , Size(0) -{ -} + , Size(0) +{ +} #if defined(_win_) static void FormatName(char* buf, const TGUID& id) { diff --git a/util/system/shmat.h b/util/system/shmat.h index d9da3c151a..27467d1035 100644 --- a/util/system/shmat.h +++ b/util/system/shmat.h @@ -12,7 +12,7 @@ class TSharedMemory: public TThrRefBase { int Size; public: - TSharedMemory(); + TSharedMemory(); ~TSharedMemory() override; bool Create(int Size); diff --git a/util/system/tls.cpp b/util/system/tls.cpp index c2f1a04a14..09a30f6305 100644 --- a/util/system/tls.cpp +++ b/util/system/tls.cpp @@ -113,7 +113,7 @@ namespace { } virtual TPerThreadStorage* MyStorageSlow() = 0; - + virtual ~TGenericTlsBase() = default; }; } diff --git a/util/system/types.h b/util/system/types.h index 12e68a6060..d4306a4dc4 100644 --- a/util/system/types.h +++ b/util/system/types.h @@ -94,11 +94,11 @@ typedef int64_t i64; #error "Unsupported platform" #endif -// SUPERLONG -#if !defined(DONT_USE_SUPERLONG) && !defined(SUPERLONG_MAX) +// SUPERLONG +#if !defined(DONT_USE_SUPERLONG) && !defined(SUPERLONG_MAX) #define SUPERLONG_MAX ~LL(0) -typedef i64 SUPERLONG; -#endif +typedef i64 SUPERLONG; +#endif // UNICODE #ifdef __cplusplus diff --git a/util/thread/pool.h b/util/thread/pool.h index d1ea3a67cb..ad0f447cc4 100644 --- a/util/thread/pool.h +++ b/util/thread/pool.h @@ -15,22 +15,22 @@ class TDuration; struct IObjectInQueue { virtual ~IObjectInQueue() = default; - /** - * Supposed to be implemented by user, to define jobs processed - * in multiple threads. - * - * @param threadSpecificResource is nullptr by default. But if you override + /** + * Supposed to be implemented by user, to define jobs processed + * in multiple threads. + * + * @param threadSpecificResource is nullptr by default. But if you override * IThreadPool::CreateThreadSpecificResource, then result of * IThreadPool::CreateThreadSpecificResource is passed as threadSpecificResource - * parameter. - */ - virtual void Process(void* threadSpecificResource) = 0; + * parameter. + */ + virtual void Process(void* threadSpecificResource) = 0; }; -/** - * Mighty class to add 'Pool' method to derived classes. - * Useful only for creators of new queue classes. - */ +/** + * Mighty class to add 'Pool' method to derived classes. + * Useful only for creators of new queue classes. + */ class TThreadFactoryHolder { public: TThreadFactoryHolder() noexcept; @@ -133,20 +133,20 @@ struct TThreadPoolParams { } }; -/** +/** * A queue processed simultaneously by several threads - */ + */ class IThreadPool: public IThreadFactory, public TNonCopyable { public: using TParams = TThreadPoolParams; ~IThreadPool() override = default; - - /** - * Safe versions of Add*() functions. Behave exactly like as non-safe - * version of Add*(), but use exceptions instead returning false - */ - void SafeAdd(IObjectInQueue* obj); + + /** + * Safe versions of Add*() functions. Behave exactly like as non-safe + * version of Add*(), but use exceptions instead returning false + */ + void SafeAdd(IObjectInQueue* obj); template <class T> void SafeAddFunc(T&& func) { @@ -154,13 +154,13 @@ public: } void SafeAddAndOwn(THolder<IObjectInQueue> obj); - - /** - * Add object to queue, run ojb->Proccess in other threads. - * Obj is not deleted after execution - * @return true of obj is successfully added to queue - * @return false if queue is full or shutting down - */ + + /** + * Add object to queue, run ojb->Proccess in other threads. + * Obj is not deleted after execution + * @return true of obj is successfully added to queue + * @return false if queue is full or shutting down + */ virtual bool Add(IObjectInQueue* obj) Y_WARN_UNUSED_RESULT = 0; template <class T> @@ -174,17 +174,17 @@ public: } bool AddAndOwn(THolder<IObjectInQueue> obj) Y_WARN_UNUSED_RESULT; - virtual void Start(size_t threadCount, size_t queueSizeLimit = 0) = 0; + virtual void Start(size_t threadCount, size_t queueSizeLimit = 0) = 0; /** Wait for completion of all scheduled objects, and then exit */ virtual void Stop() noexcept = 0; - /** Number of tasks currently in queue */ + /** Number of tasks currently in queue */ virtual size_t Size() const noexcept = 0; - -public: - /** - * RAII wrapper for Create/DestroyThreadSpecificResource. + +public: + /** + * RAII wrapper for Create/DestroyThreadSpecificResource. * Useful only for implementers of new IThreadPool queues. - */ + */ class TTsr { public: inline TTsr(IThreadPool* q) @@ -210,12 +210,12 @@ public: void* Data_; }; - /** - * CreateThreadSpecificResource and DestroyThreadSpecificResource + /** + * CreateThreadSpecificResource and DestroyThreadSpecificResource * called from internals of (TAdaptiveThreadPool, TThreadPool, ...) implementation, * not by user of IThreadPool interface. - * Created resource is passed to IObjectInQueue::Proccess function. - */ + * Created resource is passed to IObjectInQueue::Proccess function. + */ virtual void* CreateThreadSpecificResource() { return nullptr; } @@ -230,11 +230,11 @@ private: IThread* DoCreate() override; }; -/** +/** * Single-threaded implementation of IThreadPool, process tasks in same thread when - * added. - * Can be used to remove multithreading. - */ + * added. + * Can be used to remove multithreading. + */ class TFakeThreadPool: public IThreadPool { public: bool Add(IObjectInQueue* pObj) override Y_WARN_UNUSED_RESULT { @@ -263,17 +263,17 @@ protected: TParams Params; }; -/** queue processed by fixed size thread pool */ +/** queue processed by fixed size thread pool */ class TThreadPool: public TThreadPoolBase { public: TThreadPool(const TParams& params = {}); ~TThreadPool() override; bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** - * @param queueSizeLimit means "unlimited" when = 0 - * @param threadCount means "single thread" when = 0 - */ + /** + * @param queueSizeLimit means "unlimited" when = 0 + * @param threadCount means "single thread" when = 0 + */ void Start(size_t threadCount, size_t queueSizeLimit = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; @@ -286,24 +286,24 @@ private: THolder<TImpl> Impl_; }; -/** - * Always create new thread for new task, when all existing threads are busy. - * Maybe dangerous, number of threads is not limited. - */ +/** + * Always create new thread for new task, when all existing threads are busy. + * Maybe dangerous, number of threads is not limited. + */ class TAdaptiveThreadPool: public TThreadPoolBase { public: TAdaptiveThreadPool(const TParams& params = {}); ~TAdaptiveThreadPool() override; - /** - * If working thread waits task too long (more then interval parameter), - * then the thread would be killed. Default value - infinity, all created threads - * waits for new task forever, before Stop. - */ + /** + * If working thread waits task too long (more then interval parameter), + * then the thread would be killed. Default value - infinity, all created threads + * waits for new task forever, before Stop. + */ void SetMaxIdleTime(TDuration interval); bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** @param thrnum, @param maxque are ignored */ + /** @param thrnum, @param maxque are ignored */ void Start(size_t thrnum = 0, size_t maxque = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; @@ -320,10 +320,10 @@ public: ~TSimpleThreadPool() override; bool Add(IObjectInQueue* obj) override Y_WARN_UNUSED_RESULT; - /** + /** * @parameter thrnum. If thrnum is 0, use TAdaptiveThreadPool with small * SetMaxIdleTime interval parameter. if thrnum is not 0, use non-blocking TThreadPool - */ + */ void Start(size_t thrnum, size_t maxque = 0) override; void Stop() noexcept override; size_t Size() const noexcept override; @@ -332,11 +332,11 @@ private: THolder<IThreadPool> Slave_; }; -/** - * Helper to override virtual functions Create/DestroyThreadSpecificResource +/** + * Helper to override virtual functions Create/DestroyThreadSpecificResource * from IThreadPool and implement them using functions with same name from - * pointer to TSlave. - */ + * pointer to TSlave. + */ template <class TQueueType, class TSlave> class TThreadPoolBinder: public TQueueType { public: |