diff options
author | levysotsky <levysotsky@yandex-team.ru> | 2022-02-10 16:47:29 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:29 +0300 |
commit | 57f874ffc2a75047c1c4fea7a9fc86cb0f56ed50 (patch) | |
tree | ba6454f353979bb4bafaf230cafdf3e02ea120b2 /library/cpp | |
parent | 23d4769f0fea97cfb1028710e50f2b5ecd0ac2c0 (diff) | |
download | ydb-57f874ffc2a75047c1c4fea7a9fc86cb0f56ed50.tar.gz |
Restoring authorship annotation for <levysotsky@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp')
32 files changed, 554 insertions, 554 deletions
diff --git a/library/cpp/streams/brotli/brotli.cpp b/library/cpp/streams/brotli/brotli.cpp index 38052cb688..6e58341cbd 100644 --- a/library/cpp/streams/brotli/brotli.cpp +++ b/library/cpp/streams/brotli/brotli.cpp @@ -1,11 +1,11 @@ -#include "brotli.h" - +#include "brotli.h" + #include <contrib/libs/brotli/include/brotli/decode.h> #include <contrib/libs/brotli/include/brotli/encode.h> - + #include <util/generic/yexception.h> -#include <util/memory/addstorage.h> - +#include <util/memory/addstorage.h> + namespace { struct TAllocator { static void* Allocate(void* /* opaque */, size_t size) { @@ -19,27 +19,27 @@ namespace { } -class TBrotliCompress::TImpl { -public: +class TBrotliCompress::TImpl { +public: TImpl(IOutputStream* slave, int quality) - : Slave_(slave) + : Slave_(slave) , EncoderState_(BrotliEncoderCreateInstance(&TAllocator::Allocate, &TAllocator::Deallocate, nullptr)) - { + { if (!EncoderState_) { ythrow yexception() << "Brotli encoder initialization failed"; } - + auto res = BrotliEncoderSetParameter( EncoderState_, BROTLI_PARAM_QUALITY, quality); - + if (!res) { BrotliEncoderDestroyInstance(EncoderState_); ythrow yexception() << "Failed to set brotli encoder quality to " << quality; - } - } - + } + } + ~TImpl() { BrotliEncoderDestroyInstance(EncoderState_); } @@ -48,18 +48,18 @@ public: DoWrite(buffer, size, BROTLI_OPERATION_PROCESS); } - void Flush() { + void Flush() { DoWrite(nullptr, 0, BROTLI_OPERATION_FLUSH); - } - + } + void Finish() { Flush(); DoWrite(nullptr, 0, BROTLI_OPERATION_FINISH); Y_VERIFY(BrotliEncoderIsFinished(EncoderState_)); } -private: - IOutputStream* Slave_; +private: + IOutputStream* Slave_; BrotliEncoderState* EncoderState_; void DoWrite(const void* buffer, size_t size, BrotliEncoderOperation operation) { @@ -89,68 +89,68 @@ private: } } while (size > 0 || BrotliEncoderHasMoreOutput(EncoderState_)); } -}; - -TBrotliCompress::TBrotliCompress(IOutputStream* slave, int quality) { +}; + +TBrotliCompress::TBrotliCompress(IOutputStream* slave, int quality) { Impl_.Reset(new TImpl(slave, quality)); -} - -TBrotliCompress::~TBrotliCompress() { - try { - Finish(); - } catch (...) { - } -} - -void TBrotliCompress::DoWrite(const void* buffer, size_t size) { - Impl_->Write(buffer, size); -} - -void TBrotliCompress::DoFlush() { - if (Impl_) { - Impl_->Flush(); - } -} - -void TBrotliCompress::DoFinish() { - THolder<TImpl> impl(Impl_.Release()); - - if (impl) { +} + +TBrotliCompress::~TBrotliCompress() { + try { + Finish(); + } catch (...) { + } +} + +void TBrotliCompress::DoWrite(const void* buffer, size_t size) { + Impl_->Write(buffer, size); +} + +void TBrotliCompress::DoFlush() { + if (Impl_) { + Impl_->Flush(); + } +} + +void TBrotliCompress::DoFinish() { + THolder<TImpl> impl(Impl_.Release()); + + if (impl) { impl->Finish(); - } -} - -//////////////////////////////////////////////////////////////////////////////// - + } +} + +//////////////////////////////////////////////////////////////////////////////// + class TBrotliDecompress::TImpl: public TAdditionalStorage<TImpl> { -public: - TImpl(IInputStream* slave) - : Slave_(slave) - { +public: + TImpl(IInputStream* slave) + : Slave_(slave) + { InitDecoder(); - } - - ~TImpl() { + } + + ~TImpl() { FreeDecoder(); - } - - size_t Read(void* buffer, size_t size) { + } + + size_t Read(void* buffer, size_t size) { Y_ASSERT(size > 0); - + ui8* outBuffer = static_cast<ui8*>(buffer); - size_t availableOut = size; + size_t availableOut = size; size_t decompressedSize = 0; BrotliDecoderResult result; - do { + do { if (InputAvailable_ == 0 && !InputExhausted_) { - InputBuffer_ = TmpBuf(); + InputBuffer_ = TmpBuf(); InputAvailable_ = Slave_->Read((void*)InputBuffer_, TmpBufLen()); if (InputAvailable_ == 0) { InputExhausted_ = true; - } - } - + } + } + if (SubstreamFinished_ && !InputExhausted_) { ResetState(); } @@ -158,8 +158,8 @@ public: result = BrotliDecoderDecompressStream( DecoderState_, &InputAvailable_, - &InputBuffer_, - &availableOut, + &InputBuffer_, + &availableOut, &outBuffer, nullptr); @@ -173,33 +173,33 @@ public: } else if (result == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) { Y_VERIFY(availableOut != size, "Buffer passed to read in Brotli decoder is too small"); - break; - } + break; + } } while (decompressedSize == 0 && result == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT && !InputExhausted_); - + if (!SubstreamFinished_ && decompressedSize == 0) { ythrow yexception() << "Input stream is incomplete"; } return decompressedSize; - } - -private: - IInputStream* Slave_; + } + +private: + IInputStream* Slave_; BrotliDecoderState* DecoderState_; - + bool SubstreamFinished_ = false; bool InputExhausted_ = false; const ui8* InputBuffer_ = nullptr; size_t InputAvailable_ = 0; - - unsigned char* TmpBuf() noexcept { - return static_cast<unsigned char*>(AdditionalData()); - } - - size_t TmpBufLen() const noexcept { - return AdditionalDataLength(); - } + + unsigned char* TmpBuf() noexcept { + return static_cast<unsigned char*>(AdditionalData()); + } + + size_t TmpBufLen() const noexcept { + return AdditionalDataLength(); + } void InitDecoder() { DecoderState_ = BrotliDecoderCreateInstance(&TAllocator::Allocate, &TAllocator::Deallocate, nullptr); @@ -217,15 +217,15 @@ private: FreeDecoder(); InitDecoder(); } -}; - -TBrotliDecompress::TBrotliDecompress(IInputStream* slave, size_t bufferSize) +}; + +TBrotliDecompress::TBrotliDecompress(IInputStream* slave, size_t bufferSize) : Impl_(new (bufferSize) TImpl(slave)) -{ -} - -TBrotliDecompress::~TBrotliDecompress() = default; - -size_t TBrotliDecompress::DoRead(void* buffer, size_t size) { - return Impl_->Read(buffer, size); -} +{ +} + +TBrotliDecompress::~TBrotliDecompress() = default; + +size_t TBrotliDecompress::DoRead(void* buffer, size_t size) { + return Impl_->Read(buffer, size); +} diff --git a/library/cpp/streams/brotli/brotli.h b/library/cpp/streams/brotli/brotli.h index b3af869e29..b7e4034b86 100644 --- a/library/cpp/streams/brotli/brotli.h +++ b/library/cpp/streams/brotli/brotli.h @@ -1,52 +1,52 @@ -#pragma once - -#include <util/generic/ptr.h> -#include <util/stream/input.h> -#include <util/stream/output.h> - -/** - * @addtogroup Streams_Archs - * @{ - */ - +#pragma once + +#include <util/generic/ptr.h> +#include <util/stream/input.h> +#include <util/stream/output.h> + +/** + * @addtogroup Streams_Archs + * @{ + */ + class TBrotliCompress: public IOutputStream { -public: - static constexpr int BEST_QUALITY = 11; - - /** - @param slave stream to write compressed data to - @param quality the higher the quality, the slower and better the compression. Range is 0 to 11. - */ - explicit TBrotliCompress(IOutputStream* slave, int quality = BEST_QUALITY); - ~TBrotliCompress() override; - -private: - void DoWrite(const void* buffer, size_t size) override; - void DoFlush() override; - void DoFinish() override; - -public: - class TImpl; - THolder<TImpl> Impl_; -}; - -//////////////////////////////////////////////////////////////////////////////// - +public: + static constexpr int BEST_QUALITY = 11; + + /** + @param slave stream to write compressed data to + @param quality the higher the quality, the slower and better the compression. Range is 0 to 11. + */ + explicit TBrotliCompress(IOutputStream* slave, int quality = BEST_QUALITY); + ~TBrotliCompress() override; + +private: + void DoWrite(const void* buffer, size_t size) override; + void DoFlush() override; + void DoFinish() override; + +public: + class TImpl; + THolder<TImpl> Impl_; +}; + +//////////////////////////////////////////////////////////////////////////////// + class TBrotliDecompress: public IInputStream { -public: - /** - @param slave stream to read compressed data from - @param bufferSize approximate size of buffer compressed data is read in - */ - explicit TBrotliDecompress(IInputStream* slave, size_t bufferSize = 8 * 1024); - ~TBrotliDecompress() override; - -private: - size_t DoRead(void* buffer, size_t size) override; - -private: - class TImpl; - THolder<TImpl> Impl_; -}; - -/** @} */ +public: + /** + @param slave stream to read compressed data from + @param bufferSize approximate size of buffer compressed data is read in + */ + explicit TBrotliDecompress(IInputStream* slave, size_t bufferSize = 8 * 1024); + ~TBrotliDecompress() override; + +private: + size_t DoRead(void* buffer, size_t size) override; + +private: + class TImpl; + THolder<TImpl> Impl_; +}; + +/** @} */ diff --git a/library/cpp/streams/brotli/brotli_ut.cpp b/library/cpp/streams/brotli/brotli_ut.cpp index aeb2e284dc..2d07943226 100644 --- a/library/cpp/streams/brotli/brotli_ut.cpp +++ b/library/cpp/streams/brotli/brotli_ut.cpp @@ -1,9 +1,9 @@ -#include "brotli.h" - +#include "brotli.h" + #include <library/cpp/testing/unittest/registar.h> - -#include <util/random/fast.h> - + +#include <util/random/fast.h> + Y_UNIT_TEST_SUITE(TBrotliTestSuite) { TString Compress(TString data) { TString compressed; @@ -14,7 +14,7 @@ Y_UNIT_TEST_SUITE(TBrotliTestSuite) { output.Finish(); return compressed; } - + TString Decompress(TString data) { TStringInput input(data); TBrotliDecompress decompressStream(&input); @@ -27,20 +27,20 @@ Y_UNIT_TEST_SUITE(TBrotliTestSuite) { TString GenerateRandomString(size_t size) { TReallyFastRng32 rng(42); - TString result; - result.reserve(size + sizeof(ui64)); - while (result.size() < size) { - ui64 value = rng.GenRand64(); - result += TStringBuf(reinterpret_cast<const char*>(&value), sizeof(value)); - } - result.resize(size); - return result; - } - + TString result; + result.reserve(size + sizeof(ui64)); + while (result.size() < size) { + ui64 value = rng.GenRand64(); + result += TStringBuf(reinterpret_cast<const char*>(&value), sizeof(value)); + } + result.resize(size); + return result; + } + Y_UNIT_TEST(TestHelloWorld) { TestCase("hello world"); - } - + } + Y_UNIT_TEST(TestFlush) { TStringStream ss; TBrotliCompress compressStream(&ss); @@ -64,26 +64,26 @@ Y_UNIT_TEST_SUITE(TBrotliTestSuite) { auto c1 = Compress(s1); auto c2 = Compress(s2); UNIT_ASSERT_VALUES_EQUAL(s1 + s2, Decompress(c1 + c2)); - } - + } + Y_UNIT_TEST(TestIncompleteStream) { TString manyAs(64 * 1024, 'a'); auto compressed = Compress(manyAs); TString truncated(compressed.data(), compressed.size() - 1); UNIT_CHECK_GENERATED_EXCEPTION(Decompress(truncated), std::exception); - } - + } + Y_UNIT_TEST(Test64KB) { auto manyAs = TString(64 * 1024, 'a'); TString str("Hello from the Matrix!@#% How are you?}{\n\t\a"); TestCase(manyAs + str + manyAs); - } - + } + Y_UNIT_TEST(Test1MB) { TestCase(GenerateRandomString(1 * 1024 * 1024)); } Y_UNIT_TEST(TestEmpty) { TestCase(""); - } -} + } +} diff --git a/library/cpp/streams/brotli/ut/ya.make b/library/cpp/streams/brotli/ut/ya.make index 243462f1b2..70c207ba7e 100644 --- a/library/cpp/streams/brotli/ut/ya.make +++ b/library/cpp/streams/brotli/ut/ya.make @@ -1,12 +1,12 @@ UNITTEST_FOR(library/cpp/streams/brotli) - + OWNER( levysotsky g:util ) - -SRCS( - brotli_ut.cpp -) - -END() + +SRCS( + brotli_ut.cpp +) + +END() diff --git a/library/cpp/streams/brotli/ya.make b/library/cpp/streams/brotli/ya.make index fa2bfec9cc..108419e69e 100644 --- a/library/cpp/streams/brotli/ya.make +++ b/library/cpp/streams/brotli/ya.make @@ -1,17 +1,17 @@ -LIBRARY() - +LIBRARY() + OWNER( levysotsky g:util ) - -PEERDIR( - contrib/libs/brotli/enc - contrib/libs/brotli/dec -) - -SRCS( - brotli.cpp -) - -END() + +PEERDIR( + contrib/libs/brotli/enc + contrib/libs/brotli/dec +) + +SRCS( + brotli.cpp +) + +END() diff --git a/library/cpp/streams/ya.make b/library/cpp/streams/ya.make index 7426a874ee..474ecb051e 100644 --- a/library/cpp/streams/ya.make +++ b/library/cpp/streams/ya.make @@ -2,7 +2,7 @@ RECURSE( brotli brotli/ut base64 - brotli + brotli bzip2 bzip2/ut factory diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index 44517a0092..633be5ced9 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -363,12 +363,12 @@ public: \ #define UNIT_FAIL_IMPL(R, M) \ do { \ - ::NUnitTest::NPrivate::RaiseError(R, ::TStringBuilder() << R << " at " << __LOCATION__ << ", " << __PRETTY_FUNCTION__ << ": " << M, true); \ + ::NUnitTest::NPrivate::RaiseError(R, ::TStringBuilder() << R << " at " << __LOCATION__ << ", " << __PRETTY_FUNCTION__ << ": " << M, true); \ } while (false) #define UNIT_FAIL_NONFATAL_IMPL(R, M) \ do { \ - ::NUnitTest::NPrivate::RaiseError(R, ::TStringBuilder() << R << " at " << __LOCATION__ << ", " << __PRETTY_FUNCTION__ << ": " << M, false); \ + ::NUnitTest::NPrivate::RaiseError(R, ::TStringBuilder() << R << " at " << __LOCATION__ << ", " << __PRETTY_FUNCTION__ << ": " << M, false); \ } while (false) #define UNIT_FAIL(M) UNIT_FAIL_IMPL("forced failure", M) @@ -378,7 +378,7 @@ public: \ #define UNIT_ASSERT_TYPES_EQUAL(A, B) \ do { \ if (!std::is_same<A, B>::value) { \ - UNIT_FAIL_IMPL("types equal assertion failed", (::TStringBuilder() << #A << " (" << TypeName<A>() << ") != " << #B << " (" << TypeName<B>() << ")").data()); \ + UNIT_FAIL_IMPL("types equal assertion failed", (::TStringBuilder() << #A << " (" << TypeName<A>() << ") != " << #B << " (" << TypeName<B>() << ")").data()); \ } \ } while (false) @@ -391,7 +391,7 @@ public: \ const auto _es = ToString((long double)(E)); \ const auto _as = ToString((long double)(A)); \ const auto _ds = ToString((long double)(D)); \ - auto&& failMsg = Sprintf("std::abs(%s - %s) > %s %s", _es.data(), _as.data(), _ds.data(), (::TStringBuilder() << C).data()); \ + auto&& failMsg = Sprintf("std::abs(%s - %s) > %s %s", _es.data(), _as.data(), _ds.data(), (::TStringBuilder() << C).data()); \ UNIT_FAIL_IMPL("assertion failure", failMsg); \ } \ } while (false) @@ -405,19 +405,19 @@ public: \ const auto _dd = (D); \ if (std::isnan((long double)_ed) && !std::isnan((long double)_ad)) { \ const auto _as = ToString((long double)_ad); \ - auto&& failMsg = Sprintf("expected NaN, got %s %s", _as.data(), (::TStringBuilder() << C).data()); \ + auto&& failMsg = Sprintf("expected NaN, got %s %s", _as.data(), (::TStringBuilder() << C).data()); \ UNIT_FAIL_IMPL("assertion failure", failMsg); \ } \ if (!std::isnan((long double)_ed) && std::isnan((long double)_ad)) { \ const auto _es = ToString((long double)_ed); \ - auto&& failMsg = Sprintf("expected %s, got NaN %s", _es.data(), (::TStringBuilder() << C).data()); \ + auto&& failMsg = Sprintf("expected %s, got NaN %s", _es.data(), (::TStringBuilder() << C).data()); \ UNIT_FAIL_IMPL("assertion failure", failMsg); \ } \ if (std::abs((_ed) - (_ad)) > (_dd)) { \ const auto _es = ToString((long double)_ed); \ const auto _as = ToString((long double)_ad); \ const auto _ds = ToString((long double)_dd); \ - auto&& failMsg = Sprintf("std::abs(%s - %s) > %s %s", _es.data(), _as.data(), _ds.data(), (::TStringBuilder() << C).data()); \ + auto&& failMsg = Sprintf("std::abs(%s - %s) > %s %s", _es.data(), _as.data(), _ds.data(), (::TStringBuilder() << C).data()); \ UNIT_FAIL_IMPL("assertion failure", failMsg); \ } \ } while (false) @@ -430,7 +430,7 @@ public: \ const TString _a(A); \ const TString _b(B); \ if (_a != _b) { \ - auto&& failMsg = Sprintf("%s != %s %s", ToString(_a).data(), ToString(_b).data(), (::TStringBuilder() << C).data()); \ + auto&& failMsg = Sprintf("%s != %s %s", ToString(_a).data(), ToString(_b).data(), (::TStringBuilder() << C).data()); \ UNIT_FAIL_IMPL("strings equal assertion failed", failMsg); \ } \ } while (false) @@ -442,7 +442,7 @@ public: \ const TString _a(A); \ const TString _b(B); \ if (!_a.Contains(_b)) { \ - auto&& msg = Sprintf("\"%s\" does not contain \"%s\", %s", ToString(_a).data(), ToString(_b).data(), (::TStringBuilder() << C).data()); \ + auto&& msg = Sprintf("\"%s\" does not contain \"%s\", %s", ToString(_a).data(), ToString(_b).data(), (::TStringBuilder() << C).data()); \ UNIT_FAIL_IMPL("strings contains assertion failed", msg); \ } \ } while (false) @@ -464,7 +464,7 @@ public: \ const TString _a(A); \ const TString _b(B); \ if (_a == _b) { \ - auto&& msg = Sprintf("%s == %s %s", ToString(_a).data(), ToString(_b).data(), (::TStringBuilder() << C).data()); \ + auto&& msg = Sprintf("%s == %s %s", ToString(_a).data(), ToString(_b).data(), (::TStringBuilder() << C).data()); \ UNIT_FAIL_IMPL("strings unequal assertion failed", msg); \ } \ } while (false) @@ -475,7 +475,7 @@ public: \ #define UNIT_ASSERT_C(A, C) \ do { \ if (!(A)) { \ - UNIT_FAIL_IMPL("assertion failed", Sprintf("(%s) %s", #A, (::TStringBuilder() << C).data())); \ + UNIT_FAIL_IMPL("assertion failed", Sprintf("(%s) %s", #A, (::TStringBuilder() << C).data())); \ } \ } while (false) @@ -485,7 +485,7 @@ public: \ #define UNIT_ASSERT_EQUAL_C(A, B, C) \ do { \ if (!((A) == (B))) { \ - UNIT_FAIL_IMPL("equal assertion failed", Sprintf("%s == %s %s", #A, #B, (::TStringBuilder() << C).data())); \ + UNIT_FAIL_IMPL("equal assertion failed", Sprintf("%s == %s %s", #A, #B, (::TStringBuilder() << C).data())); \ } \ } while (false) @@ -494,7 +494,7 @@ public: \ #define UNIT_ASSERT_UNEQUAL_C(A, B, C) \ do { \ if ((A) == (B)) { \ - UNIT_FAIL_IMPL("unequal assertion failed", Sprintf("%s != %s %s", #A, #B, (::TStringBuilder() << C).data()));\ + UNIT_FAIL_IMPL("unequal assertion failed", Sprintf("%s != %s %s", #A, #B, (::TStringBuilder() << C).data()));\ } \ } while (false) @@ -503,7 +503,7 @@ public: \ #define UNIT_ASSERT_LT_C(A, B, C) \ do { \ if (!((A) < (B))) { \ - UNIT_FAIL_IMPL("less-than assertion failed", Sprintf("%s < %s %s", #A, #B, (::TStringBuilder() << C).data())); \ + UNIT_FAIL_IMPL("less-than assertion failed", Sprintf("%s < %s %s", #A, #B, (::TStringBuilder() << C).data())); \ } \ } while (false) @@ -512,7 +512,7 @@ public: \ #define UNIT_ASSERT_LE_C(A, B, C) \ do { \ if (!((A) <= (B))) { \ - UNIT_FAIL_IMPL("less-or-equal assertion failed", Sprintf("%s <= %s %s", #A, #B, (::TStringBuilder() << C).data())); \ + UNIT_FAIL_IMPL("less-or-equal assertion failed", Sprintf("%s <= %s %s", #A, #B, (::TStringBuilder() << C).data())); \ } \ } while (false) @@ -521,7 +521,7 @@ public: \ #define UNIT_ASSERT_GT_C(A, B, C) \ do { \ if (!((A) > (B))) { \ - UNIT_FAIL_IMPL("greater-than assertion failed", Sprintf("%s > %s %s", #A, #B, (::TStringBuilder() << C).data())); \ + UNIT_FAIL_IMPL("greater-than assertion failed", Sprintf("%s > %s %s", #A, #B, (::TStringBuilder() << C).data())); \ } \ } while (false) @@ -530,7 +530,7 @@ public: \ #define UNIT_ASSERT_GE_C(A, B, C) \ do { \ if (!((A) >= (B))) { \ - UNIT_FAIL_IMPL("greater-or-equal assertion failed", Sprintf("%s >= %s %s", #A, #B, (::TStringBuilder() << C).data())); \ + UNIT_FAIL_IMPL("greater-or-equal assertion failed", Sprintf("%s >= %s %s", #A, #B, (::TStringBuilder() << C).data())); \ } \ } while (false) @@ -651,7 +651,7 @@ public: \ } catch (const ::NUnitTest::TAssertException&) { \ throw; \ } catch (...) { \ - UNIT_FAIL_IMPL("exception-free assertion failed", Sprintf("%s throws %s\nException message: %s", #A, (::TStringBuilder() << C).data(), CurrentExceptionMessage().data())); \ + UNIT_FAIL_IMPL("exception-free assertion failed", Sprintf("%s throws %s\nException message: %s", #A, (::TStringBuilder() << C).data(), CurrentExceptionMessage().data())); \ } \ } while (false) @@ -712,7 +712,7 @@ public: \ TString _bsInd; \ bool _usePlainDiff; \ if (!::NUnitTest::NPrivate::CompareAndMakeStrings(A, B, _as, _asInd, _bs, _bsInd, _usePlainDiff, EQflag)) { \ - auto&& failMsg = Sprintf("(%s %s %s) failed: (%s %s %s) %s", #A, EQstr, #B, _as.data(), NEQstr, _bs.data(), (::TStringBuilder() << C).data()); \ + auto&& failMsg = Sprintf("(%s %s %s) failed: (%s %s %s) %s", #A, EQstr, #B, _as.data(), NEQstr, _bs.data(), (::TStringBuilder() << C).data()); \ if (EQflag && !_usePlainDiff) { \ failMsg += ", with diff:\n"; \ failMsg += ::NUnitTest::ColoredDiff(_asInd, _bsInd); \ diff --git a/library/cpp/ya.make b/library/cpp/ya.make index 8c1193b007..36aec001ef 100644 --- a/library/cpp/ya.make +++ b/library/cpp/ya.make @@ -331,7 +331,7 @@ RECURSE( sighandler simhash simhash/ut - skiff + skiff sliding_window sliding_window/ut solve_ambig diff --git a/library/cpp/yson/detail.h b/library/cpp/yson/detail.h index 27f5e8ffff..1b0bd4c449 100644 --- a/library/cpp/yson/detail.h +++ b/library/cpp/yson/detail.h @@ -453,7 +453,7 @@ namespace NYson { default: ythrow TYsonException() << "Incorrect %-literal prefix: '" << ch << "'"; } - + for (size_t i = 0; i < expectedString.size(); ++i) { if (expectedString[i] != ch) { ythrow TYsonException() @@ -464,10 +464,10 @@ namespace NYson { TBaseStream::Advance(1); ch = TBaseStream::template GetChar<AllowFinish>(); } - + return expectedValue; - } - + } + void ReadQuotedString(TStringBuf* value) { Buffer_.clear(); while (true) { @@ -494,14 +494,14 @@ namespace NYson { } CheckMemoryLimit(); } - + auto unquotedValue = UnescapeC(Buffer_.data(), Buffer_.size()); Buffer_.clear(); Buffer_.insert(Buffer_.end(), unquotedValue.data(), unquotedValue.data() + unquotedValue.size()); CheckMemoryLimit(); *value = TStringBuf(Buffer_.data(), Buffer_.size()); } - + template <bool AllowFinish> void ReadUnquotedString(TStringBuf* value) { Buffer_.clear(); diff --git a/library/cpp/yson/lexer_detail.h b/library/cpp/yson/lexer_detail.h index 0bba30acdd..c3d1d53fdb 100644 --- a/library/cpp/yson/lexer_detail.h +++ b/library/cpp/yson/lexer_detail.h @@ -230,7 +230,7 @@ namespace NYson { TStringBuf value; TBase::ReadBinaryString(&value); *token = TToken(value); - } + } } } diff --git a/library/cpp/yson/node/node.cpp b/library/cpp/yson/node/node.cpp index b39e070718..db507c2bb8 100644 --- a/library/cpp/yson/node/node.cpp +++ b/library/cpp/yson/node/node.cpp @@ -148,10 +148,10 @@ TNode::TNode(bool b) : Value_(b) { } -TNode::TNode(TMapType map) +TNode::TNode(TMapType map) : Value_(std::move(map)) -{ } - +{ } + TNode::TNode(const TNode& rhs) : TNode() { @@ -259,7 +259,7 @@ bool TNode::Empty() const case Map: return std::get<TMapType>(Value_).empty(); default: - ythrow TTypeError() << "Empty() called for type " << GetType(); + ythrow TTypeError() << "Empty() called for type " << GetType(); } } @@ -273,7 +273,7 @@ size_t TNode::Size() const case Map: return std::get<TMapType>(Value_).size(); default: - ythrow TTypeError() << "Size() called for type " << GetType(); + ythrow TTypeError() << "Size() called for type " << GetType(); } } @@ -822,7 +822,7 @@ void TNode::Move(TNode&& rhs) void TNode::CheckType(EType type) const { Y_ENSURE_EX(GetType() == type, - TTypeError() << "TNode type " << type << " expected, actual type " << GetType(); + TTypeError() << "TNode type " << type << " expected, actual type " << GetType(); ); } diff --git a/library/cpp/yson/node/node.h b/library/cpp/yson/node/node.h index 5f90f95df0..bbf36144f6 100644 --- a/library/cpp/yson/node/node.h +++ b/library/cpp/yson/node/node.h @@ -101,7 +101,7 @@ public: TNode(unsigned long long ui); TNode(double d); TNode(bool b); - TNode(TMapType map); + TNode(TMapType map); TNode(const TNode& rhs); TNode& operator=(const TNode& rhs); @@ -358,7 +358,7 @@ inline TString TNode::ConvertTo<TString>() const { case NYT::TNode::Map: case NYT::TNode::Null: case NYT::TNode::Undefined: - ythrow TTypeError() << "ConvertTo<TString>() called for type " << GetType(); + ythrow TTypeError() << "ConvertTo<TString>() called for type " << GetType(); } Y_UNREACHABLE(); } @@ -380,7 +380,7 @@ inline double TNode::ConvertTo<double>() const { case NYT::TNode::Map: case NYT::TNode::Null: case NYT::TNode::Undefined: - ythrow TTypeError() << "ConvertTo<double>() called for type " << GetType(); + ythrow TTypeError() << "ConvertTo<double>() called for type " << GetType(); } } @@ -401,7 +401,7 @@ inline bool TNode::ConvertTo<bool>() const { case NYT::TNode::Map: case NYT::TNode::Null: case NYT::TNode::Undefined: - ythrow TTypeError() << "ConvertTo<bool>() called for type " << GetType(); + ythrow TTypeError() << "ConvertTo<bool>() called for type " << GetType(); } } diff --git a/library/cpp/yson/node/node_io.cpp b/library/cpp/yson/node/node_io.cpp index 294a7f7217..e7eb6555ef 100644 --- a/library/cpp/yson/node/node_io.cpp +++ b/library/cpp/yson/node/node_io.cpp @@ -96,12 +96,12 @@ TString NodeToYsonString(const TNode& node, NYson::EYsonFormat format) } TString NodeToCanonicalYsonString(const TNode& node, NYson::EYsonFormat format) -{ - TStringStream stream; - NodeToCanonicalYsonStream(node, &stream, format); - return stream.Str(); -} - +{ + TStringStream stream; + NodeToCanonicalYsonStream(node, &stream, format); + return stream.Str(); +} + TNode NodeFromYsonStream(IInputStream* input, ::NYson::EYsonType type) { TNode result = CreateEmptyNodeByType(type); @@ -120,12 +120,12 @@ void NodeToYsonStream(const TNode& node, IOutputStream* output, NYson::EYsonForm } void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, NYson::EYsonFormat format) -{ +{ ::NYson::TYsonWriter writer(output, format); - TNodeVisitor visitor(&writer, /*sortMapKeys*/ true); - visitor.Visit(node); -} - + TNodeVisitor visitor(&writer, /*sortMapKeys*/ true); + visitor.Visit(node); +} + TNode NodeFromJsonString(const TStringBuf input) { TMemoryInput stream(input); diff --git a/library/cpp/yson/node/node_io.h b/library/cpp/yson/node/node_io.h index 2ad23b658f..cdab595044 100644 --- a/library/cpp/yson/node/node_io.h +++ b/library/cpp/yson/node/node_io.h @@ -11,28 +11,28 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// -// Parse TNode from string in YSON format +// Parse TNode from string in YSON format TNode NodeFromYsonString(const TStringBuf input, ::NYson::EYsonType type = ::NYson::EYsonType::Node); - -// Serialize TNode to string in one of YSON formats with random order of maps' keys (don't use in tests) + +// Serialize TNode to string in one of YSON formats with random order of maps' keys (don't use in tests) TString NodeToYsonString(const TNode& node, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); -// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests) +// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests) TString NodeToCanonicalYsonString(const TNode& node, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); - -// Parse TNode from stream in YSON format + +// Parse TNode from stream in YSON format TNode NodeFromYsonStream(IInputStream* input, ::NYson::EYsonType type = ::NYson::EYsonType::Node); - -// Serialize TNode to stream in one of YSON formats with random order of maps' keys (don't use in tests) + +// Serialize TNode to stream in one of YSON formats with random order of maps' keys (don't use in tests) void NodeToYsonStream(const TNode& node, IOutputStream* output, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); -// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests) +// Same as the latter, but maps' keys are sorted lexicographically (to be used in tests) void NodeToCanonicalYsonStream(const TNode& node, IOutputStream* output, ::NYson::EYsonFormat format = ::NYson::EYsonFormat::Text); - -// Parse TNode from string in JSON format + +// Parse TNode from string in JSON format TNode NodeFromJsonString(const TStringBuf input); - -// Convert TJsonValue to TNode + +// Convert TJsonValue to TNode TNode NodeFromJsonValue(const NJson::TJsonValue& input); //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yson/node/node_ut.cpp b/library/cpp/yson/node/node_ut.cpp index 448e99f575..0235364c39 100644 --- a/library/cpp/yson/node/node_ut.cpp +++ b/library/cpp/yson/node/node_ut.cpp @@ -382,19 +382,19 @@ Y_UNIT_TEST_SUITE(YtNodeTest) { UNIT_ASSERT_EXCEPTION(TNode("random").ConvertTo<bool>(), TFromStringException); UNIT_ASSERT_EXCEPTION(TNode("").ConvertTo<bool>(), TFromStringException); } - + Y_UNIT_TEST(TestCanonicalSerialization) { - auto node = TNode() - ("ca", "ca")("c", "c")("a", "a")("b", "b") - ("bb", TNode() - ("ii", "ii")("i", "i")("jj", "jj")); - node.Attributes() = TNode()("za", "za")("z", "z")("xxx", "xxx")("xx", "xx"); - UNIT_ASSERT_VALUES_EQUAL(NodeToCanonicalYsonString(node), - "<\"xx\"=\"xx\";\"xxx\"=\"xxx\";\"z\"=\"z\";\"za\"=\"za\">" - "{\"a\"=\"a\";\"b\"=\"b\";\"bb\"=" - "{\"i\"=\"i\";\"ii\"=\"ii\";\"jj\"=\"jj\"};" - "\"c\"=\"c\";\"ca\"=\"ca\"}"); - } + auto node = TNode() + ("ca", "ca")("c", "c")("a", "a")("b", "b") + ("bb", TNode() + ("ii", "ii")("i", "i")("jj", "jj")); + node.Attributes() = TNode()("za", "za")("z", "z")("xxx", "xxx")("xx", "xx"); + UNIT_ASSERT_VALUES_EQUAL(NodeToCanonicalYsonString(node), + "<\"xx\"=\"xx\";\"xxx\"=\"xxx\";\"z\"=\"z\";\"za\"=\"za\">" + "{\"a\"=\"a\";\"b\"=\"b\";\"bb\"=" + "{\"i\"=\"i\";\"ii\"=\"ii\";\"jj\"=\"jj\"};" + "\"c\"=\"c\";\"ca\"=\"ca\"}"); + } Y_UNIT_TEST(OperatorEqualSubnode) { TNode node; diff --git a/library/cpp/yson/node/node_visitor.cpp b/library/cpp/yson/node/node_visitor.cpp index 899fbfa02a..98b7c949d8 100644 --- a/library/cpp/yson/node/node_visitor.cpp +++ b/library/cpp/yson/node/node_visitor.cpp @@ -1,38 +1,38 @@ #include "node_visitor.h" -#include <util/generic/algorithm.h> +#include <util/generic/algorithm.h> #include <util/string/printf.h> namespace NYT { //////////////////////////////////////////////////////////////////////////////// -namespace { - -template <typename Fun> -void Iterate(const TNode::TMapType& nodeMap, bool sortByKey, Fun action) -{ - if (sortByKey) { - TVector<TNode::TMapType::const_iterator> iterators; - for (auto it = nodeMap.begin(); it != nodeMap.end(); ++it) { - iterators.push_back(it); - } - SortBy(iterators, [](TNode::TMapType::const_iterator it) { return it->first; }); - for (const auto& it : iterators) { - action(*it); - } - } else { - ForEach(nodeMap.begin(), nodeMap.end(), action); - } -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// - +namespace { + +template <typename Fun> +void Iterate(const TNode::TMapType& nodeMap, bool sortByKey, Fun action) +{ + if (sortByKey) { + TVector<TNode::TMapType::const_iterator> iterators; + for (auto it = nodeMap.begin(); it != nodeMap.end(); ++it) { + iterators.push_back(it); + } + SortBy(iterators, [](TNode::TMapType::const_iterator it) { return it->first; }); + for (const auto& it : iterators) { + action(*it); + } + } else { + ForEach(nodeMap.begin(), nodeMap.end(), action); + } +} + +} // namespace + +//////////////////////////////////////////////////////////////////////////////// + TNodeVisitor::TNodeVisitor(NYson::IYsonConsumer* consumer, bool sortMapKeys) : Consumer_(consumer) - , SortMapKeys_(sortMapKeys) + , SortMapKeys_(sortMapKeys) { } void TNodeVisitor::Visit(const TNode& node) @@ -44,14 +44,14 @@ void TNodeVisitor::VisitAny(const TNode& node) { if (node.HasAttributes()) { Consumer_->OnBeginAttributes(); - Iterate(node.GetAttributes().AsMap(), SortMapKeys_, [&](const std::pair<TString, TNode>& item) { + Iterate(node.GetAttributes().AsMap(), SortMapKeys_, [&](const std::pair<TString, TNode>& item) { Consumer_->OnKeyedItem(item.first); if (item.second.IsUndefined()) { - ythrow TNode::TTypeError() << "unable to visit attribute value of type " - << TNode::EType::Undefined << "; attribute name: `" << item.first << '\'' ; + ythrow TNode::TTypeError() << "unable to visit attribute value of type " + << TNode::EType::Undefined << "; attribute name: `" << item.first << '\'' ; } VisitAny(item.second); - }); + }); Consumer_->OnEndAttributes(); } @@ -81,7 +81,7 @@ void TNodeVisitor::VisitAny(const TNode& node) VisitEntity(); break; case TNode::Undefined: - ythrow TNode::TTypeError() << "unable to visit TNode of type " << node.GetType(); + ythrow TNode::TTypeError() << "unable to visit TNode of type " << node.GetType(); default: Y_FAIL("Unexpected type: %d", node.GetType()); } @@ -119,8 +119,8 @@ void TNodeVisitor::VisitList(const TNode::TListType& nodeList) for (const auto& item : nodeList) { Consumer_->OnListItem(); if (item.IsUndefined()) { - ythrow TNode::TTypeError() << "unable to visit list node child of type " - << TNode::EType::Undefined << "; list index: " << index; + ythrow TNode::TTypeError() << "unable to visit list node child of type " + << TNode::EType::Undefined << "; list index: " << index; } VisitAny(item); ++index; @@ -131,14 +131,14 @@ void TNodeVisitor::VisitList(const TNode::TListType& nodeList) void TNodeVisitor::VisitMap(const TNode::TMapType& nodeMap) { Consumer_->OnBeginMap(); - Iterate(nodeMap, SortMapKeys_, [&](const std::pair<TString, TNode>& item) { + Iterate(nodeMap, SortMapKeys_, [&](const std::pair<TString, TNode>& item) { Consumer_->OnKeyedItem(item.first); if (item.second.IsUndefined()) { - ythrow TNode::TTypeError() << "unable to visit map node child of type " - << TNode::EType::Undefined << "; map key: `" << item.first << '\'' ; + ythrow TNode::TTypeError() << "unable to visit map node child of type " + << TNode::EType::Undefined << "; map key: `" << item.first << '\'' ; } VisitAny(item.second); - }); + }); Consumer_->OnEndMap(); } diff --git a/library/cpp/yson/node/node_visitor.h b/library/cpp/yson/node/node_visitor.h index db25832309..6dd4b8a5b4 100644 --- a/library/cpp/yson/node/node_visitor.h +++ b/library/cpp/yson/node/node_visitor.h @@ -19,7 +19,7 @@ public: private: NYson::IYsonConsumer* Consumer_; - bool SortMapKeys_; + bool SortMapKeys_; private: void VisitAny(const TNode& node); diff --git a/library/cpp/yson/node/serialize.cpp b/library/cpp/yson/node/serialize.cpp index aeb467622b..f65c599186 100644 --- a/library/cpp/yson/node/serialize.cpp +++ b/library/cpp/yson/node/serialize.cpp @@ -1,101 +1,101 @@ -#include "serialize.h" - +#include "serialize.h" + #include "node_visitor.h" - + #include <library/cpp/yson/consumer.h> - -namespace NYT { - -//////////////////////////////////////////////////////////////////////////////// - + +namespace NYT { + +//////////////////////////////////////////////////////////////////////////////// + void Serialize(const TString& value, NYson::IYsonConsumer* consumer) -{ - consumer->OnStringScalar(value); -} - +{ + consumer->OnStringScalar(value); +} + void Serialize(const TStringBuf& value, NYson::IYsonConsumer* consumer) -{ - consumer->OnStringScalar(value); -} - +{ + consumer->OnStringScalar(value); +} + void Serialize(const char* value, NYson::IYsonConsumer* consumer) -{ - consumer->OnStringScalar(value); -} - -void Deserialize(TString& value, const TNode& node) -{ - value = node.AsString(); -} - -#define SERIALIZE_SIGNED(type) \ +{ + consumer->OnStringScalar(value); +} + +void Deserialize(TString& value, const TNode& node) +{ + value = node.AsString(); +} + +#define SERIALIZE_SIGNED(type) \ void Serialize(type value, NYson::IYsonConsumer* consumer) \ -{ \ - consumer->OnInt64Scalar(static_cast<i64>(value)); \ -} - -#define SERIALIZE_UNSIGNED(type) \ +{ \ + consumer->OnInt64Scalar(static_cast<i64>(value)); \ +} + +#define SERIALIZE_UNSIGNED(type) \ void Serialize(type value, NYson::IYsonConsumer* consumer) \ -{ \ - consumer->OnUint64Scalar(static_cast<ui64>(value)); \ -} - -SERIALIZE_SIGNED(signed char); -SERIALIZE_SIGNED(short); -SERIALIZE_SIGNED(int); -SERIALIZE_SIGNED(long); -SERIALIZE_SIGNED(long long); - -SERIALIZE_UNSIGNED(unsigned char); -SERIALIZE_UNSIGNED(unsigned short); -SERIALIZE_UNSIGNED(unsigned int); -SERIALIZE_UNSIGNED(unsigned long); -SERIALIZE_UNSIGNED(unsigned long long); - -#undef SERIALIZE_SIGNED -#undef SERIALIZE_UNSIGNED - -void Deserialize(i64& value, const TNode& node) -{ - value = node.AsInt64(); -} - -void Deserialize(ui64& value, const TNode& node) -{ - value = node.AsUint64(); -} - +{ \ + consumer->OnUint64Scalar(static_cast<ui64>(value)); \ +} + +SERIALIZE_SIGNED(signed char); +SERIALIZE_SIGNED(short); +SERIALIZE_SIGNED(int); +SERIALIZE_SIGNED(long); +SERIALIZE_SIGNED(long long); + +SERIALIZE_UNSIGNED(unsigned char); +SERIALIZE_UNSIGNED(unsigned short); +SERIALIZE_UNSIGNED(unsigned int); +SERIALIZE_UNSIGNED(unsigned long); +SERIALIZE_UNSIGNED(unsigned long long); + +#undef SERIALIZE_SIGNED +#undef SERIALIZE_UNSIGNED + +void Deserialize(i64& value, const TNode& node) +{ + value = node.AsInt64(); +} + +void Deserialize(ui64& value, const TNode& node) +{ + value = node.AsUint64(); +} + void Serialize(double value, NYson::IYsonConsumer* consumer) -{ - consumer->OnDoubleScalar(value); -} - -void Deserialize(double& value, const TNode& node) -{ - value = node.AsDouble(); -} - +{ + consumer->OnDoubleScalar(value); +} + +void Deserialize(double& value, const TNode& node) +{ + value = node.AsDouble(); +} + void Serialize(bool value, NYson::IYsonConsumer* consumer) -{ - consumer->OnBooleanScalar(value); -} - -void Deserialize(bool& value, const TNode& node) -{ - value = node.AsBool(); -} - +{ + consumer->OnBooleanScalar(value); +} + +void Deserialize(bool& value, const TNode& node) +{ + value = node.AsBool(); +} + void Serialize(const TNode& node, NYson::IYsonConsumer* consumer) -{ - TNodeVisitor visitor(consumer); - visitor.Visit(node); -} - -void Deserialize(TNode& value, const TNode& node) -{ - value = node; -} - -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT +{ + TNodeVisitor visitor(consumer); + visitor.Visit(node); +} + +void Deserialize(TNode& value, const TNode& node) +{ + value = node; +} + +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT diff --git a/library/cpp/yson/node/serialize.h b/library/cpp/yson/node/serialize.h index 99b598a44c..5fc72a0482 100644 --- a/library/cpp/yson/node/serialize.h +++ b/library/cpp/yson/node/serialize.h @@ -1,45 +1,45 @@ -#pragma once - -#include "node.h" - +#pragma once + +#include "node.h" + namespace NYT { namespace NYson { struct IYsonConsumer; } // namespace NYson -//////////////////////////////////////////////////////////////////////////////// - +//////////////////////////////////////////////////////////////////////////////// + void Serialize(const TString& value, NYson::IYsonConsumer* consumer); void Serialize(const TStringBuf& value, NYson::IYsonConsumer* consumer); void Serialize(const char* value, NYson::IYsonConsumer* consumer); -void Deserialize(TString& value, const TNode& node); - +void Deserialize(TString& value, const TNode& node); + void Serialize(signed char value, NYson::IYsonConsumer* consumer); void Serialize(short value, NYson::IYsonConsumer* consumer); void Serialize(int value, NYson::IYsonConsumer* consumer); void Serialize(long value, NYson::IYsonConsumer* consumer); void Serialize(long long value, NYson::IYsonConsumer* consumer); -void Deserialize(i64& value, const TNode& node); - +void Deserialize(i64& value, const TNode& node); + void Serialize(unsigned char value, NYson::IYsonConsumer* consumer); void Serialize(unsigned short value, NYson::IYsonConsumer* consumer); void Serialize(unsigned int value, NYson::IYsonConsumer* consumer); void Serialize(unsigned long value, NYson::IYsonConsumer* consumer); void Serialize(unsigned long long value, NYson::IYsonConsumer* consumer); -void Deserialize(ui64& value, const TNode& node); - +void Deserialize(ui64& value, const TNode& node); + void Serialize(double value, NYson::IYsonConsumer* consumer); -void Deserialize(double& value, const TNode& node); - +void Deserialize(double& value, const TNode& node); + void Serialize(bool value, NYson::IYsonConsumer* consumer); -void Deserialize(bool& value, const TNode& node); - +void Deserialize(bool& value, const TNode& node); + void Serialize(const TNode& node, NYson::IYsonConsumer* consumer); -void Deserialize(TNode& value, const TNode& node); - +void Deserialize(TNode& value, const TNode& node); + void Serialize(const THashMap<TString, TString>& renameColumns, NYson::IYsonConsumer* consumer); -//////////////////////////////////////////////////////////////////////////////// - -} // namespace NYT +//////////////////////////////////////////////////////////////////////////////// + +} // namespace NYT diff --git a/library/cpp/yson/node/ya.make b/library/cpp/yson/node/ya.make index a082b293c4..7b96a1e634 100644 --- a/library/cpp/yson/node/ya.make +++ b/library/cpp/yson/node/ya.make @@ -17,7 +17,7 @@ SRCS( node_io.cpp node_builder.cpp node_visitor.cpp - serialize.cpp + serialize.cpp ) END() diff --git a/library/cpp/yson/parser_detail.h b/library/cpp/yson/parser_detail.h index 44223caf12..806212e440 100644 --- a/library/cpp/yson/parser_detail.h +++ b/library/cpp/yson/parser_detail.h @@ -209,9 +209,9 @@ namespace NYson { ch = TBase::template SkipSpaceAndGetChar<AllowFinish>(); if (ch == KeyValueSeparatorSymbol) { TBase::Advance(1); - } else { + } else { ythrow TYsonException() << "Expected '" << KeyValueSeparatorSymbol << "' but '" << ch << "' found"; - } + } ParseNode<AllowFinish>(); ch = TBase::template SkipSpaceAndGetChar<AllowFinish>(); if (ch == KeyedItemSeparatorSymbol) { diff --git a/library/cpp/yson/writer.cpp b/library/cpp/yson/writer.cpp index 054459f9f5..104a338f63 100644 --- a/library/cpp/yson/writer.cpp +++ b/library/cpp/yson/writer.cpp @@ -8,8 +8,8 @@ #include <util/string/cast.h> -#include <cmath> - +#include <cmath> + namespace NYson { //////////////////////////////////////////////////////////////////////////////// @@ -117,7 +117,7 @@ namespace NYson { static const TStringBuf nanLiteral = "%nan"; static const TStringBuf infLiteral = "%inf"; static const TStringBuf negativeInfLiteral = "%-inf"; - + TStringBuf str; if (std::isnan(value)) { str = nanLiteral; @@ -128,11 +128,11 @@ namespace NYson { } return TString(str.data(), str.size()); } - - } + + } //////////////////////////////////////////////////////////////////////////////// - + TYsonWriter::TYsonWriter( IOutputStream* stream, EYsonFormat format, diff --git a/library/cpp/yt/memory/new-inl.h b/library/cpp/yt/memory/new-inl.h index 0a84818516..ce00d338f5 100644 --- a/library/cpp/yt/memory/new-inl.h +++ b/library/cpp/yt/memory/new-inl.h @@ -227,16 +227,16 @@ Y_FORCE_INLINE TIntrusivePtr<T> NewWithExtraSpace( size_t extraSpaceSize, As&&... args) { - auto totalSize = NYT::NDetail::TConstructHelper<T>::Size + extraSpaceSize; + auto totalSize = NYT::NDetail::TConstructHelper<T>::Size + extraSpaceSize; void* ptr = nullptr; - if (NYT::NDetail::TConstructHelper<T>::Alignment <= 16) { + if (NYT::NDetail::TConstructHelper<T>::Alignment <= 16) { ptr = NYTAlloc::Allocate(totalSize); } else { - ptr = NYT::NDetail::AllignedMalloc(totalSize, NYT::NDetail::TConstructHelper<T>::Alignment); + ptr = NYT::NDetail::AllignedMalloc(totalSize, NYT::NDetail::TConstructHelper<T>::Alignment); } - return NYT::NDetail::SafeConstruct<T>(ptr, std::forward<As>(args)...); + return NYT::NDetail::SafeConstruct<T>(ptr, std::forward<As>(args)...); } template <class T, class... As, class> @@ -245,12 +245,12 @@ Y_FORCE_INLINE TIntrusivePtr<T> NewWithExtraSpace( size_t extraSpaceSize, As&&... args) { - auto totalSize = NYT::NDetail::TConstructHelper<T>::Size + extraSpaceSize; + auto totalSize = NYT::NDetail::TConstructHelper<T>::Size + extraSpaceSize; auto* ptr = allocator->Allocate(totalSize); if (!ptr) { return nullptr; } - return NYT::NDetail::SafeConstruct<T>(ptr, std::forward<As>(args)...); + return NYT::NDetail::SafeConstruct<T>(ptr, std::forward<As>(args)...); } //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/misc/enum-inl.h b/library/cpp/yt/misc/enum-inl.h index 59ef704775..0941e1fb63 100644 --- a/library/cpp/yt/misc/enum-inl.h +++ b/library/cpp/yt/misc/enum-inl.h @@ -8,7 +8,7 @@ #include <util/string/printf.h> #include <util/string/cast.h> -#include <algorithm> +#include <algorithm> #include <stdexcept> namespace NYT { @@ -36,25 +36,25 @@ namespace NYT { //////////////////////////////////////////////////////////////////////////////// -namespace NDetail { - -template <typename TValues> -static constexpr bool AreValuesDistinct(const TValues& values) -{ - for (int i = 0; i < static_cast<int>(values.size()); ++i) { - for (int j = i + 1; j < static_cast<int>(values.size()); ++j) { - if (values[i] == values[j]) { - return false; - } - } - } - return true; -} - -} // namespace NDetail - -//////////////////////////////////////////////////////////////////////////////// - +namespace NDetail { + +template <typename TValues> +static constexpr bool AreValuesDistinct(const TValues& values) +{ + for (int i = 0; i < static_cast<int>(values.size()); ++i) { + for (int j = i + 1; j < static_cast<int>(values.size()); ++j) { + if (values[i] == values[j]) { + return false; + } + } + } + return true; +} + +} // namespace NDetail + +//////////////////////////////////////////////////////////////////////////////// + #define ENUM__BEGIN_TRAITS(name, underlyingType, isBit, isStringSerializable, seq) \ struct TEnumTraitsImpl_##name \ { \ @@ -64,13 +64,13 @@ static constexpr bool AreValuesDistinct(const TValues& values) [[maybe_unused]] static constexpr bool IsStringSerializableEnum = isStringSerializable; \ [[maybe_unused]] static constexpr int DomainSize = PP_COUNT(seq); \ \ - static constexpr std::array<TStringBuf, DomainSize> Names{{ \ - PP_FOR_EACH(ENUM__GET_DOMAIN_NAMES_ITEM, seq) \ - }}; \ - static constexpr std::array<TType, DomainSize> Values{{ \ - PP_FOR_EACH(ENUM__GET_DOMAIN_VALUES_ITEM, seq) \ - }}; \ - \ + static constexpr std::array<TStringBuf, DomainSize> Names{{ \ + PP_FOR_EACH(ENUM__GET_DOMAIN_NAMES_ITEM, seq) \ + }}; \ + static constexpr std::array<TType, DomainSize> Values{{ \ + PP_FOR_EACH(ENUM__GET_DOMAIN_VALUES_ITEM, seq) \ + }}; \ + \ static TStringBuf GetTypeName() \ { \ static constexpr TStringBuf typeName = PP_STRINGIZE(name); \ @@ -79,33 +79,33 @@ static constexpr bool AreValuesDistinct(const TValues& values) \ static const TStringBuf* FindLiteralByValue(TType value) \ { \ - for (int i = 0; i < DomainSize; ++i) { \ - if (Values[i] == value) { \ - return &Names[i]; \ - } \ - } \ + for (int i = 0; i < DomainSize; ++i) { \ + if (Values[i] == value) { \ + return &Names[i]; \ + } \ + } \ return nullptr; \ } \ \ static bool FindValueByLiteral(TStringBuf literal, TType* result) \ { \ - for (int i = 0; i < DomainSize; ++i) { \ - if (Names[i] == literal) { \ - *result = Values[i]; \ - return true; \ - } \ - } \ + for (int i = 0; i < DomainSize; ++i) { \ + if (Names[i] == literal) { \ + *result = Values[i]; \ + return true; \ + } \ + } \ return false; \ } \ \ static const std::array<TStringBuf, DomainSize>& GetDomainNames() \ { \ - return Names; \ + return Names; \ } \ \ static const std::array<TType, DomainSize>& GetDomainValues() \ { \ - return Values; \ + return Values; \ } \ \ static TType FromString(TStringBuf str) \ @@ -145,34 +145,34 @@ static constexpr bool AreValuesDistinct(const TValues& values) #define ENUM__GET_DOMAIN_NAMES_ITEM_ATOMIC(item) \ TStringBuf(PP_STRINGIZE(item)), -#define ENUM__DECOMPOSE \ +#define ENUM__DECOMPOSE \ static std::vector<TType> Decompose(TType value) \ { \ std::vector<TType> result; \ - for (int i = 0; i < DomainSize; ++i) { \ - if (static_cast<TUnderlying>(value) & static_cast<TUnderlying>(Values[i])) { \ - result.push_back(Values[i]); \ - } \ - } \ + for (int i = 0; i < DomainSize; ++i) { \ + if (static_cast<TUnderlying>(value) & static_cast<TUnderlying>(Values[i])) { \ + result.push_back(Values[i]); \ + } \ + } \ return result; \ } -#define ENUM__MINMAX \ - static constexpr TType GetMinValue() \ +#define ENUM__MINMAX \ + static constexpr TType GetMinValue() \ { \ - static_assert(!Values.empty()); \ - return *std::min_element(std::begin(Values), std::end(Values)); \ + static_assert(!Values.empty()); \ + return *std::min_element(std::begin(Values), std::end(Values)); \ } \ \ - static constexpr TType GetMaxValue() \ + static constexpr TType GetMaxValue() \ { \ - static_assert(!Values.empty()); \ - return *std::max_element(std::begin(Values), std::end(Values)); \ + static_assert(!Values.empty()); \ + return *std::max_element(std::begin(Values), std::end(Values)); \ } -#define ENUM__VALIDATE_UNIQUE(name) \ - static_assert(::NYT::NDetail::AreValuesDistinct(Values), \ - "Enumeration " #name " contains duplicate values"); +#define ENUM__VALIDATE_UNIQUE(name) \ + static_assert(::NYT::NDetail::AreValuesDistinct(Values), \ + "Enumeration " #name " contains duplicate values"); #define ENUM__END_TRAITS(name) \ }; \ @@ -181,7 +181,7 @@ static constexpr bool AreValuesDistinct(const TValues& values) { \ return TEnumTraitsImpl_##name(); \ } \ - \ + \ using ::ToString; \ [[maybe_unused]] inline TString ToString(name value) \ { \ diff --git a/library/cpp/yt/misc/enum.h b/library/cpp/yt/misc/enum.h index 894364aa43..97c62cac93 100644 --- a/library/cpp/yt/misc/enum.h +++ b/library/cpp/yt/misc/enum.h @@ -108,16 +108,16 @@ struct TEnumTraits<T, true> #define DEFINE_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, false, false, seq) \ - ENUM__MINMAX \ - ENUM__VALIDATE_UNIQUE(name) \ - ENUM__END_TRAITS(name) + ENUM__MINMAX \ + ENUM__VALIDATE_UNIQUE(name) \ + ENUM__END_TRAITS(name) //! Defines a smart enumeration with a specific underlying type. //! Duplicate enumeration values are allowed. #define DEFINE_AMBIGUOUS_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, false, false, seq) \ - ENUM__MINMAX \ + ENUM__MINMAX \ ENUM__END_TRAITS(name) //! Defines a smart enumeration with the default |int| underlying type. @@ -133,8 +133,8 @@ struct TEnumTraits<T, true> #define DEFINE_BIT_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, true, false, seq) \ - ENUM__DECOMPOSE \ - ENUM__VALIDATE_UNIQUE(name) \ + ENUM__DECOMPOSE \ + ENUM__VALIDATE_UNIQUE(name) \ ENUM__END_TRAITS(name) \ ENUM__BITWISE_OPS(name) @@ -148,7 +148,7 @@ struct TEnumTraits<T, true> #define DEFINE_AMBIGUOUS_BIT_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, true, false, seq) \ - ENUM__DECOMPOSE \ + ENUM__DECOMPOSE \ ENUM__END_TRAITS(name) \ ENUM__BITWISE_OPS(name) @@ -169,8 +169,8 @@ struct TEnumTraits<T, true> #define DEFINE_STRING_SERIALIZABLE_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, false, true, seq) \ - ENUM__MINMAX \ - ENUM__VALIDATE_UNIQUE(name) \ + ENUM__MINMAX \ + ENUM__VALIDATE_UNIQUE(name) \ ENUM__END_TRAITS(name) \ //! Defines a smart enumeration with a specific underlying type and IsStringSerializable attribute. @@ -178,7 +178,7 @@ struct TEnumTraits<T, true> #define DEFINE_AMBIGUOUS_STRING_SERIALIZABLE_ENUM_WITH_UNDERLYING_TYPE(name, underlyingType, seq) \ ENUM__CLASS(name, underlyingType, seq) \ ENUM__BEGIN_TRAITS(name, underlyingType, false, true, seq) \ - ENUM__MINMAX \ + ENUM__MINMAX \ ENUM__END_TRAITS(name) //! Defines a smart enumeration with the default |int| underlying type and IsStringSerializable attribute. diff --git a/library/cpp/yt/string/enum.cpp b/library/cpp/yt/string/enum.cpp index 7cb8e5c6b6..aaff64f2df 100644 --- a/library/cpp/yt/string/enum.cpp +++ b/library/cpp/yt/string/enum.cpp @@ -26,17 +26,17 @@ TString EncodeEnumValue(TStringBuf value) namespace NDetail { void ThrowMalformedEnumValueException(TStringBuf typeName, TStringBuf value) -{ +{ throw TSimpleException(Format("Error parsing %v value %Qv", typeName, value)); -} - +} + void FormatUnknownEnumValue(TStringBuilderBase* builder, TStringBuf name, i64 value) -{ - builder->AppendFormat("%v(%v)", name, value); -} - +{ + builder->AppendFormat("%v(%v)", name, value); +} + } // namespace NDetail //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/string/enum.h b/library/cpp/yt/string/enum.h index 10dc02610f..6490114bed 100644 --- a/library/cpp/yt/string/enum.h +++ b/library/cpp/yt/string/enum.h @@ -5,7 +5,7 @@ #include <library/cpp/yt/misc/enum.h> #include <optional> - + namespace NYT { //////////////////////////////////////////////////////////////////////////////// @@ -15,13 +15,13 @@ TString EncodeEnumValue(TStringBuf value); template <class T> T ParseEnum(TStringBuf value); - -template <class T> + +template <class T> void FormatEnum(TStringBuilderBase* builder, T value, bool lowerCase); - + template <class T> TString FormatEnum(T value, typename TEnumTraits<T>::TType* = nullptr); - + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT diff --git a/library/cpp/yt/string/format-inl.h b/library/cpp/yt/string/format-inl.h index 5484d4a216..ab08c58f55 100644 --- a/library/cpp/yt/string/format-inl.h +++ b/library/cpp/yt/string/format-inl.h @@ -4,7 +4,7 @@ #include "format.h" #endif -#include "enum.h" +#include "enum.h" #include "string.h" #include <library/cpp/yt/assert/assert.h> @@ -180,12 +180,12 @@ struct TValueFormatter<TEnum, typename std::enable_if<TEnumTraits<TEnum>::IsEnum lowercase = true; } else if (IsQuotationSpecSymbol(*current)) { ++current; - } else { + } else { break; - } + } } - FormatEnum(builder, value, lowercase); + FormatEnum(builder, value, lowercase); } }; diff --git a/library/cpp/yt/string/string.cpp b/library/cpp/yt/string/string.cpp index 7440ac3fdd..1229359833 100644 --- a/library/cpp/yt/string/string.cpp +++ b/library/cpp/yt/string/string.cpp @@ -1,5 +1,5 @@ #include "string.h" -#include "format.h" +#include "format.h" #include <library/cpp/yt/assert/assert.h> diff --git a/library/cpp/yt/string/string.h b/library/cpp/yt/string/string.h index ae6c99caab..c51b9ae410 100644 --- a/library/cpp/yt/string/string.h +++ b/library/cpp/yt/string/string.h @@ -8,8 +8,8 @@ #include <util/generic/string.h> -#include <util/string/strip.h> - +#include <util/string/strip.h> + #include <vector> #include <set> #include <map> diff --git a/library/cpp/yt/yson_string/string.cpp b/library/cpp/yt/yson_string/string.cpp index 99d45e8616..c00aa98a50 100644 --- a/library/cpp/yt/yson_string/string.cpp +++ b/library/cpp/yt/yson_string/string.cpp @@ -99,8 +99,8 @@ TYsonString::TYsonString( TStringBuf data, EYsonType type) : TYsonString(TYsonStringBuf(data, type)) -{ } - +{ } + #ifdef TSTRING_IS_STD_STRING TYsonString::TYsonString( const TString& data, @@ -120,7 +120,7 @@ TYsonString::TYsonString( Type_ = type; } #endif - + TYsonString::TYsonString( const TSharedRef& data, EYsonType type) @@ -134,22 +134,22 @@ TYsonString::TYsonString( TYsonString::operator bool() const { return !std::holds_alternative<TNullPayload>(Payload_); -} - +} + EYsonType TYsonString::GetType() const -{ +{ YT_VERIFY(*this); return Type_; } TStringBuf TYsonString::AsStringBuf() const -{ +{ YT_VERIFY(*this); return TStringBuf(Begin_, Begin_ + Size_); -} - +} + TString TYsonString::ToString() const -{ +{ return Visit( Payload_, [] (const TNullPayload&) -> TString { @@ -161,13 +161,13 @@ TString TYsonString::ToString() const [] (const TString& payload) { return payload; }); -} - +} + size_t TYsonString::ComputeHash() const -{ +{ return THash<TStringBuf>()(TStringBuf(Begin_, Begin_ + Size_)); -} - +} + //////////////////////////////////////////////////////////////////////////////// TString ToString(const TYsonString& yson) @@ -175,11 +175,11 @@ TString ToString(const TYsonString& yson) return yson.ToString(); } -TString ToString(const TYsonStringBuf& yson) -{ +TString ToString(const TYsonStringBuf& yson) +{ return TString(yson.AsStringBuf()); -} - +} + //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NYson diff --git a/library/cpp/yt/yson_string/string.h b/library/cpp/yt/yson_string/string.h index e13af37a6d..b25223aa6c 100644 --- a/library/cpp/yt/yson_string/string.h +++ b/library/cpp/yt/yson_string/string.h @@ -47,28 +47,28 @@ public: //! Returns type of YSON contained here. The instance must be non-null. EYsonType GetType() const; -protected: +protected: TStringBuf Data_; EYsonType Type_; - bool Null_; -}; - + bool Null_; +}; + //////////////////////////////////////////////////////////////////////////////// //! An owning version of TYsonStringBuf. /*! * Internally captures the data either via TString or a polymorphic ref-counted holder. */ -class TYsonString -{ -public: +class TYsonString +{ +public: //! Constructs a null instance. TYsonString(); - + //! Constructs an instance from TYsonStringBuf. //! Copies the data into a ref-counted payload. - explicit TYsonString(const TYsonStringBuf& ysonStringBuf); - + explicit TYsonString(const TYsonStringBuf& ysonStringBuf); + //! Constructs an instance from TStringBuf. //! Copies the data into a ref-counted payload. explicit TYsonString( @@ -108,7 +108,7 @@ private: { }; using THolder = TRefCountedPtr; - + std::variant<TNullPayload, THolder, TString> Payload_; const char* Begin_; @@ -119,17 +119,17 @@ private: //////////////////////////////////////////////////////////////////////////////// bool operator == (const TYsonString& lhs, const TYsonString& rhs); -bool operator == (const TYsonString& lhs, const TYsonStringBuf& rhs); -bool operator == (const TYsonStringBuf& lhs, const TYsonString& rhs); -bool operator == (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs); - +bool operator == (const TYsonString& lhs, const TYsonStringBuf& rhs); +bool operator == (const TYsonStringBuf& lhs, const TYsonString& rhs); +bool operator == (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs); + bool operator != (const TYsonString& lhs, const TYsonString& rhs); -bool operator != (const TYsonString& lhs, const TYsonStringBuf& rhs); -bool operator != (const TYsonStringBuf& lhs, const TYsonString& rhs); -bool operator != (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs); +bool operator != (const TYsonString& lhs, const TYsonStringBuf& rhs); +bool operator != (const TYsonStringBuf& lhs, const TYsonString& rhs); +bool operator != (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs); TString ToString(const TYsonString& yson); -TString ToString(const TYsonStringBuf& yson); +TString ToString(const TYsonStringBuf& yson); //////////////////////////////////////////////////////////////////////////////// |