Skip to content
Permalink
Browse files
[Improvement] remove unnecessary memcpy in OlapBlockDataConvertor (#9491
)

* [Improvement] remove unnecessary memcpy in OlapBlockDataConvertor
  • Loading branch information
Gabriel39 committed May 13, 2022
1 parent 650e3a6 commit 4ca5be94a7940a88b4c8150873a9cb5b69931244
Showing 2 changed files with 5 additions and 14 deletions.
@@ -317,8 +317,6 @@ void OlapBlockDataConvertor::OlapColumnDataConvertorChar::set_source_column(
const ColumnWithTypeAndName& typed_column, size_t row_pos, size_t num_rows) {
OlapBlockDataConvertor::OlapColumnDataConvertorBase::set_source_column(typed_column, row_pos,
num_rows);
_raw_data.resize(_length * num_rows);
memset(_raw_data.data(), 0, _length * num_rows);
_slice.resize(num_rows);
}

@@ -352,21 +350,18 @@ Status OlapBlockDataConvertor::OlapColumnDataConvertorChar::convert_to_olap() {
const ColumnString::Char* char_data = column_string->get_chars().data();
const ColumnString::Offset* offset_cur = column_string->get_offsets().data() + _row_pos;
const ColumnString::Offset* offset_end = offset_cur + _num_rows;
char* raw_data = _raw_data.data();
Slice* slice = _slice.data();
size_t string_length;
size_t string_offset = *(offset_cur - 1);
size_t slice_size = _length;
[[maybe_unused]] size_t slice_size = _length;
if (_nullmap) {
const UInt8* nullmap_cur = _nullmap + _row_pos;
while (offset_cur != offset_end) {
if (!*nullmap_cur) {
string_length = *offset_cur - string_offset - 1;
assert(string_length <= slice_size);
memcpy(raw_data, char_data + string_offset, string_length);

slice->data = raw_data;
slice->size = slice_size;
slice->data = (char*)char_data + string_offset;
slice->size = string_length;
} else {
// TODO: this may not be neccessary, check and remove later
slice->data = nullptr;
@@ -377,22 +372,19 @@ Status OlapBlockDataConvertor::OlapColumnDataConvertorChar::convert_to_olap() {
++nullmap_cur;
++slice;
++offset_cur;
raw_data += slice_size;
}
assert(nullmap_cur == _nullmap + _row_pos + _num_rows && slice == _slice.get_end_ptr());
} else {
while (offset_cur != offset_end) {
string_length = *offset_cur - string_offset - 1;
assert(string_length <= slice_size);
memcpy(raw_data, char_data + string_offset, string_length);

slice->data = raw_data;
slice->size = slice_size;
slice->data = (char*)char_data + string_offset;
slice->size = string_length;

string_offset = *offset_cur;
++slice;
++offset_cur;
raw_data += slice_size;
}
assert(slice == _slice.get_end_ptr());
}
@@ -101,7 +101,6 @@ class OlapBlockDataConvertor {
private:
size_t _length;
PaddedPODArray<Slice> _slice;
PaddedPODArray<char> _raw_data;
};

class OlapColumnDataConvertorVarChar : public OlapColumnDataConvertorBase {

0 comments on commit 4ca5be9

Please sign in to comment.