small fix

This commit is contained in:
Nikita Mikhaylov 2019-11-21 16:44:11 +03:00
parent c913155d95
commit 31cb69269b

View File

@ -384,32 +384,36 @@ void registerInputFormatProcessorTabSeparated(FormatFactory & factory)
}
}
void saveUpToPosition(ReadBuffer & in, DB::Memory<> & memory, char * ptr)
void saveUpToPosition(ReadBuffer & in, DB::Memory<> & memory, char * current)
{
assert(ptr >= in.position());
assert(ptr <= in.buffer().end());
const int old_bytes = memory.size();
const int additional_bytes = ptr - in.position();
const int additional_bytes = current - in.position();
const int new_bytes = old_bytes + additional_bytes;
/// There are no new bytes to add to memory.
/// No need to do extra stuff.
if (new_bytes == 0)
return;
memory.resize(new_bytes);
memcpy(memory.data() + old_bytes, in.position(), additional_bytes);
in.position() = ptr;
in.position() = current;
}
bool loadAtPosition(ReadBuffer & in, DB::Memory<> & memory, char * & ptr)
bool loadAtPosition(ReadBuffer & in, DB::Memory<> & memory, char * & current)
{
assert(ptr <= in.buffer().end());
if (ptr < in.buffer().end())
if (current < in.buffer().end())
{
return true;
}
saveUpToPosition(in, memory, in.buffer().end());
saveUpToPosition(in, memory, current);
bool loaded_more = !in.eof();
assert(in.position() == in.buffer().begin());
ptr = in.position();
current = in.position();
return loaded_more;
}