diff options
author | stanly <stanly@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:49 +0300 |
commit | cde218e65dfef5ce03a48d641fd8f7913cf17b2d (patch) | |
tree | d3349caea4095825a55b5ba24fe758067b29ce6f /util | |
parent | 9f813499b4ef585cb3c2bb93de93ef003daf4fc4 (diff) | |
download | ydb-cde218e65dfef5ce03a48d641fd8f7913cf17b2d.tar.gz |
Restoring authorship annotation for <stanly@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
32 files changed, 381 insertions, 381 deletions
diff --git a/util/folder/fts.cpp b/util/folder/fts.cpp index 0e6a6f86eb..314e8d6d58 100644 --- a/util/folder/fts.cpp +++ b/util/folder/fts.cpp @@ -215,18 +215,18 @@ static int fts_safe_changedir(FTS*, FTSENT*, int, const char*); #define BNAMES 2 /* yfts_children, names only */ #define BREAD 3 /* yfts_read */ -static u_short -yfts_type_from_info(u_short info) { - if (info == FTS_D || info == FTS_DP || info == FTS_DOT) { - return FTS_D; - } else if (info == FTS_F) { - return FTS_F; - } else if (info == FTS_SL || info == FTS_SLNONE) { - return FTS_SL; - } - return FTS_NSOK; -} - +static u_short +yfts_type_from_info(u_short info) { + if (info == FTS_D || info == FTS_DP || info == FTS_DOT) { + return FTS_D; + } else if (info == FTS_F) { + return FTS_F; + } else if (info == FTS_SL || info == FTS_SLNONE) { + return FTS_SL; + } + return FTS_NSOK; +} + static void* yreallocf(void* ptr, size_t size) { @@ -314,7 +314,7 @@ FTS* yfts_open(char* const* argv, int options, int (*compar)(const FTSENT**, con p->fts_parent = parent; p->fts_accpath = p->fts_name; p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); - p->fts_type = yfts_type_from_info(p->fts_info); + p->fts_type = yfts_type_from_info(p->fts_info); /* Command-line "." and ".." are real directories. */ if (p->fts_info == FTS_DOT) { @@ -482,7 +482,7 @@ yfts_read(FTS* sp) { /* Any type of file may be re-visited; re-stat and re-turn. */ if (instr == FTS_AGAIN) { p->fts_info = fts_stat(sp, p, 0); - p->fts_type = yfts_type_from_info(p->fts_info); + p->fts_type = yfts_type_from_info(p->fts_info); return (p); } @@ -495,7 +495,7 @@ yfts_read(FTS* sp) { if (instr == FTS_FOLLOW && (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { p->fts_info = fts_stat(sp, p, 1); - p->fts_type = yfts_type_from_info(p->fts_info); + p->fts_type = yfts_type_from_info(p->fts_info); if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { if (valid_dird(p->fts_symfd = get_cwdd())) { p->fts_errno = errno; @@ -591,7 +591,7 @@ next: } if (p->fts_instr == FTS_FOLLOW) { p->fts_info = fts_stat(sp, p, 1); - p->fts_type = yfts_type_from_info(p->fts_info); + p->fts_type = yfts_type_from_info(p->fts_info); if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { if (valid_dird(p->fts_symfd = get_cwdd())) { @@ -981,16 +981,16 @@ fts_build(FTS* sp, int type) p->fts_flags |= FTS_ISW; #endif -#ifdef _DIRENT_HAVE_D_TYPE - if (dp->d_type == DT_DIR) { - p->fts_type = FTS_D; - } else if (dp->d_type == DT_REG) { - p->fts_type = FTS_F; - } else if (dp->d_type == DT_LNK) { - p->fts_type = FTS_SL; - } -#endif - +#ifdef _DIRENT_HAVE_D_TYPE + if (dp->d_type == DT_DIR) { + p->fts_type = FTS_D; + } else if (dp->d_type == DT_REG) { + p->fts_type = FTS_F; + } else if (dp->d_type == DT_LNK) { + p->fts_type = FTS_SL; + } +#endif + // coverity[dead_error_line]: false positive if (cderrno) { if (nlinks) { @@ -1019,7 +1019,7 @@ fts_build(FTS* sp, int type) } /* Stat it. */ p->fts_info = fts_stat(sp, p, 0); - p->fts_type = yfts_type_from_info(p->fts_info); + p->fts_type = yfts_type_from_info(p->fts_info); /* Decrement link count if applicable. */ if (nlinks > 0 && (p->fts_info == FTS_D || @@ -1259,7 +1259,7 @@ fts_alloc(FTS* sp, const char* name, int namelen) p->fts_instr = FTS_NOINSTR; p->fts_number = 0; p->fts_pointer = nullptr; - p->fts_type = FTS_NSOK; + p->fts_type = FTS_NSOK; return (p); } diff --git a/util/folder/fts.h b/util/folder/fts.h index f3c799e8c8..6ee42fd803 100644 --- a/util/folder/fts.h +++ b/util/folder/fts.h @@ -84,7 +84,7 @@ typedef struct _ftsent { #define FTS_SLNONE 13 /* symbolic link without target */ #define FTS_W 14 /* whiteout object */ u_short fts_info; /* user flags for FTSENT structure */ - u_short fts_type; /* type of fs node; one of FTS_D, FTS_F, FTS_SL */ + u_short fts_type; /* type of fs node; one of FTS_D, FTS_F, FTS_SL */ #define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ #define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ diff --git a/util/folder/iterator.h b/util/folder/iterator.h index 69e025b9c4..f84cac2b99 100644 --- a/util/folder/iterator.h +++ b/util/folder/iterator.h @@ -97,10 +97,10 @@ public: return ret; } - inline void Skip(FTSENT* ent) { - yfts_set(FileTree_.Get(), ent, FTS_SKIP); - } - + inline void Skip(FTSENT* ent) { + yfts_set(FileTree_.Get(), ent, FTS_SKIP); + } + private: TOptions Options_; TString Path_; diff --git a/util/folder/iterator_ut.cpp b/util/folder/iterator_ut.cpp index 936becd139..9a3f92313f 100644 --- a/util/folder/iterator_ut.cpp +++ b/util/folder/iterator_ut.cpp @@ -22,7 +22,7 @@ class TDirIteratorTest: public TTestBase { UNIT_TEST(TestIt) UNIT_TEST(TestError) UNIT_TEST(TestLocal) - UNIT_TEST(TestSkip) + UNIT_TEST(TestSkip) UNIT_TEST(TestSort) UNIT_TEST_SUITE_END(); @@ -134,45 +134,45 @@ private: } } - inline void TestSkip() { - TDirHier hier; - - const TString dir = "tmpdir"; - const TDirHier::TPath path = {dir, 1}; - - hier.Add(path); - hier.AddDir(dir + LOCSLASH_C + "dir1"); - hier.AddDir(dir + LOCSLASH_C + "dir1" + LOCSLASH_C + "dir2"); - // - // Without skip - // - { - TDirIterator di(dir); - - UNIT_ASSERT(di.Next()); - UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir1"); - UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir2"); - UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir2"); - UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir1"); - UNIT_ASSERT(di.Next()); - UNIT_ASSERT_EQUAL(di.Next(), nullptr); - } - // - // With skip - // - { - TDirIterator di(dir); - - UNIT_ASSERT(di.Next()); - auto ent = di.Next(); - UNIT_ASSERT_EQUAL(TStringBuf(ent->fts_name), "dir1"); - di.Skip(ent); - UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir1"); - UNIT_ASSERT(di.Next()); - UNIT_ASSERT_EQUAL(di.Next(), nullptr); - } - } - + inline void TestSkip() { + TDirHier hier; + + const TString dir = "tmpdir"; + const TDirHier::TPath path = {dir, 1}; + + hier.Add(path); + hier.AddDir(dir + LOCSLASH_C + "dir1"); + hier.AddDir(dir + LOCSLASH_C + "dir1" + LOCSLASH_C + "dir2"); + // + // Without skip + // + { + TDirIterator di(dir); + + UNIT_ASSERT(di.Next()); + UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir1"); + UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir2"); + UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir2"); + UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir1"); + UNIT_ASSERT(di.Next()); + UNIT_ASSERT_EQUAL(di.Next(), nullptr); + } + // + // With skip + // + { + TDirIterator di(dir); + + UNIT_ASSERT(di.Next()); + auto ent = di.Next(); + UNIT_ASSERT_EQUAL(TStringBuf(ent->fts_name), "dir1"); + di.Skip(ent); + UNIT_ASSERT_EQUAL(TStringBuf(di.Next()->fts_name), "dir1"); + UNIT_ASSERT(di.Next()); + UNIT_ASSERT_EQUAL(di.Next(), nullptr); + } + } + inline void TestSort() { TDirHier dh; const TString dir("tmpdir"); diff --git a/util/folder/path.cpp b/util/folder/path.cpp index bfe0c67d68..0b5a1a83ae 100644 --- a/util/folder/path.cpp +++ b/util/folder/path.cpp @@ -367,14 +367,14 @@ void TFsPath::MkDir(const int mode) const { CheckDefined(); if (!Exists()) { int r = Mkdir(this->c_str(), mode); - if (r != 0) { - // TODO (stanly) will still fail on Windows because - // LastSystemError() returns windows specific ERROR_ALREADY_EXISTS - // instead of EEXIST. - if (LastSystemError() != EEXIST) { - ythrow TIoSystemError() << "could not create directory " << Path_; - } - } + if (r != 0) { + // TODO (stanly) will still fail on Windows because + // LastSystemError() returns windows specific ERROR_ALREADY_EXISTS + // instead of EEXIST. + if (LastSystemError() != EEXIST) { + ythrow TIoSystemError() << "could not create directory " << Path_; + } + } } } diff --git a/util/folder/path.h b/util/folder/path.h index 2fb4d6b4ef..5ab77b2612 100644 --- a/util/folder/path.h +++ b/util/folder/path.h @@ -115,12 +115,12 @@ public: } TFsPath RelativeTo(const TFsPath& root) const; //must be subpath of root - - /** - * @returns relative path or empty path if root equals to this. - */ + + /** + * @returns relative path or empty path if root equals to this. + */ TFsPath RelativePath(const TFsPath& root) const; //..; for relative paths 1st component must be the same - + /** * Never fails. Returns this if already a root. */ diff --git a/util/generic/array_ref.h b/util/generic/array_ref.h index 1ac60ac7d3..811147b212 100644 --- a/util/generic/array_ref.h +++ b/util/generic/array_ref.h @@ -252,12 +252,12 @@ TArrayRef<char> as_writable_bytes(TArrayRef<T> arrayRef) noexcept { template <class Range> constexpr TArrayRef<const typename Range::value_type> MakeArrayRef(const Range& range) { return TArrayRef<const typename Range::value_type>(range); -} - +} + template <class Range> constexpr TArrayRef<typename Range::value_type> MakeArrayRef(Range& range) { return TArrayRef<typename Range::value_type>(range); -} +} template <class Range> constexpr TArrayRef<const typename Range::value_type> MakeConstArrayRef(const Range& range) { diff --git a/util/generic/buffer.cpp b/util/generic/buffer.cpp index b92697e1d0..8fde049b6e 100644 --- a/util/generic/buffer.cpp +++ b/util/generic/buffer.cpp @@ -22,14 +22,14 @@ TBuffer::TBuffer(TBuffer&& b) noexcept Swap(b); } -TBuffer::TBuffer(const char* buf, size_t len) +TBuffer::TBuffer(const char* buf, size_t len) : Data_(nullptr) - , Len_(0) - , Pos_(0) -{ - Append(buf, len); -} - + , Len_(0) + , Pos_(0) +{ + Append(buf, len); +} + TBuffer& TBuffer::operator=(TBuffer&& b) noexcept { y_deallocate(Data_); diff --git a/util/generic/intrlist.h b/util/generic/intrlist.h index b5d3f2051b..5995c75fcf 100644 --- a/util/generic/intrlist.h +++ b/util/generic/intrlist.h @@ -11,7 +11,7 @@ struct TIntrusiveListDefaultTag {}; * two-way linked list */ template <class T, class Tag = TIntrusiveListDefaultTag> -class TIntrusiveListItem { +class TIntrusiveListItem { private: using TListItem = TIntrusiveListItem<T, Tag>; @@ -110,16 +110,16 @@ public: } private: - inline TIntrusiveListItem(const TIntrusiveListItem&) = delete; - inline TIntrusiveListItem& operator=(const TIntrusiveListItem&) = delete; - -private: + inline TIntrusiveListItem(const TIntrusiveListItem&) = delete; + inline TIntrusiveListItem& operator=(const TIntrusiveListItem&) = delete; + +private: TListItem* Next_; TListItem* Prev_; }; template <class T, class Tag> -class TIntrusiveList { +class TIntrusiveList { private: using TListItem = TIntrusiveListItem<T, Tag>; @@ -342,8 +342,8 @@ public: public: inline TIntrusiveList() noexcept = default; - inline ~TIntrusiveList() = default; - + inline ~TIntrusiveList() = default; + inline TIntrusiveList(TIntrusiveList&& right) noexcept { this->Swap(right); } @@ -362,7 +362,7 @@ public: } inline size_t Size() const noexcept { - return std::distance(Begin(), End()); + return std::distance(Begin(), End()); } inline void Remove(TListItem* item) noexcept { @@ -577,10 +577,10 @@ public: } private: - inline TIntrusiveList(const TIntrusiveList&) = delete; - inline TIntrusiveList& operator=(const TIntrusiveList&) = delete; - -private: + inline TIntrusiveList(const TIntrusiveList&) = delete; + inline TIntrusiveList& operator=(const TIntrusiveList&) = delete; + +private: TListItem End_; }; @@ -687,16 +687,16 @@ public: template <class TListItem, class TNode> class TIteratorBase { public: - using TItem = TListItem; - using TReference = TNode&; - using TPointer = TNode*; - - using difference_type = std::ptrdiff_t; - using value_type = TNode; - using pointer = TPointer; - using reference = TReference; - using iterator_category = std::forward_iterator_tag; - + using TItem = TListItem; + using TReference = TNode&; + using TPointer = TNode*; + + using difference_type = std::ptrdiff_t; + using value_type = TNode; + using pointer = TPointer; + using reference = TReference; + using iterator_category = std::forward_iterator_tag; + inline TIteratorBase(TListItem* item) noexcept : Item_(item) { @@ -766,7 +766,7 @@ public: } inline size_t Size() const noexcept { - return std::distance(Begin(), End()); + return std::distance(Begin(), End()); } inline void Clear() noexcept { diff --git a/util/generic/iterator.h b/util/generic/iterator.h index 19e9d20976..f7e718e85d 100644 --- a/util/generic/iterator.h +++ b/util/generic/iterator.h @@ -70,12 +70,12 @@ public: // TODO: private public: static constexpr bool IsNoexceptNext = noexcept(std::declval<TSlave>().Next()); - using difference_type = std::ptrdiff_t; + using difference_type = std::ptrdiff_t; using pointer = decltype(std::declval<TSlave>().Next()); using reference = decltype(*std::declval<TSlave>().Next()); using value_type = std::remove_cv_t<std::remove_reference_t<reference>>; using iterator_category = std::input_iterator_tag; - + inline TIterator() noexcept : Slave_(nullptr) , Cur_() diff --git a/util/generic/iterator_range.cpp b/util/generic/iterator_range.cpp index bd8d7ff81b..97e1d8c3dd 100644 --- a/util/generic/iterator_range.cpp +++ b/util/generic/iterator_range.cpp @@ -1 +1 @@ -#include "iterator_range.h" +#include "iterator_range.h" diff --git a/util/generic/iterator_range.h b/util/generic/iterator_range.h index 9f4d02da29..45db9f055d 100644 --- a/util/generic/iterator_range.h +++ b/util/generic/iterator_range.h @@ -49,9 +49,9 @@ public: using difference_type = typename std::iterator_traits<iterator>::difference_type; using size_type = std::size_t; - TIteratorRange() - : Begin_() - , End_() + TIteratorRange() + : Begin_() + , End_() { } @@ -70,13 +70,13 @@ public: } Y_PURE_FUNCTION bool empty() const { - return Begin_ == End_; - } - - size_type size() const { + return Begin_ == End_; + } + + size_type size() const { return End_ - Begin_; - } - + } + reference operator[](size_t at) const { Y_ASSERT(at < size()); diff --git a/util/generic/iterator_range_ut.cpp b/util/generic/iterator_range_ut.cpp index a7e3670ae1..e859c90b01 100644 --- a/util/generic/iterator_range_ut.cpp +++ b/util/generic/iterator_range_ut.cpp @@ -1,4 +1,4 @@ -#include "iterator_range.h" +#include "iterator_range.h" #include <library/cpp/testing/unittest/registar.h> #include <util/generic/algorithm.h> @@ -6,9 +6,9 @@ Y_UNIT_TEST_SUITE(IteratorRange) { Y_UNIT_TEST(DefaultConstructor) { - TIteratorRange<int*> range; - UNIT_ASSERT(range.empty()); - } + TIteratorRange<int*> range; + UNIT_ASSERT(range.empty()); + } Y_UNIT_TEST(DefaultConstructorSentinel) { TIteratorRange<int*, void*> range; @@ -16,11 +16,11 @@ Y_UNIT_TEST_SUITE(IteratorRange) { } Y_UNIT_TEST(RangeBasedForLoop) { - // compileability test - for (int i : TIteratorRange<int*>()) { - Y_UNUSED(i); - } - } + // compileability test + for (int i : TIteratorRange<int*>()) { + Y_UNUSED(i); + } + } Y_UNIT_TEST(RangeBasedForLoopSentinel) { // compileability test @@ -30,11 +30,11 @@ Y_UNIT_TEST_SUITE(IteratorRange) { } Y_UNIT_TEST(Works) { - const int values[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - auto range = MakeIteratorRange(values, values + Y_ARRAY_SIZE(values)); - UNIT_ASSERT_VALUES_EQUAL(range.size(), Y_ARRAY_SIZE(values)); - UNIT_ASSERT(Equal(range.begin(), range.end(), values)); - UNIT_ASSERT(!range.empty()); + const int values[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + auto range = MakeIteratorRange(values, values + Y_ARRAY_SIZE(values)); + UNIT_ASSERT_VALUES_EQUAL(range.size(), Y_ARRAY_SIZE(values)); + UNIT_ASSERT(Equal(range.begin(), range.end(), values)); + UNIT_ASSERT(!range.empty()); } Y_UNIT_TEST(WorksSentinel) { @@ -89,10 +89,10 @@ Y_UNIT_TEST_SUITE(IteratorRange) { } Y_UNIT_TEST(CanUseInAlgorithms) { - const int values[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; - auto range = MakeIteratorRange(values, values + Y_ARRAY_SIZE(values)); - // more like compileability test - // we should be able to use TIteratorRange as a container parameter for standard algorithms - UNIT_ASSERT(AllOf(range, [](int x) { return x > 0; })); - } + const int values[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + auto range = MakeIteratorRange(values, values + Y_ARRAY_SIZE(values)); + // more like compileability test + // we should be able to use TIteratorRange as a container parameter for standard algorithms + UNIT_ASSERT(AllOf(range, [](int x) { return x > 0; })); + } } diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp index c2dcff23f6..c87d2e6374 100644 --- a/util/generic/ptr_ut.cpp +++ b/util/generic/ptr_ut.cpp @@ -708,7 +708,7 @@ void TPointerTest::TestMakeShared() { UNIT_ASSERT(state == OS_NOT_CREATED || state == OS_DESTROYED); } } - + template <class TPtr> void TestPtrComparison(const TPtr& ptr) { UNIT_ASSERT(ptr == ptr); @@ -719,15 +719,15 @@ void TestPtrComparison(const TPtr& ptr) { void TPointerTest::TestComparison() { THolder<A> ptr1(new A); - TAutoPtr<A> ptr2; - TSimpleSharedPtr<int> ptr3(new int(6)); - TIntrusivePtr<A> ptr4; + TAutoPtr<A> ptr2; + TSimpleSharedPtr<int> ptr3(new int(6)); + TIntrusivePtr<A> ptr4; TIntrusiveConstPtr<A> ptr5 = ptr4; - - UNIT_ASSERT(ptr1 != nullptr); - UNIT_ASSERT(ptr2 == nullptr); - UNIT_ASSERT(ptr3 != nullptr); - UNIT_ASSERT(ptr4 == nullptr); + + UNIT_ASSERT(ptr1 != nullptr); + UNIT_ASSERT(ptr2 == nullptr); + UNIT_ASSERT(ptr3 != nullptr); + UNIT_ASSERT(ptr4 == nullptr); UNIT_ASSERT(ptr5 == nullptr); TestPtrComparison(ptr1); @@ -735,7 +735,7 @@ void TPointerTest::TestComparison() { TestPtrComparison(ptr3); TestPtrComparison(ptr4); TestPtrComparison(ptr5); -} +} template <class T, class TRefCountedPtr> void TPointerTest::TestRefCountedPtrsInHashSetImpl() { diff --git a/util/generic/stack.h b/util/generic/stack.h index dbcbf2b5c9..048de43c9a 100644 --- a/util/generic/stack.h +++ b/util/generic/stack.h @@ -12,7 +12,7 @@ class TStack: public std::stack<T, S> { public: using TBase::TBase; - inline explicit operator bool() const noexcept { - return !this->empty(); - } + inline explicit operator bool() const noexcept { + return !this->empty(); + } }; diff --git a/util/generic/stack_ut.cpp b/util/generic/stack_ut.cpp index 248127d326..d60115caad 100644 --- a/util/generic/stack_ut.cpp +++ b/util/generic/stack_ut.cpp @@ -1,16 +1,16 @@ -#include "stack.h" - +#include "stack.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TYStackTest) { Y_UNIT_TEST(ExplicitBool) { TStack<int> s; - - UNIT_ASSERT(!s); + + UNIT_ASSERT(!s); UNIT_ASSERT(s.empty()); - s.push(100); - s.push(200); + s.push(100); + s.push(200); UNIT_ASSERT(s); - UNIT_ASSERT(!s.empty()); - } -} + UNIT_ASSERT(!s.empty()); + } +} diff --git a/util/generic/ut/ya.make b/util/generic/ut/ya.make index 6eaf24cc5f..c6bb8fe327 100644 --- a/util/generic/ut/ya.make +++ b/util/generic/ut/ya.make @@ -24,7 +24,7 @@ SRCS( generic/intrlist_ut.cpp generic/is_in_ut.cpp generic/iterator_ut.cpp - generic/iterator_range_ut.cpp + generic/iterator_range_ut.cpp generic/lazy_value_ut.cpp generic/list_ut.cpp generic/map_ut.cpp diff --git a/util/generic/vector.h b/util/generic/vector.h index a5b258955a..d6631a8c60 100644 --- a/util/generic/vector.h +++ b/util/generic/vector.h @@ -6,7 +6,7 @@ #include <util/memory/alloc.h> #include <vector> -#include <initializer_list> +#include <initializer_list> template <class T, class A> class TVector: public std::vector<T, TReboundAllocator<A, T>> { @@ -58,15 +58,15 @@ public: } inline TVector(std::initializer_list<T> il) - : TBase(il) - { - } - + : TBase(il) + { + } + inline TVector(std::initializer_list<T> il, const typename TBase::allocator_type& a) - : TBase(il, a) - { - } - + : TBase(il, a) + { + } + inline TVector(const TSelf& src) : TBase(src) { @@ -93,11 +93,11 @@ public: return *this; } - inline TSelf& operator=(std::initializer_list<T> il) { - this->assign(il.begin(), il.end()); - return *this; - } - + inline TSelf& operator=(std::initializer_list<T> il) { + this->assign(il.begin(), il.end()); + return *this; + } + inline explicit operator bool() const noexcept { return !this->empty(); } diff --git a/util/generic/vector_ut.cpp b/util/generic/vector_ut.cpp index 0f6b4037a0..d829831fb6 100644 --- a/util/generic/vector_ut.cpp +++ b/util/generic/vector_ut.cpp @@ -29,7 +29,7 @@ class TYVectorTest: public TTestBase { UNIT_TEST(TestFillInConstructor) UNIT_TEST(TestYResize) UNIT_TEST(TestCrop) - UNIT_TEST(TestInitializeList) + UNIT_TEST(TestInitializeList) UNIT_TEST_SUITE_END(); private: @@ -563,34 +563,34 @@ private: TestYResize<TPod>(); TestYResize<TNonPod>(); } - + void CheckInitializeList(const TVector<int>& v) { for (size_t i = 0; i < v.size(); ++i) { UNIT_ASSERT_EQUAL(v[i], static_cast<int>(i)); - } - } - - void TestInitializeList() { - { + } + } + + void TestInitializeList() { + { TVector<int> v; - v.assign({0, 1, 2}); - CheckInitializeList(v); - } - { + v.assign({0, 1, 2}); + CheckInitializeList(v); + } + { TVector<int> v = {0, 1, 2}; - CheckInitializeList(v); - } - { + CheckInitializeList(v); + } + { TVector<int> v; - v = {0, 1, 2}; - CheckInitializeList(v); - } - { + v = {0, 1, 2}; + CheckInitializeList(v); + } + { TVector<int> v = {0, 3}; - v.insert(v.begin() + 1, {1, 2}); - CheckInitializeList(v); - } - } + v.insert(v.begin() + 1, {1, 2}); + CheckInitializeList(v); + } + } }; UNIT_TEST_SUITE_REGISTRATION(TYVectorTest); diff --git a/util/memory/pool.h b/util/memory/pool.h index 13c8b6b9ed..58a5057b3c 100644 --- a/util/memory/pool.h +++ b/util/memory/pool.h @@ -8,7 +8,7 @@ #include <util/generic/utility.h> #include <util/generic/intrlist.h> #include <util/generic/strbuf.h> -#include <util/generic/singleton.h> +#include <util/generic/singleton.h> #include <new> #include <string> @@ -67,7 +67,7 @@ private: inline size_t Used() const noexcept { return Cur_ - (const char*)this; } - + inline size_t Left() const noexcept { return Left_; } @@ -146,7 +146,7 @@ public: inline ~TMemoryPool() { Clear(); } - + inline void* Allocate(size_t len) { return RawAllocate(AlignUp<size_t>(len, PLATFORM_DATA_ALIGN)); } @@ -231,7 +231,7 @@ public: *(ret + buf.size()) = 0; return TBasicStringBuf<TChar>(ret, buf.size()); } - + inline size_t Available() const noexcept { return Current_->Left(); } @@ -309,8 +309,8 @@ private: template <typename TPool> struct TPoolableBase { inline void* operator new(size_t bytes, TPool& pool) { - return pool.Allocate(bytes); - } + return pool.Allocate(bytes); + } inline void* operator new(size_t bytes, std::align_val_t align, TPool& pool) { return pool.Allocate(bytes, (size_t)align); @@ -324,8 +324,8 @@ struct TPoolableBase { private: inline void* operator new(size_t); // disallow default allocation -}; - +}; + struct TPoolable: public TPoolableBase<TMemoryPool> { }; diff --git a/util/memory/segmented_string_pool.h b/util/memory/segmented_string_pool.h index a40aa408f5..c02b28606b 100644 --- a/util/memory/segmented_string_pool.h +++ b/util/memory/segmented_string_pool.h @@ -1,6 +1,6 @@ #pragma once -#include <util/system/align.h> +#include <util/system/align.h> #include <util/system/yassert.h> #include <util/system/defaults.h> #include <util/generic/noncopyable.h> @@ -95,9 +95,9 @@ public: curseg->freepos += last_ins_size, last_free -= 1; return (T*)rv; } - size_t get_segment_size() const { - return segment_size; - } + size_t get_segment_size() const { + return segment_size; + } bool contains(const T* ptr) const { for (seg_const_iterator i = segs.begin(), ie = segs.end(); i != ie; ++i) if ((char*)ptr >= (char*)i->data && (char*)ptr < (char*)i->data + i->freepos) @@ -186,9 +186,9 @@ public: template <typename T, typename C> inline T* pool_push(segmented_pool<C>& pool, const T* v) { - static_assert(sizeof(C) == 1, "only char type supported"); + static_assert(sizeof(C) == 1, "only char type supported"); size_t len = SizeOf(v); - C* buf = pool.append(nullptr, AlignUp(len)); + C* buf = pool.append(nullptr, AlignUp(len)); memcpy(buf, v, len); return (T*)buf; } diff --git a/util/network/socket.cpp b/util/network/socket.cpp index 4f6e804346..1b7445d612 100644 --- a/util/network/socket.cpp +++ b/util/network/socket.cpp @@ -368,61 +368,61 @@ size_t GetMaximumTransferUnit(SOCKET /*s*/) { return 8192; } -int GetSocketToS(SOCKET s) { - TOpaqueAddr addr; - +int GetSocketToS(SOCKET s) { + TOpaqueAddr addr; + if (getsockname(s, addr.MutableAddr(), addr.LenPtr()) < 0) { ythrow TSystemError() << "getsockname() failed"; - } - - return GetSocketToS(s, &addr); -} - -int GetSocketToS(SOCKET s, const IRemoteAddr* addr) { - int result = 0; - - switch (addr->Addr()->sa_family) { + } + + return GetSocketToS(s, &addr); +} + +int GetSocketToS(SOCKET s, const IRemoteAddr* addr) { + int result = 0; + + switch (addr->Addr()->sa_family) { case AF_INET: CheckedGetSockOpt(s, IPPROTO_IP, IP_TOS, result, "tos"); break; - + case AF_INET6: -#ifdef IPV6_TCLASS +#ifdef IPV6_TCLASS CheckedGetSockOpt(s, IPPROTO_IPV6, IPV6_TCLASS, result, "tos"); -#endif +#endif break; - } - - return result; -} - -void SetSocketToS(SOCKET s, const NAddr::IRemoteAddr* addr, int tos) { - switch (addr->Addr()->sa_family) { + } + + return result; +} + +void SetSocketToS(SOCKET s, const NAddr::IRemoteAddr* addr, int tos) { + switch (addr->Addr()->sa_family) { case AF_INET: CheckedSetSockOpt(s, IPPROTO_IP, IP_TOS, tos, "tos"); return; - + case AF_INET6: -#ifdef IPV6_TCLASS +#ifdef IPV6_TCLASS CheckedSetSockOpt(s, IPPROTO_IPV6, IPV6_TCLASS, tos, "tos"); return; -#endif +#endif break; - } - - ythrow yexception() << "SetSocketToS unsupported for family " << addr->Addr()->sa_family; -} - -void SetSocketToS(SOCKET s, int tos) { - TOpaqueAddr addr; - + } + + ythrow yexception() << "SetSocketToS unsupported for family " << addr->Addr()->sa_family; +} + +void SetSocketToS(SOCKET s, int tos) { + TOpaqueAddr addr; + if (getsockname(s, addr.MutableAddr(), addr.LenPtr()) < 0) { ythrow TSystemError() << "getsockname() failed"; - } - - SetSocketToS(s, &addr, tos); -} - + } + + SetSocketToS(s, &addr, tos); +} + void SetSocketPriority(SOCKET s, int priority) { #if defined(SO_PRIORITY) CheckedSetSockOpt(s, SOL_SOCKET, SO_PRIORITY, priority, "priority"); diff --git a/util/network/socket.h b/util/network/socket.h index 40c8648b40..4c8e045e7b 100644 --- a/util/network/socket.h +++ b/util/network/socket.h @@ -92,10 +92,10 @@ static inline void FixIPv6ListenSocket(SOCKET s) { #endif } -namespace NAddr { - class IRemoteAddr; -} - +namespace NAddr { + class IRemoteAddr; +} + void SetSocketTimeout(SOCKET s, long timeout); void SetSocketTimeout(SOCKET s, long sec, long msec); void SetNoDelay(SOCKET s, bool value); @@ -112,10 +112,10 @@ bool GetRemoteAddr(SOCKET s, char* str, socklen_t size); size_t GetMaximumSegmentSize(SOCKET s); size_t GetMaximumTransferUnit(SOCKET s); void SetDeferAccept(SOCKET s); -void SetSocketToS(SOCKET s, int tos); -void SetSocketToS(SOCKET s, const NAddr::IRemoteAddr* addr, int tos); -int GetSocketToS(SOCKET s); -int GetSocketToS(SOCKET s, const NAddr::IRemoteAddr* addr); +void SetSocketToS(SOCKET s, int tos); +void SetSocketToS(SOCKET s, const NAddr::IRemoteAddr* addr, int tos); +int GetSocketToS(SOCKET s); +int GetSocketToS(SOCKET s, const NAddr::IRemoteAddr* addr); void SetSocketPriority(SOCKET s, int priority); void SetTcpFastOpen(SOCKET s, int qlen); /** diff --git a/util/string/ascii.h b/util/string/ascii.h index 10344384d3..f40482f679 100644 --- a/util/string/ascii.h +++ b/util/string/ascii.h @@ -212,8 +212,8 @@ static inline int AsciiCompareIgnoreCase(const char* s1, const char* s2) noexcep * similar to stricmp. */ Y_PURE_FUNCTION int AsciiCompareIgnoreCase(const TStringBuf s1, const TStringBuf s2) noexcept; - -/** + +/** * ASCII case-sensitive string comparison (for proper UTF8 strings * case-sensitive comparison consider using @c library/cpp/charset). * @@ -224,24 +224,24 @@ Y_PURE_FUNCTION int AsciiCompareIgnoreCase(const TStringBuf s1, const TStringBuf */ static inline bool AsciiHasPrefix(const TStringBuf s1, const TStringBuf s2) noexcept { return (s1.size() >= s2.size()) && memcmp(s1.data(), s2.data(), s2.size()) == 0; -} - -/** - * ASCII case-insensitive string comparison (for proper UTF8 strings +} + +/** + * ASCII case-insensitive string comparison (for proper UTF8 strings * case-insensitive comparison consider using @c library/cpp/charset). - * - * @return true iff @c s2 are case-insensitively prefix of @c s1. - */ + * + * @return true iff @c s2 are case-insensitively prefix of @c s1. + */ static inline bool AsciiHasPrefixIgnoreCase(const TStringBuf s1, const TStringBuf s2) noexcept { return (s1.size() >= s2.size()) && strnicmp(s1.data(), s2.data(), s2.size()) == 0; -} - -/** - * ASCII case-insensitive string comparison (for proper UTF8 strings +} + +/** + * ASCII case-insensitive string comparison (for proper UTF8 strings * case-insensitive comparison consider using @c library/cpp/charset). - * - * @return true iff @c s2 are case-insensitively suffix of @c s1. - */ + * + * @return true iff @c s2 are case-insensitively suffix of @c s1. + */ static inline bool AsciiHasSuffixIgnoreCase(const TStringBuf s1, const TStringBuf s2) noexcept { return (s1.size() >= s2.size()) && strnicmp((s1.data() + (s1.size() - s2.size())), s2.data(), s2.size()) == 0; -} +} diff --git a/util/string/ascii_ut.cpp b/util/string/ascii_ut.cpp index 89069fee50..b35dc835ad 100644 --- a/util/string/ascii_ut.cpp +++ b/util/string/ascii_ut.cpp @@ -84,15 +84,15 @@ Y_UNIT_TEST_SUITE(TAsciiTest) { UNIT_ASSERT(AsciiCompareIgnoreCase("qqQ", "qq") > 0); UNIT_ASSERT(AsciiCompareIgnoreCase("qq", "qq") == 0); - - UNIT_ASSERT_EQUAL(AsciiHasPrefix("qweasd", "qwe"), true); - UNIT_ASSERT_EQUAL(AsciiHasPrefix("qweasd", "qWe"), false); - UNIT_ASSERT_EQUAL(AsciiHasPrefix("qweasd", "eWq"), false); - - UNIT_ASSERT_EQUAL(AsciiHasPrefixIgnoreCase("qweasd", "qWe"), true); - UNIT_ASSERT_EQUAL(AsciiHasPrefixIgnoreCase("qweasd", "eWq"), false); - - UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "asD"), true); - UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "ast"), false); + + UNIT_ASSERT_EQUAL(AsciiHasPrefix("qweasd", "qwe"), true); + UNIT_ASSERT_EQUAL(AsciiHasPrefix("qweasd", "qWe"), false); + UNIT_ASSERT_EQUAL(AsciiHasPrefix("qweasd", "eWq"), false); + + UNIT_ASSERT_EQUAL(AsciiHasPrefixIgnoreCase("qweasd", "qWe"), true); + UNIT_ASSERT_EQUAL(AsciiHasPrefixIgnoreCase("qweasd", "eWq"), false); + + UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "asD"), true); + UNIT_ASSERT_EQUAL(AsciiHasSuffixIgnoreCase("qweasd", "ast"), false); } } diff --git a/util/string/printf_ut.cpp b/util/string/printf_ut.cpp index 2b2f980b70..d11129b6b0 100644 --- a/util/string/printf_ut.cpp +++ b/util/string/printf_ut.cpp @@ -21,10 +21,10 @@ Y_UNIT_TEST_SUITE(TStringPrintf) { } Y_UNIT_TEST(TestSpecial) { - UNIT_ASSERT_EQUAL("4294967295", Sprintf("%" PRIu32, (ui32)(-1))); + UNIT_ASSERT_EQUAL("4294967295", Sprintf("%" PRIu32, (ui32)(-1))); } - + Y_UNIT_TEST(TestExplicitPositions) { - UNIT_ASSERT_EQUAL("abc xyz abc", Sprintf("%1$s %2$s %1$s", "abc", "xyz")); - } + UNIT_ASSERT_EQUAL("abc xyz abc", Sprintf("%1$s %2$s %1$s", "abc", "xyz")); + } } diff --git a/util/system/hostname.cpp b/util/system/hostname.cpp index 386f646d6b..56a322a790 100644 --- a/util/system/hostname.cpp +++ b/util/system/hostname.cpp @@ -1,7 +1,7 @@ #include <util/memory/tempbuf.h> #include <util/generic/singleton.h> #include <util/generic/yexception.h> -#include <util/network/ip.h> +#include <util/network/ip.h> #if defined(_unix_) #include <unistd.h> @@ -31,24 +31,24 @@ namespace { TString HostName; }; - - struct TFQDNHostNameHolder { - inline TFQDNHostNameHolder() { - struct addrinfo hints; - struct addrinfo* ais{nullptr}; - char buf[1024]; - - memset(buf, 0, sizeof(buf)); - int res = gethostname(buf, sizeof(buf) - 1); - if (res) { - ythrow TSystemError() << "can not get hostname"; - } - - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_flags = AI_CANONNAME; - res = getaddrinfo(buf, nullptr, &hints, &ais); - if (res) { + + struct TFQDNHostNameHolder { + inline TFQDNHostNameHolder() { + struct addrinfo hints; + struct addrinfo* ais{nullptr}; + char buf[1024]; + + memset(buf, 0, sizeof(buf)); + int res = gethostname(buf, sizeof(buf) - 1); + if (res) { + ythrow TSystemError() << "can not get hostname"; + } + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_CANONNAME; + res = getaddrinfo(buf, nullptr, &hints, &ais); + if (res) { if (res != EAI_NONAME) { ythrow TSystemError() << "can not get FQDN (return code is " << res << ", hostname is \"" << buf << "\")"; } @@ -56,12 +56,12 @@ namespace { } else { FQDNHostName = ais->ai_canonname; freeaddrinfo(ais); - } - FQDNHostName.to_lower(); - } - + } + FQDNHostName.to_lower(); + } + TString FQDNHostName; - }; + }; } const TString& HostName() { @@ -71,26 +71,26 @@ const TString& HostName() { const char* GetHostName() { return HostName().data(); } - + const TString& FQDNHostName() { - return (Singleton<TFQDNHostNameHolder>())->FQDNHostName; -} - -const char* GetFQDNHostName() { + return (Singleton<TFQDNHostNameHolder>())->FQDNHostName; +} + +const char* GetFQDNHostName() { return FQDNHostName().data(); -} - +} + bool IsFQDN(const TString& name) { TString absName = name; if (!absName.EndsWith('.')) { - absName.append("."); - } - - try { - // ResolveHost() can't be used since it is ipv4-only, port is not important - TNetworkAddress addr(absName, 0); + absName.append("."); + } + + try { + // ResolveHost() can't be used since it is ipv4-only, port is not important + TNetworkAddress addr(absName, 0); } catch (const TNetworkResolutionError&) { - return false; - } - return true; -} + return false; + } + return true; +} diff --git a/util/system/hostname.h b/util/system/hostname.h index 0839ee2b59..e25e1d0c05 100644 --- a/util/system/hostname.h +++ b/util/system/hostname.h @@ -4,7 +4,7 @@ const char* GetHostName(); const TString& HostName(); - -const char* GetFQDNHostName(); + +const char* GetFQDNHostName(); const TString& FQDNHostName(); bool IsFQDN(const TString& name); diff --git a/util/system/hostname_ut.cpp b/util/system/hostname_ut.cpp index fb1cb7dde4..03eacb8aeb 100644 --- a/util/system/hostname_ut.cpp +++ b/util/system/hostname_ut.cpp @@ -6,11 +6,11 @@ Y_UNIT_TEST_SUITE(THostNameTest) { Y_UNIT_TEST(Test1) { UNIT_ASSERT(*GetHostName() != '?'); } - + Y_UNIT_TEST(TestFQDN) { UNIT_ASSERT(*GetFQDNHostName() != '?'); } - + Y_UNIT_TEST(TestIsFQDN) { const auto x = GetFQDNHostName(); diff --git a/util/system/spin_wait.cpp b/util/system/spin_wait.cpp index e27045e74f..88ce48d7b6 100644 --- a/util/system/spin_wait.cpp +++ b/util/system/spin_wait.cpp @@ -17,7 +17,7 @@ static inline T RandomizeSleepTime(T t) noexcept { //arbitrary values #define MIN_SLEEP_TIME 500 -#define MAX_SPIN_COUNT 0x7FF +#define MAX_SPIN_COUNT 0x7FF TSpinWait::TSpinWait() noexcept : T(MIN_SLEEP_TIME) diff --git a/util/thread/lfqueue.h b/util/thread/lfqueue.h index ab523631e4..451bff0743 100644 --- a/util/thread/lfqueue.h +++ b/util/thread/lfqueue.h @@ -2,7 +2,7 @@ #include "fwd.h" -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/system/atomic.h> #include <util/system/yassert.h> #include "lfstack.h" @@ -358,41 +358,41 @@ public: return res; } }; - + template <class T, class TCounter> -class TAutoLockFreeQueue { -public: +class TAutoLockFreeQueue { +public: using TRef = THolder<T>; - + inline ~TAutoLockFreeQueue() { - TRef tmp; - + TRef tmp; + while (Dequeue(&tmp)) { } - } - - inline bool Dequeue(TRef* t) { + } + + inline bool Dequeue(TRef* t) { T* res = nullptr; - - if (Queue.Dequeue(&res)) { - t->Reset(res); - - return true; - } - - return false; - } - - inline void Enqueue(TRef& t) { - Queue.Enqueue(t.Get()); + + if (Queue.Dequeue(&res)) { + t->Reset(res); + + return true; + } + + return false; + } + + inline void Enqueue(TRef& t) { + Queue.Enqueue(t.Get()); Y_UNUSED(t.Release()); - } - - inline void Enqueue(TRef&& t) { - Queue.Enqueue(t.Get()); + } + + inline void Enqueue(TRef&& t) { + Queue.Enqueue(t.Get()); Y_UNUSED(t.Release()); - } - + } + inline bool IsEmpty() { return Queue.IsEmpty(); } @@ -401,6 +401,6 @@ public: return Queue.GetCounter(); } -private: - TLockFreeQueue<T*, TCounter> Queue; -}; +private: + TLockFreeQueue<T*, TCounter> Queue; +}; diff --git a/util/ya.make b/util/ya.make index 6ebe7e40cf..58822f630f 100644 --- a/util/ya.make +++ b/util/ya.make @@ -106,7 +106,7 @@ JOIN_SRCS( generic/intrlist.cpp generic/is_in.cpp generic/iterator.cpp - generic/iterator_range.cpp + generic/iterator_range.cpp generic/lazy_value.cpp generic/list.cpp generic/map.cpp |