Просмотр исходного кода

Restoring authorship annotation for <nikitamorozov@yandex-team.ru>. Commit 2 of 2.

nikitamorozov 3 лет назад
Родитель
Сommit
523d26598d

+ 1 - 1
library/cpp/yson/node/serialize.cpp

@@ -1,6 +1,6 @@
 #include "serialize.h"
 #include "serialize.h"
 
 
-#include "node_visitor.h" 
+#include "node_visitor.h"
 
 
 #include <library/cpp/yson/consumer.h>
 #include <library/cpp/yson/consumer.h>
 
 

+ 25 - 25
util/stream/buffer.cpp

@@ -1,6 +1,6 @@
 #include "buffer.h"
 #include "buffer.h"
 #include <util/generic/buffer.h>
 #include <util/generic/buffer.h>
-#include <util/generic/yexception.h> 
+#include <util/generic/yexception.h>
 
 
 class TBufferOutput::TImpl {
 class TBufferOutput::TImpl {
 public:
 public:
@@ -11,21 +11,21 @@ public:
 
 
     virtual ~TImpl() = default;
     virtual ~TImpl() = default;
 
 
-    inline size_t DoNext(void** ptr) { 
-        if (Data_.Avail() == 0) { 
-            Data_.Reserve(FastClp2(Data_.Capacity() + MinBufferGrowSize)); 
-        } 
-        size_t previousSize = Data_.size(); 
-        Data_.Resize(Data_.Capacity()); 
-        *ptr = Data_.Begin() + previousSize; 
-        return Data_.Size() - previousSize; 
-    } 
- 
-    inline void DoUndo(size_t len) { 
-        Y_VERIFY(len <= Data_.Size(), "trying to undo more bytes than actually written"); 
-        Data_.Resize(Data_.size() - len); 
-    } 
- 
+    inline size_t DoNext(void** ptr) {
+        if (Data_.Avail() == 0) {
+            Data_.Reserve(FastClp2(Data_.Capacity() + MinBufferGrowSize));
+        }
+        size_t previousSize = Data_.size();
+        Data_.Resize(Data_.Capacity());
+        *ptr = Data_.Begin() + previousSize;
+        return Data_.Size() - previousSize;
+    }
+
+    inline void DoUndo(size_t len) {
+        Y_VERIFY(len <= Data_.Size(), "trying to undo more bytes than actually written");
+        Data_.Resize(Data_.size() - len);
+    }
+
     inline void DoWrite(const void* buf, size_t len) {
     inline void DoWrite(const void* buf, size_t len) {
         Data_.Append((const char*)buf, len);
         Data_.Append((const char*)buf, len);
     }
     }
@@ -40,7 +40,7 @@ public:
 
 
 private:
 private:
     TBuffer& Data_;
     TBuffer& Data_;
-    static constexpr size_t MinBufferGrowSize = 16; 
+    static constexpr size_t MinBufferGrowSize = 16;
 };
 };
 
 
 namespace {
 namespace {
@@ -75,14 +75,14 @@ TBuffer& TBufferOutput::Buffer() const noexcept {
     return Impl_->Buffer();
     return Impl_->Buffer();
 }
 }
 
 
-size_t TBufferOutput::DoNext(void** ptr) { 
-    return Impl_->DoNext(ptr); 
-} 
- 
-void TBufferOutput::DoUndo(size_t len) { 
-    Impl_->DoUndo(len); 
-} 
- 
+size_t TBufferOutput::DoNext(void** ptr) {
+    return Impl_->DoNext(ptr);
+}
+
+void TBufferOutput::DoUndo(size_t len) {
+    Impl_->DoUndo(len);
+}
+
 void TBufferOutput::DoWrite(const void* buf, size_t len) {
 void TBufferOutput::DoWrite(const void* buf, size_t len) {
     Impl_->DoWrite(buf, len);
     Impl_->DoWrite(buf, len);
 }
 }

+ 4 - 4
util/stream/buffer.h

@@ -1,7 +1,7 @@
 #pragma once
 #pragma once
 
 
 #include "zerocopy.h"
 #include "zerocopy.h"
-#include "zerocopy_output.h" 
+#include "zerocopy_output.h"
 
 
 #include <util/generic/ptr.h>
 #include <util/generic/ptr.h>
 
 
@@ -15,7 +15,7 @@ class TBuffer;
 /**
 /**
  * Output stream that writes into a `TBuffer`.
  * Output stream that writes into a `TBuffer`.
  */
  */
-class TBufferOutput: public IZeroCopyOutput { 
+class TBufferOutput: public IZeroCopyOutput {
 public:
 public:
     class TImpl;
     class TImpl;
 
 
@@ -46,8 +46,8 @@ public:
     TBuffer& Buffer() const noexcept;
     TBuffer& Buffer() const noexcept;
 
 
 private:
 private:
-    size_t DoNext(void** ptr) override; 
-    void DoUndo(size_t len) override; 
+    size_t DoNext(void** ptr) override;
+    void DoUndo(size_t len) override;
     void DoWrite(const void* buf, size_t len) override;
     void DoWrite(const void* buf, size_t len) override;
     void DoWriteC(char c) override;
     void DoWriteC(char c) override;
 
 

+ 25 - 25
util/stream/buffer_ut.cpp

@@ -33,31 +33,31 @@ Y_UNIT_TEST_SUITE(TBufferTest) {
         UNIT_ASSERT_VALUES_EQUAL(tmp, "4567890");
         UNIT_ASSERT_VALUES_EQUAL(tmp, "4567890");
     }
     }
 
 
-    Y_UNIT_TEST(WriteViaNextAndUndo) { 
-        TBuffer buffer; 
-        TBufferOutput output(buffer); 
-        TString str; 
- 
-        for (size_t i = 0; i < 10000; ++i) { 
-            str.push_back('a' + (i % 20)); 
-        } 
- 
-        size_t written = 0; 
-        void* ptr = nullptr; 
-        while (written < str.size()) { 
-            size_t bufferSize = output.Next(&ptr); 
-            UNIT_ASSERT(ptr && bufferSize > 0); 
-            size_t toWrite = Min(bufferSize, str.size() - written); 
-            memcpy(ptr, str.begin() + written, toWrite); 
-            written += toWrite; 
-            if (toWrite < bufferSize) { 
-                output.Undo(bufferSize - toWrite); 
-            } 
-        } 
- 
-        UNIT_ASSERT(0 == memcmp(buffer.data(), str.begin(), buffer.size())); 
-    } 
- 
+    Y_UNIT_TEST(WriteViaNextAndUndo) {
+        TBuffer buffer;
+        TBufferOutput output(buffer);
+        TString str;
+
+        for (size_t i = 0; i < 10000; ++i) {
+            str.push_back('a' + (i % 20));
+        }
+
+        size_t written = 0;
+        void* ptr = nullptr;
+        while (written < str.size()) {
+            size_t bufferSize = output.Next(&ptr);
+            UNIT_ASSERT(ptr && bufferSize > 0);
+            size_t toWrite = Min(bufferSize, str.size() - written);
+            memcpy(ptr, str.begin() + written, toWrite);
+            written += toWrite;
+            if (toWrite < bufferSize) {
+                output.Undo(bufferSize - toWrite);
+            }
+        }
+
+        UNIT_ASSERT(0 == memcmp(buffer.data(), str.begin(), buffer.size()));
+    }
+
     Y_UNIT_TEST(Write) {
     Y_UNIT_TEST(Write) {
         TBuffer buffer;
         TBuffer buffer;
         TBufferOutput output(buffer);
         TBufferOutput output(buffer);

+ 29 - 29
util/stream/buffered.cpp

@@ -163,21 +163,21 @@ public:
         MemOut_.Reset(Buf(), Len());
         MemOut_.Reset(Buf(), Len());
     }
     }
 
 
-    inline size_t Next(void** ptr) { 
-        if (MemOut_.Avail() == 0) { 
-            Slave_->Write(Buf(), Stored()); 
-            OnBufferExhausted(); 
-            Reset(); 
-        } 
- 
-        return MemOut_.Next(ptr); 
-    } 
- 
-    inline void Undo(size_t len) { 
-        Y_VERIFY(len <= Stored(), "trying to undo more bytes than actually written"); 
-        MemOut_.Undo(len); 
-    } 
- 
+    inline size_t Next(void** ptr) {
+        if (MemOut_.Avail() == 0) {
+            Slave_->Write(Buf(), Stored());
+            OnBufferExhausted();
+            Reset();
+        }
+
+        return MemOut_.Next(ptr);
+    }
+
+    inline void Undo(size_t len) {
+        Y_VERIFY(len <= Stored(), "trying to undo more bytes than actually written");
+        MemOut_.Undo(len);
+    }
+
     inline void Write(const void* buf, size_t len) {
     inline void Write(const void* buf, size_t len) {
         if (len <= MemOut_.Avail()) {
         if (len <= MemOut_.Avail()) {
             /*
             /*
@@ -367,24 +367,24 @@ TBufferedOutputBase::~TBufferedOutputBase() {
     }
     }
 }
 }
 
 
-size_t TBufferedOutputBase::DoNext(void** ptr) { 
-    Y_ENSURE(Impl_.Get(), "cannot call next in finished stream"); 
-    return Impl_->Next(ptr); 
-} 
- 
-void TBufferedOutputBase::DoUndo(size_t len) { 
-    Y_ENSURE(Impl_.Get(), "cannot call undo in finished stream"); 
-    Impl_->Undo(len); 
-} 
- 
+size_t TBufferedOutputBase::DoNext(void** ptr) {
+    Y_ENSURE(Impl_.Get(), "cannot call next in finished stream");
+    return Impl_->Next(ptr);
+}
+
+void TBufferedOutputBase::DoUndo(size_t len) {
+    Y_ENSURE(Impl_.Get(), "cannot call undo in finished stream");
+    Impl_->Undo(len);
+}
+
 void TBufferedOutputBase::DoWrite(const void* data, size_t len) {
 void TBufferedOutputBase::DoWrite(const void* data, size_t len) {
-    Y_ENSURE(Impl_.Get(), "cannot write to finished stream"); 
-    Impl_->Write(data, len); 
+    Y_ENSURE(Impl_.Get(), "cannot write to finished stream");
+    Impl_->Write(data, len);
 }
 }
 
 
 void TBufferedOutputBase::DoWriteC(char c) {
 void TBufferedOutputBase::DoWriteC(char c) {
-    Y_ENSURE(Impl_.Get(), "cannot write to finished stream"); 
-    Impl_->Write(c); 
+    Y_ENSURE(Impl_.Get(), "cannot write to finished stream");
+    Impl_->Write(c);
 }
 }
 
 
 void TBufferedOutputBase::DoFlush() {
 void TBufferedOutputBase::DoFlush() {

+ 4 - 4
util/stream/buffered.h

@@ -1,7 +1,7 @@
 #pragma once
 #pragma once
 
 
 #include "zerocopy.h"
 #include "zerocopy.h"
-#include "zerocopy_output.h" 
+#include "zerocopy_output.h"
 
 
 #include <utility>
 #include <utility>
 #include <util/generic/ptr.h>
 #include <util/generic/ptr.h>
@@ -59,7 +59,7 @@ private:
  * Also note that this stream does not claim ownership of the underlying stream,
  * Also note that this stream does not claim ownership of the underlying stream,
  * so it's up to the user to free it.
  * so it's up to the user to free it.
  */
  */
-class TBufferedOutputBase: public IZeroCopyOutput { 
+class TBufferedOutputBase: public IZeroCopyOutput {
 public:
 public:
     /**
     /**
      * Constructs a buffered stream that dynamically adjusts the size of the
      * Constructs a buffered stream that dynamically adjusts the size of the
@@ -111,8 +111,8 @@ public:
     class TImpl;
     class TImpl;
 
 
 protected:
 protected:
-    size_t DoNext(void** ptr) override; 
-    void DoUndo(size_t len) override; 
+    size_t DoNext(void** ptr) override;
+    void DoUndo(size_t len) override;
     void DoWrite(const void* data, size_t len) override;
     void DoWrite(const void* data, size_t len) override;
     void DoWriteC(char c) override;
     void DoWriteC(char c) override;
     void DoFlush() override;
     void DoFlush() override;

+ 33 - 33
util/stream/buffered_ut.cpp

@@ -73,40 +73,40 @@ Y_UNIT_TEST_SUITE(TestBufferedIO) {
         UNIT_ASSERT_VALUES_EQUAL(s, "123");
         UNIT_ASSERT_VALUES_EQUAL(s, "123");
     }
     }
 
 
-    template <class TOut> 
+    template <class TOut>
     inline void DoGenAndWrite(TOut&& output, TString& str) {
     inline void DoGenAndWrite(TOut&& output, TString& str) {
-        TMersenne<ui64> r; 
-        for (size_t i = 0; i < 43210; ++i) { 
-            str.append('A' + (r.GenRand() % 10)); 
-        } 
-        size_t written = 0; 
-        void* ptr = nullptr; 
-        while (written < str.size()) { 
-            size_t bufferSize = output.Next(&ptr); 
-            UNIT_ASSERT(ptr && bufferSize > 0); 
-            size_t toWrite = Min(bufferSize, str.size() - written); 
-            memcpy(ptr, str.begin() + written, toWrite); 
-            written += toWrite; 
-            if (toWrite < bufferSize) { 
-                output.Undo(bufferSize - toWrite); 
-            } 
-        } 
-    } 
- 
-    Y_UNIT_TEST(TestWriteViaNextAndUndo) { 
-        TString str1, str2; 
-        DoGenAndWrite(TBuffered<TStringOutput>(5000, str1), str2); 
- 
-        UNIT_ASSERT_STRINGS_EQUAL(str1, str2); 
-    } 
- 
-    Y_UNIT_TEST(TestWriteViaNextAndUndoAdaptive) { 
-        TString str1, str2; 
-        DoGenAndWrite(TAdaptivelyBuffered<TStringOutput>(str1), str2); 
- 
-        UNIT_ASSERT_STRINGS_EQUAL(str1, str2); 
-    } 
- 
+        TMersenne<ui64> r;
+        for (size_t i = 0; i < 43210; ++i) {
+            str.append('A' + (r.GenRand() % 10));
+        }
+        size_t written = 0;
+        void* ptr = nullptr;
+        while (written < str.size()) {
+            size_t bufferSize = output.Next(&ptr);
+            UNIT_ASSERT(ptr && bufferSize > 0);
+            size_t toWrite = Min(bufferSize, str.size() - written);
+            memcpy(ptr, str.begin() + written, toWrite);
+            written += toWrite;
+            if (toWrite < bufferSize) {
+                output.Undo(bufferSize - toWrite);
+            }
+        }
+    }
+
+    Y_UNIT_TEST(TestWriteViaNextAndUndo) {
+        TString str1, str2;
+        DoGenAndWrite(TBuffered<TStringOutput>(5000, str1), str2);
+
+        UNIT_ASSERT_STRINGS_EQUAL(str1, str2);
+    }
+
+    Y_UNIT_TEST(TestWriteViaNextAndUndoAdaptive) {
+        TString str1, str2;
+        DoGenAndWrite(TAdaptivelyBuffered<TStringOutput>(str1), str2);
+
+        UNIT_ASSERT_STRINGS_EQUAL(str1, str2);
+    }
+
     Y_UNIT_TEST(TestInput) {
     Y_UNIT_TEST(TestInput) {
         TString s("0123456789abcdefghijklmn");
         TString s("0123456789abcdefghijklmn");
         TBuffered<TStringInput> in(5, s);
         TBuffered<TStringInput> in(5, s);

+ 1 - 1
util/stream/fwd.h

@@ -7,7 +7,7 @@ class IOutputStream;
 
 
 class IZeroCopyInput;
 class IZeroCopyInput;
 class IZeroCopyInputFastReadTo;
 class IZeroCopyInputFastReadTo;
-class IZeroCopyOutput; 
+class IZeroCopyOutput;
 
 
 using TStreamManipulator = void (*)(IOutputStream&);
 using TStreamManipulator = void (*)(IOutputStream&);
 
 

+ 12 - 12
util/stream/mem.cpp

@@ -38,19 +38,19 @@ void TMemoryInput::DoUndo(size_t len) {
 
 
 TMemoryOutput::~TMemoryOutput() = default;
 TMemoryOutput::~TMemoryOutput() = default;
 
 
-size_t TMemoryOutput::DoNext(void** ptr) { 
+size_t TMemoryOutput::DoNext(void** ptr) {
     Y_ENSURE(Buf_ < End_, TStringBuf("memory output stream exhausted"));
     Y_ENSURE(Buf_ < End_, TStringBuf("memory output stream exhausted"));
-    *ptr = Buf_; 
-    size_t bufferSize = End_ - Buf_; 
-    Buf_ = End_; 
- 
-    return bufferSize; 
-} 
- 
-void TMemoryOutput::DoUndo(size_t len) { 
-    Buf_ -= len; 
-} 
- 
+    *ptr = Buf_;
+    size_t bufferSize = End_ - Buf_;
+    Buf_ = End_;
+
+    return bufferSize;
+}
+
+void TMemoryOutput::DoUndo(size_t len) {
+    Buf_ -= len;
+}
+
 void TMemoryOutput::DoWrite(const void* buf, size_t len) {
 void TMemoryOutput::DoWrite(const void* buf, size_t len) {
     char* end = Buf_ + len;
     char* end = Buf_ + len;
     Y_ENSURE(end <= End_, TStringBuf("memory output stream exhausted"));
     Y_ENSURE(end <= End_, TStringBuf("memory output stream exhausted"));

+ 4 - 4
util/stream/mem.h

@@ -1,7 +1,7 @@
 #pragma once
 #pragma once
 
 
 #include "zerocopy.h"
 #include "zerocopy.h"
-#include "zerocopy_output.h" 
+#include "zerocopy_output.h"
 
 
 #include <util/generic/strbuf.h>
 #include <util/generic/strbuf.h>
 
 
@@ -108,7 +108,7 @@ private:
 /**
 /**
  * Output stream that writes data to a memory block.
  * Output stream that writes data to a memory block.
  */
  */
-class TMemoryOutput: public IZeroCopyOutput { 
+class TMemoryOutput: public IZeroCopyOutput {
 public:
 public:
     /**
     /**
      * Constructs a stream that writes to the provided memory block. It's up
      * Constructs a stream that writes to the provided memory block. It's up
@@ -174,8 +174,8 @@ public:
     }
     }
 
 
 private:
 private:
-    size_t DoNext(void** ptr) override; 
-    void DoUndo(size_t len) override; 
+    size_t DoNext(void** ptr) override;
+    void DoUndo(size_t len) override;
     void DoWrite(const void* buf, size_t len) override;
     void DoWrite(const void* buf, size_t len) override;
     void DoWriteC(char c) override;
     void DoWriteC(char c) override;
 
 

Некоторые файлы не были показаны из-за большого количества измененных файлов