mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-12 17:32:32 +00:00
Added suggestion from Nikolay Kochetov #3720
This commit is contained in:
parent
621e622f79
commit
be80b7b188
@ -8,6 +8,11 @@
|
|||||||
namespace DB
|
namespace DB
|
||||||
{
|
{
|
||||||
|
|
||||||
|
namespace ErrorCodes
|
||||||
|
{
|
||||||
|
extern const int CANNOT_WRITE_AFTER_END_OF_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
/** Writes data to existing std::vector or similar type. When not enough space, it doubles vector size.
|
/** Writes data to existing std::vector or similar type. When not enough space, it doubles vector size.
|
||||||
*
|
*
|
||||||
* In destructor, vector is cutted to the size of written data.
|
* In destructor, vector is cutted to the size of written data.
|
||||||
@ -24,6 +29,9 @@ private:
|
|||||||
|
|
||||||
void nextImpl() override
|
void nextImpl() override
|
||||||
{
|
{
|
||||||
|
if (is_finished)
|
||||||
|
throw Exception("WriteBufferFromVector is finished", ErrorCodes::CANNOT_WRITE_AFTER_END_OF_BUFFER);
|
||||||
|
|
||||||
size_t old_size = vector.size();
|
size_t old_size = vector.size();
|
||||||
vector.resize(old_size * 2);
|
vector.resize(old_size * 2);
|
||||||
internal_buffer = Buffer(reinterpret_cast<Position>(&vector[old_size]), reinterpret_cast<Position>(vector.data() + vector.size()));
|
internal_buffer = Buffer(reinterpret_cast<Position>(&vector[old_size]), reinterpret_cast<Position>(vector.data() + vector.size()));
|
||||||
@ -49,6 +57,9 @@ public:
|
|||||||
((position() - reinterpret_cast<Position>(vector.data()))
|
((position() - reinterpret_cast<Position>(vector.data()))
|
||||||
+ sizeof(typename VectorType::value_type) - 1) /// Align up.
|
+ sizeof(typename VectorType::value_type) - 1) /// Align up.
|
||||||
/ sizeof(typename VectorType::value_type));
|
/ sizeof(typename VectorType::value_type));
|
||||||
|
|
||||||
|
/// Prevent further writes.
|
||||||
|
set(nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
~WriteBufferFromVector() override
|
~WriteBufferFromVector() override
|
||||||
|
Loading…
Reference in New Issue
Block a user