diff options
author | sankear <sankear@yandex-team.ru> | 2022-02-10 16:50:10 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:10 +0300 |
commit | 7377d7b033ffbef85e9bb0bf35091a8e79ed422c (patch) | |
tree | fca7665beced1b829e5ab628094d3721a66c1001 | |
parent | f054f783b50cf93fa12c0cc6375769c21f3fd27e (diff) | |
download | ydb-7377d7b033ffbef85e9bb0bf35091a8e79ed422c.tar.gz |
Restoring authorship annotation for <sankear@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | library/cpp/containers/top_keeper/top_keeper.h | 38 | ||||
-rw-r--r-- | library/cpp/containers/top_keeper/top_keeper/top_keeper.h | 38 | ||||
-rw-r--r-- | library/cpp/deprecated/mapped_file/mapped_file.cpp | 14 | ||||
-rw-r--r-- | library/cpp/deprecated/mapped_file/mapped_file.h | 8 | ||||
-rw-r--r-- | util/generic/maybe.h | 18 | ||||
-rw-r--r-- | util/generic/maybe_ut.cpp | 20 | ||||
-rw-r--r-- | util/generic/vector.h | 4 | ||||
-rw-r--r-- | util/memory/blob.cpp | 12 | ||||
-rw-r--r-- | util/memory/blob.h | 12 | ||||
-rw-r--r-- | util/string/vector.cpp | 18 | ||||
-rw-r--r-- | util/string/vector.h | 10 | ||||
-rw-r--r-- | util/system/file.cpp | 16 | ||||
-rw-r--r-- | util/system/file_ut.cpp | 140 | ||||
-rw-r--r-- | util/system/filemap.cpp | 30 | ||||
-rw-r--r-- | util/system/filemap.h | 8 |
15 files changed, 193 insertions, 193 deletions
diff --git a/library/cpp/containers/top_keeper/top_keeper.h b/library/cpp/containers/top_keeper/top_keeper.h index 2f282b5a9e..670561b0af 100644 --- a/library/cpp/containers/top_keeper/top_keeper.h +++ b/library/cpp/containers/top_keeper/top_keeper.h @@ -22,16 +22,16 @@ private: template <class UT> bool Insert(UT&& value) noexcept { - if (Y_UNLIKELY(0 == HalfMaxSize)) { + if (Y_UNLIKELY(0 == HalfMaxSize)) { return false; } - if (Internal.size() < HalfMaxSize) { + if (Internal.size() < HalfMaxSize) { if (Internal.empty() || Comparer(Internal[MinElementIndex], value)) { MinElementIndex = Internal.size(); - Internal.push_back(std::forward<UT>(value)); - return true; - } + Internal.push_back(std::forward<UT>(value)); + return true; + } } else if (!Comparer(value, Internal[MinElementIndex])) { return false; } @@ -69,11 +69,11 @@ private: } void Partition() { - if (Y_UNLIKELY(HalfMaxSize == 0)) { - return; - } - if (Y_LIKELY(Internal.size() >= HalfMaxSize)) { - NthElement(Internal.begin(), Internal.begin() + HalfMaxSize - 1, Internal.end(), Comparer); + if (Y_UNLIKELY(HalfMaxSize == 0)) { + return; + } + if (Y_LIKELY(Internal.size() >= HalfMaxSize)) { + NthElement(Internal.begin(), Internal.begin() + HalfMaxSize - 1, Internal.end(), Comparer); Internal.erase(Internal.begin() + HalfMaxSize, Internal.end()); //we should update MinElementIndex cause we just altered Internal @@ -96,7 +96,7 @@ private: void SetMaxSize(size_t newHalfMaxSize) { HalfMaxSize = newHalfMaxSize; - Reserve(); + Reserve(); Partition(); } @@ -142,14 +142,14 @@ private: bool Finalized; public: - TTopKeeper() - : MaxSize(0) - , Comparer() - , Internal(0, Comparer) - , Finalized(false) - { - } - + TTopKeeper() + : MaxSize(0) + , Comparer() + , Internal(0, Comparer) + , Finalized(false) + { + } + TTopKeeper(size_t maxSize, const TComparator& comp = TComparator()) : MaxSize(maxSize) , Comparer(comp) diff --git a/library/cpp/containers/top_keeper/top_keeper/top_keeper.h b/library/cpp/containers/top_keeper/top_keeper/top_keeper.h index 2f282b5a9e..670561b0af 100644 --- a/library/cpp/containers/top_keeper/top_keeper/top_keeper.h +++ b/library/cpp/containers/top_keeper/top_keeper/top_keeper.h @@ -22,16 +22,16 @@ private: template <class UT> bool Insert(UT&& value) noexcept { - if (Y_UNLIKELY(0 == HalfMaxSize)) { + if (Y_UNLIKELY(0 == HalfMaxSize)) { return false; } - if (Internal.size() < HalfMaxSize) { + if (Internal.size() < HalfMaxSize) { if (Internal.empty() || Comparer(Internal[MinElementIndex], value)) { MinElementIndex = Internal.size(); - Internal.push_back(std::forward<UT>(value)); - return true; - } + Internal.push_back(std::forward<UT>(value)); + return true; + } } else if (!Comparer(value, Internal[MinElementIndex])) { return false; } @@ -69,11 +69,11 @@ private: } void Partition() { - if (Y_UNLIKELY(HalfMaxSize == 0)) { - return; - } - if (Y_LIKELY(Internal.size() >= HalfMaxSize)) { - NthElement(Internal.begin(), Internal.begin() + HalfMaxSize - 1, Internal.end(), Comparer); + if (Y_UNLIKELY(HalfMaxSize == 0)) { + return; + } + if (Y_LIKELY(Internal.size() >= HalfMaxSize)) { + NthElement(Internal.begin(), Internal.begin() + HalfMaxSize - 1, Internal.end(), Comparer); Internal.erase(Internal.begin() + HalfMaxSize, Internal.end()); //we should update MinElementIndex cause we just altered Internal @@ -96,7 +96,7 @@ private: void SetMaxSize(size_t newHalfMaxSize) { HalfMaxSize = newHalfMaxSize; - Reserve(); + Reserve(); Partition(); } @@ -142,14 +142,14 @@ private: bool Finalized; public: - TTopKeeper() - : MaxSize(0) - , Comparer() - , Internal(0, Comparer) - , Finalized(false) - { - } - + TTopKeeper() + : MaxSize(0) + , Comparer() + , Internal(0, Comparer) + , Finalized(false) + { + } + TTopKeeper(size_t maxSize, const TComparator& comp = TComparator()) : MaxSize(maxSize) , Comparer(comp) diff --git a/library/cpp/deprecated/mapped_file/mapped_file.cpp b/library/cpp/deprecated/mapped_file/mapped_file.cpp index b0e4511299..7da3992e5b 100644 --- a/library/cpp/deprecated/mapped_file/mapped_file.cpp +++ b/library/cpp/deprecated/mapped_file/mapped_file.cpp @@ -14,7 +14,7 @@ TMappedFile::TMappedFile(TFileMap* map, const char* dbgName) { Map_->Map(0, static_cast<size_t>(len)); } -TMappedFile::TMappedFile(const TFile& file, TFileMap::EOpenMode om, const char* dbgName) +TMappedFile::TMappedFile(const TFile& file, TFileMap::EOpenMode om, const char* dbgName) : Map_(nullptr) { init(file, om, dbgName); @@ -28,13 +28,13 @@ void TMappedFile::precharge(size_t off, size_t size) const { } void TMappedFile::init(const TString& name) { - THolder<TFileMap> map(new TFileMap(name)); + THolder<TFileMap> map(new TFileMap(name)); TMappedFile newFile(map.Get(), name.data()); Y_UNUSED(map.Release()); - newFile.swap(*this); - newFile.term(); -} - + newFile.swap(*this); + newFile.term(); +} + void TMappedFile::init(const TString& name, size_t length, TFileMap::EOpenMode om) { THolder<TFileMap> map(new TFileMap(name, length, om)); TMappedFile newFile(map.Get(), name.data()); @@ -43,7 +43,7 @@ void TMappedFile::init(const TString& name, size_t length, TFileMap::EOpenMode o newFile.term(); } -void TMappedFile::init(const TFile& file, TFileMap::EOpenMode om, const char* dbgName) { +void TMappedFile::init(const TFile& file, TFileMap::EOpenMode om, const char* dbgName) { THolder<TFileMap> map(new TFileMap(file, om)); TMappedFile newFile(map.Get(), dbgName); Y_UNUSED(map.Release()); diff --git a/library/cpp/deprecated/mapped_file/mapped_file.h b/library/cpp/deprecated/mapped_file/mapped_file.h index 45859ed65a..ec59737a17 100644 --- a/library/cpp/deprecated/mapped_file/mapped_file.h +++ b/library/cpp/deprecated/mapped_file/mapped_file.h @@ -32,10 +32,10 @@ public: explicit TMappedFile(const TString& name) { Map_ = nullptr; - init(name, TFileMap::oRdOnly); + init(name, TFileMap::oRdOnly); } - TMappedFile(const TFile& file, TFileMap::EOpenMode om = TFileMap::oRdOnly, const char* dbgName = "unknown"); + TMappedFile(const TFile& file, TFileMap::EOpenMode om = TFileMap::oRdOnly, const char* dbgName = "unknown"); void init(const TString& name); @@ -43,8 +43,8 @@ public: void init(const TString& name, size_t length, TFileMap::EOpenMode om); - void init(const TFile&, TFileMap::EOpenMode om = TFileMap::oRdOnly, const char* dbgName = "unknown"); - + void init(const TFile&, TFileMap::EOpenMode om = TFileMap::oRdOnly, const char* dbgName = "unknown"); + void flush(); void term() { diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 34d21aebcd..ce476a171d 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -708,15 +708,15 @@ template <class T, class TPolicy, class U, std::enable_if_t<std::is_convertible< constexpr bool operator>=(const U& value, const TMaybe<T, TPolicy>& maybe) { return !(value < maybe); } - + class IOutputStream; - -template <class T, class TPolicy> + +template <class T, class TPolicy> inline IOutputStream& operator<<(IOutputStream& out, const TMaybe<T, TPolicy>& maybe) { - if (maybe.Defined()) { - out << *maybe; - } else { + if (maybe.Defined()) { + out << *maybe; + } else { out << TStringBuf("(empty maybe)"); - } - return out; -} + } + return out; +} diff --git a/util/generic/maybe_ut.cpp b/util/generic/maybe_ut.cpp index 2c1a425c5e..ae5b46adea 100644 --- a/util/generic/maybe_ut.cpp +++ b/util/generic/maybe_ut.cpp @@ -787,14 +787,14 @@ Y_UNIT_TEST_SUITE(TMaybeTest) { UNIT_ASSERT(m2 == Nothing()); } } - + Y_UNIT_TEST(TestOutputStreamEmptyMaybe) { TString s; - TStringOutput output(s); - output << TMaybe<int>(); - UNIT_ASSERT_EQUAL("(empty maybe)", s); - } - + TStringOutput output(s); + output << TMaybe<int>(); + UNIT_ASSERT_EQUAL("(empty maybe)", s); + } + Y_UNIT_TEST(TestOutputStreamNothing) { TString s; TStringOutput output(s); @@ -804,10 +804,10 @@ Y_UNIT_TEST_SUITE(TMaybeTest) { Y_UNIT_TEST(TestOutputStreamDefinedMaybe) { TString s; - TStringOutput output(s); - output << TMaybe<int>(42); - UNIT_ASSERT_EQUAL("42", s); - } + TStringOutput output(s); + output << TMaybe<int>(42); + UNIT_ASSERT_EQUAL("42", s); + } Y_UNIT_TEST(TestMaybeCovarianceImplicit) { struct TestStruct { diff --git a/util/generic/vector.h b/util/generic/vector.h index a5b258955a..843ac659c8 100644 --- a/util/generic/vector.h +++ b/util/generic/vector.h @@ -73,7 +73,7 @@ public: } inline TVector(TSelf&& src) noexcept - : TBase(std::forward<TSelf>(src)) + : TBase(std::forward<TSelf>(src)) { } @@ -89,7 +89,7 @@ public: } inline TSelf& operator=(TSelf&& src) noexcept { - TBase::operator=(std::forward<TSelf>(src)); + TBase::operator=(std::forward<TSelf>(src)); return *this; } diff --git a/util/memory/blob.cpp b/util/memory/blob.cpp index 91da5cadca..d7656c2bac 100644 --- a/util/memory/blob.cpp +++ b/util/memory/blob.cpp @@ -284,14 +284,14 @@ TBlob TBlob::LockedFromFile(const TFile& file) { return ConstructAsMap<TAtomicCounter>(file, EMappingMode::Locked); } -TBlob TBlob::LockedFromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length) { +TBlob TBlob::LockedFromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length) { return ConstructFromMap<TSimpleCounter>(map, offset, length, EMappingMode::Locked); -} - -TBlob TBlob::LockedFromMemoryMap(const TMemoryMap& map, ui64 offset, size_t length) { +} + +TBlob TBlob::LockedFromMemoryMap(const TMemoryMap& map, ui64 offset, size_t length) { return ConstructFromMap<TAtomicCounter>(map, offset, length, EMappingMode::Locked); -} - +} + TBlob TBlob::FromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length) { return ConstructFromMap<TSimpleCounter>(map, offset, length, EMappingMode::Standard); } diff --git a/util/memory/blob.h b/util/memory/blob.h index 20c02a68df..701a6d9070 100644 --- a/util/memory/blob.h +++ b/util/memory/blob.h @@ -250,12 +250,12 @@ public: /// Creates a locked blob with a multi-threaded (atomic) refcounter. It maps the file content as data. static TBlob LockedFromFile(const TFile& file); - /// Creates a locked blob with a single-threaded (non atomic) refcounter from the mapped memory. - static TBlob LockedFromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length); - - /// Creates a locked blob with a multi-threaded (atomic) refcounter from the mapped memory. - static TBlob LockedFromMemoryMap(const TMemoryMap& map, ui64 offset, size_t length); - + /// Creates a locked blob with a single-threaded (non atomic) refcounter from the mapped memory. + static TBlob LockedFromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length); + + /// Creates a locked blob with a multi-threaded (atomic) refcounter from the mapped memory. + static TBlob LockedFromMemoryMap(const TMemoryMap& map, ui64 offset, size_t length); + /// Creates a blob with a single-threaded (non atomic) refcounter from the mapped memory. static TBlob FromMemoryMapSingleThreaded(const TMemoryMap& map, ui64 offset, size_t length); diff --git a/util/string/vector.cpp b/util/string/vector.cpp index 9ba401f0a2..1e8ddae94f 100644 --- a/util/string/vector.cpp +++ b/util/string/vector.cpp @@ -12,7 +12,7 @@ static inline void DoSplit2(TConsumer& c, TDelim& d, const TBasicStringBuf<TChr> template <class TConsumer, class TDelim, typename TChr> static inline void DoSplit1(TConsumer& cc, TDelim& d, const TBasicStringBuf<TChr> str, int opts) { if (opts & KEEP_EMPTY_TOKENS) { - DoSplit2(cc, d, str, opts); + DoSplit2(cc, d, str, opts); } else { TSkipEmptyTokens<TConsumer> sc(&cc); @@ -35,13 +35,13 @@ static inline void DoSplit0(C* res, const TBasicStringBuf<TChr> str, TDelim& d, if (maxFields) { TLimitingConsumer<TConsumer, const TChr> lc(maxFields, &cc); - DoSplit1(lc, d, str, options); + DoSplit1(lc, d, str, options); if (lc.Last) { res->push_back(TStringType(lc.Last, str.data() + str.size() - lc.Last)); } } else { - DoSplit1(cc, d, str, options); + DoSplit1(cc, d, str, options); } } @@ -55,11 +55,11 @@ static void SplitStringImplT(TVector<std::conditional_t<std::is_same<TChr, wchar if (*(delim + 1)) { TStringDelimiter<const TChr> d(delim, std::char_traits<TChr>::length(delim)); - DoSplit0(res, str, d, maxFields, options); + DoSplit0(res, str, d, maxFields, options); } else { TCharDelimiter<const TChr> d(*delim); - DoSplit0(res, str, d, maxFields, options); + DoSplit0(res, str, d, maxFields, options); } } @@ -69,16 +69,16 @@ void ::NPrivate::SplitStringImpl(TVector<TString>* res, const char* ptr, const c void ::NPrivate::SplitStringImpl(TVector<TString>* res, const char* ptr, size_t len, const char* delim, size_t maxFields, int options) { return SplitStringImplT<char>(res, TStringBuf(ptr, len), delim, maxFields, options); -} - +} + void ::NPrivate::SplitStringImpl(TVector<TUtf16String>* res, const wchar16* ptr, const wchar16* delimiter, size_t maxFields, int options) { return SplitStringImplT<wchar16>(res, TWtringBuf(ptr), delimiter, maxFields, options); } void ::NPrivate::SplitStringImpl(TVector<TUtf16String>* res, const wchar16* ptr, size_t len, const wchar16* delimiter, size_t maxFields, int options) { return SplitStringImplT<wchar16>(res, TWtringBuf(ptr, len), delimiter, maxFields, options); -} - +} + TUtf16String JoinStrings(const TVector<TUtf16String>& v, const TWtringBuf delim) { return JoinStrings(v.begin(), v.end(), delim); } diff --git a/util/string/vector.h b/util/string/vector.h index e36c348bbe..d01d9403c3 100644 --- a/util/string/vector.h +++ b/util/string/vector.h @@ -16,12 +16,12 @@ // NOTE: Check StringSplitter below to get more convenient split string interface. namespace NPrivate { - + void SplitStringImpl(TVector<TString>* res, const char* ptr, const char* delimiter, size_t maxFields, int options); void SplitStringImpl(TVector<TString>* res, const char* ptr, size_t len, const char* delimiter, size_t maxFields, int options); - + void SplitStringImpl(TVector<TUtf16String>* res, const wchar16* ptr, const wchar16* delimiter, size_t maxFields, int options); void SplitStringImpl(TVector<TUtf16String>* res, const wchar16* ptr, size_t len, @@ -56,9 +56,9 @@ SplitString(const C* ptr, size_t len, const C* delimiter, size_t maxFields = 0, int options = 0) { TVector<typename ::NPrivate::TStringDeducer<C>::type> res; ::NPrivate::SplitStringImpl(&res, ptr, len, delimiter, maxFields, options); - return res; -} - + return res; +} + template <typename C> TVector<typename ::NPrivate::TStringDeducer<C>::type> SplitString(const typename ::NPrivate::TStringDeducer<C>::type& str, const C* delimiter, diff --git a/util/system/file.cpp b/util/system/file.cpp index 4a261d020c..0b1b38d668 100644 --- a/util/system/file.cpp +++ b/util/system/file.cpp @@ -937,7 +937,7 @@ public: // Syscalls can cause contention if they operate on very large data blocks. static constexpr size_t MaxReadPortion = 1_GB; - i32 RawRead(void* bufferIn, size_t numBytes) { + i32 RawRead(void* bufferIn, size_t numBytes) { const size_t toRead = Min(MaxReadPortion, numBytes); return Handle_.Read(bufferIn, toRead); } @@ -1002,7 +1002,7 @@ public: while (numBytes) { const i32 toRead = (i32)Min(MaxReadPortion, numBytes); - const i32 reallyRead = RawPread(buf, toRead, offset); + const i32 reallyRead = RawPread(buf, toRead, offset); if (reallyRead < 0) { ythrow TFileError() << "can not read data from " << FileName_.Quote(); @@ -1021,10 +1021,10 @@ public: return buf - (ui8*)bufferIn; } - i32 RawPread(void* buf, ui32 len, i64 offset) const { - return Handle_.Pread(buf, len, offset); - } - + i32 RawPread(void* buf, ui32 len, i64 offset) const { + return Handle_.Pread(buf, len, offset); + } + void Pload(void* buf, size_t len, i64 offset) const { if (Pread(buf, len, offset) != len) { ythrow TFileError() << "can't read " << len << " bytes at offset " << offset << " from " << FileName_.Quote(); @@ -1171,8 +1171,8 @@ size_t TFile::Read(void* buf, size_t len) { return Impl_->Read(buf, len); } -i32 TFile::RawRead(void* buf, size_t len) { - return Impl_->RawRead(buf, len); +i32 TFile::RawRead(void* buf, size_t len) { + return Impl_->RawRead(buf, len); } size_t TFile::ReadOrFail(void* buf, size_t len) { diff --git a/util/system/file_ut.cpp b/util/system/file_ut.cpp index 941e6a50f3..abdee31d7e 100644 --- a/util/system/file_ut.cpp +++ b/util/system/file_ut.cpp @@ -19,10 +19,10 @@ class TFileTest: public TTestBase { UNIT_TEST(TestLocale); UNIT_TEST(TestFlush); UNIT_TEST(TestFlushSpecialFile); - UNIT_TEST(TestRawRead); - UNIT_TEST(TestRead); + UNIT_TEST(TestRawRead); + UNIT_TEST(TestRead); UNIT_TEST(TestRawPread); - UNIT_TEST(TestPread); + UNIT_TEST(TestPread); UNIT_TEST(TestCache); UNIT_TEST_SUITE_END(); @@ -33,10 +33,10 @@ public: void TestLocale(); void TestFlush(); void TestFlushSpecialFile(); - void TestRawRead(); - void TestRead(); + void TestRawRead(); + void TestRead(); void TestRawPread(); - void TestPread(); + void TestPread(); void TestCache(); inline void TestLinkTo() { @@ -239,48 +239,48 @@ void TFileTest::TestFlushSpecialFile() { #endif } -void TFileTest::TestRawRead() { - TTempFile tmp("tmp"); - - { - TFile file(tmp.Name(), OpenAlways | WrOnly); - file.Write("1234567", 7); - file.Flush(); - file.Close(); - } - - { - TFile file(tmp.Name(), OpenExisting | RdOnly); - char buf[7]; - i32 reallyRead = file.RawRead(buf, 7); - Y_ENSURE(0 <= reallyRead && reallyRead <= 7); - Y_ENSURE(TStringBuf(buf, reallyRead) == TStringBuf("1234567").Head(reallyRead)); - } -} - -void TFileTest::TestRead() { - TTempFile tmp("tmp"); - - { - TFile file(tmp.Name(), OpenAlways | WrOnly); - file.Write("1234567", 7); - file.Flush(); - file.Close(); - } - - { - TFile file(tmp.Name(), OpenExisting | RdOnly); - char buf[7]; - Y_ENSURE(file.Read(buf, 7) == 7); - Y_ENSURE(TStringBuf(buf, 7) == "1234567"); - - memset(buf, 0, sizeof(buf)); - file.Seek(0, sSet); - Y_ENSURE(file.Read(buf, 123) == 7); - Y_ENSURE(TStringBuf(buf, 7) == "1234567"); - } -} - +void TFileTest::TestRawRead() { + TTempFile tmp("tmp"); + + { + TFile file(tmp.Name(), OpenAlways | WrOnly); + file.Write("1234567", 7); + file.Flush(); + file.Close(); + } + + { + TFile file(tmp.Name(), OpenExisting | RdOnly); + char buf[7]; + i32 reallyRead = file.RawRead(buf, 7); + Y_ENSURE(0 <= reallyRead && reallyRead <= 7); + Y_ENSURE(TStringBuf(buf, reallyRead) == TStringBuf("1234567").Head(reallyRead)); + } +} + +void TFileTest::TestRead() { + TTempFile tmp("tmp"); + + { + TFile file(tmp.Name(), OpenAlways | WrOnly); + file.Write("1234567", 7); + file.Flush(); + file.Close(); + } + + { + TFile file(tmp.Name(), OpenExisting | RdOnly); + char buf[7]; + Y_ENSURE(file.Read(buf, 7) == 7); + Y_ENSURE(TStringBuf(buf, 7) == "1234567"); + + memset(buf, 0, sizeof(buf)); + file.Seek(0, sSet); + Y_ENSURE(file.Read(buf, 123) == 7); + Y_ENSURE(TStringBuf(buf, 7) == "1234567"); + } +} + void TFileTest::TestRawPread() { TTempFile tmp("tmp"); @@ -305,28 +305,28 @@ void TFileTest::TestRawPread() { } } -void TFileTest::TestPread() { - TTempFile tmp("tmp"); - - { - TFile file(tmp.Name(), OpenAlways | WrOnly); - file.Write("1234567", 7); - file.Flush(); - file.Close(); - } - - { - TFile file(tmp.Name(), OpenExisting | RdOnly); - char buf[7]; - Y_ENSURE(file.Pread(buf, 3, 1) == 3); - Y_ENSURE(TStringBuf(buf, 3) == "234"); - - memset(buf, 0, sizeof(buf)); - Y_ENSURE(file.Pread(buf, 2, 5) == 2); - Y_ENSURE(TStringBuf(buf, 2) == "67"); - } -} - +void TFileTest::TestPread() { + TTempFile tmp("tmp"); + + { + TFile file(tmp.Name(), OpenAlways | WrOnly); + file.Write("1234567", 7); + file.Flush(); + file.Close(); + } + + { + TFile file(tmp.Name(), OpenExisting | RdOnly); + char buf[7]; + Y_ENSURE(file.Pread(buf, 3, 1) == 3); + Y_ENSURE(TStringBuf(buf, 3) == "234"); + + memset(buf, 0, sizeof(buf)); + Y_ENSURE(file.Pread(buf, 2, 5) == 2); + Y_ENSURE(TStringBuf(buf, 2) == "67"); + } +} + #ifdef _linux_ #include <sys/statfs.h> #endif diff --git a/util/system/filemap.cpp b/util/system/filemap.cpp index 7454a4cb94..dde2baf5fc 100644 --- a/util/system/filemap.cpp +++ b/util/system/filemap.cpp @@ -337,7 +337,7 @@ private: TFile File_; TString DbgName_; // This string is never used to actually open a file, only in exceptions i64 Length_; - EOpenMode Mode_; + EOpenMode Mode_; #if defined(_win_) void* Mapping_; @@ -347,10 +347,10 @@ private: }; TMemoryMap::TMemoryMap(const TString& name) - : Impl_(new TImpl(name, EOpenModeFlag::oRdOnly)) -{ -} - + : Impl_(new TImpl(name, EOpenModeFlag::oRdOnly)) +{ +} + TMemoryMap::TMemoryMap(const TString& name, EOpenMode om) : Impl_(new TImpl(name, om)) { @@ -363,9 +363,9 @@ TMemoryMap::TMemoryMap(const TString& name, i64 length, EOpenMode om) TMemoryMap::TMemoryMap(FILE* f, TString dbgName) : Impl_(new TImpl(f, EOpenModeFlag::oRdOnly, std::move(dbgName))) -{ -} - +{ +} + TMemoryMap::TMemoryMap(FILE* f, EOpenMode om, TString dbgName) : Impl_(new TImpl(f, om, std::move(dbgName))) { @@ -373,9 +373,9 @@ TMemoryMap::TMemoryMap(FILE* f, EOpenMode om, TString dbgName) TMemoryMap::TMemoryMap(const TFile& file, TString dbgName) : Impl_(new TImpl(file, EOpenModeFlag::oRdOnly, std::move(dbgName))) -{ -} - +{ +} + TMemoryMap::TMemoryMap(const TFile& file, EOpenMode om, TString dbgName) : Impl_(new TImpl(file, om, std::move(dbgName))) { @@ -445,10 +445,10 @@ TFileMap::TFileMap(const TMemoryMap& map) noexcept } TFileMap::TFileMap(const TString& name) - : Map_(name) -{ -} - + : Map_(name) +{ +} + TFileMap::TFileMap(const TString& name, EOpenMode om) : Map_(name, om) { diff --git a/util/system/filemap.h b/util/system/filemap.h index 11be64bff4..3a5516fe8d 100644 --- a/util/system/filemap.h +++ b/util/system/filemap.h @@ -8,7 +8,7 @@ #include <util/generic/ptr.h> #include <util/generic/utility.h> #include <util/generic/yexception.h> -#include <util/generic/flags.h> +#include <util/generic/flags.h> #include <util/generic/string.h> #include <new> @@ -48,7 +48,7 @@ struct TMemoryMapCommon { } }; - enum EOpenModeFlag { + enum EOpenModeFlag { oRdOnly = 1, oRdWr = 2, oCopyOnWr = 4, @@ -58,7 +58,7 @@ struct TMemoryMapCommon { oPrecharge = 16, oPopulate = 32, // Populate page table entries (see mmap's MAP_POPULATE) }; - Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag) + Y_DECLARE_FLAGS(EOpenMode, EOpenModeFlag) /** * Name that will be printed in exceptions if not specified. @@ -66,7 +66,7 @@ struct TMemoryMapCommon { */ static TString UnknownFileName(); }; -Y_DECLARE_OPERATORS_FOR_FLAGS(TMemoryMapCommon::EOpenMode) +Y_DECLARE_OPERATORS_FOR_FLAGS(TMemoryMapCommon::EOpenMode) class TMemoryMap: public TMemoryMapCommon { public: |