Skip to content

Commit

Permalink
feat: introduce specilized API to write fixed length data rapidly
Browse files Browse the repository at this point in the history
Signed-off-by: SchrodingerZhu <[email protected]>
  • Loading branch information
SchrodingerZhu committed Jun 21, 2022
1 parent ebb27d1 commit 74164e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dbms/src/Flash/Coprocessor/TiDBColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ template <typename T>
void encodeLittleEndian(const T & value, WriteBuffer & ss)
{
auto v = toLittleEndian(value);
ss.write(reinterpret_cast<const char *>(&v), sizeof(v));
ss.template writeFixed<T>(&v);
}

TiDBColumn::TiDBColumn(Int8 element_len_)
Expand Down
18 changes: 18 additions & 0 deletions dbms/src/IO/WriteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ class WriteBuffer : public BufferBase
}
}

template <class T>
__attribute__((always_inline)) void writeFixed(const T * __restrict from)
{
if (likely(working_buffer.end() - pos >= static_cast<ptrdiff_t>(sizeof(T))))
{
tiflash_compiler_builtin_memcpy(pos, from, sizeof(T));
pos += sizeof(T);
}
else
{
[&]() __attribute__((noinline))
{
write(reinterpret_cast<const char *>(from), sizeof(T));
}
();
}
}


inline void write(char x)
{
Expand Down

0 comments on commit 74164e7

Please sign in to comment.