Add buffer_size_ to reader move constructor and move operator=, apply minor changes

This commit is contained in:
ado 2023-07-12 23:33:33 +02:00
parent 567995aafb
commit 9f4bcb03e1
2 changed files with 25 additions and 30 deletions

View File

@ -382,30 +382,27 @@ private:
template <typename... Ts> template <typename... Ts>
no_void_validator_tup_t<Ts...> convert_impl(const split_data& elems) { no_void_validator_tup_t<Ts...> convert_impl(const split_data& elems) {
clear_error(); clear_error();
// TODO check if this is needed
using return_type = no_void_validator_tup_t<Ts...>;
if (!splitter_.valid()) { if (!splitter_.valid()) {
set_error_bad_split(); set_error_bad_split();
no_void_validator_tup_t<Ts...> ret{}; return {};
return ret;
} }
if (!columns_mapped()) { if (!columns_mapped()) {
if (sizeof...(Ts) != elems.size()) { if (sizeof...(Ts) != elems.size()) {
set_error_number_of_columns(sizeof...(Ts), elems.size()); set_error_number_of_columns(sizeof...(Ts), elems.size());
return return_type{}; return {};
} }
} else { } else {
if (sizeof...(Ts) != column_mappings_.size()) { if (sizeof...(Ts) != column_mappings_.size()) {
set_error_incompatible_mapping(sizeof...(Ts), set_error_incompatible_mapping(sizeof...(Ts),
column_mappings_.size()); column_mappings_.size());
return return_type{}; return {};
} }
if (elems.size() != number_of_columns_) { if (elems.size() != number_of_columns_) {
set_error_number_of_columns(number_of_columns_, elems.size()); set_error_number_of_columns(number_of_columns_, elems.size());
return return_type{}; return {};
} }
} }

View File

@ -541,18 +541,19 @@ private:
: delim_{delim}, file_{fopen(file_name_.c_str(), "rb")} { : delim_{delim}, file_{fopen(file_name_.c_str(), "rb")} {
} }
// TODO update for size_ and ssize_ // TODO test for next_line_size_
reader(reader&& other) reader(reader&& other)
: buffer_{other.buffer_}, : buffer_{other.buffer_},
next_line_buffer_{other.next_line_buffer_}, next_line_buffer_{other.next_line_buffer_},
helper_buffer_{other.helper_buffer_}, converter_{std::move( helper_buffer_{other.helper_buffer_}, converter_{std::move(
other.converter_)}, other.converter_)},
next_line_converter_{std::move(other.next_line_converter_)}, next_line_converter_{std::move(other.next_line_converter_)},
buffer_size_{other.size_}, buffer_size_{other.buffer_size_},
next_line_buffer_size_{other.next_line_buffer_size_}, next_line_buffer_size_{other.next_line_buffer_size_},
helper_size_{other.helper_size_}, delim_{std::move(other.delim_)}, helper_size_{other.helper_size_}, delim_{std::move(other.delim_)},
file_{other.file_}, crlf_{other.crlf_}, line_number_{ file_{other.file_}, crlf_{other.crlf_},
other.line_number_} { line_number_{other.line_number_}, next_line_size_{
other.next_line_size_} {
other.buffer_ = nullptr; other.buffer_ = nullptr;
other.next_line_buffer_ = nullptr; other.next_line_buffer_ = nullptr;
other.helper_buffer_ = nullptr; other.helper_buffer_ = nullptr;
@ -566,13 +567,14 @@ private:
helper_buffer_ = other.helper_buffer_; helper_buffer_ = other.helper_buffer_;
converter_ = std::move(other.converter_); converter_ = std::move(other.converter_);
next_line_converter_ = std::move(other.next_line_converter_); next_line_converter_ = std::move(other.next_line_converter_);
buffer_size_ = other.size_; buffer_size_ = other.buffer_size_;
next_line_buffer_size_ = other.next_line_buffer_size_; next_line_buffer_size_ = other.next_line_buffer_size_;
helper_size_ = other.helper_size_; helper_size_ = other.helper_size_;
delim_ = std::move(other.delim_); delim_ = std::move(other.delim_);
file_ = other.file_; file_ = other.file_;
crlf_ = other.crlf_; crlf_ = other.crlf_;
line_number_ = other.line_number_; line_number_ = other.line_number_;
next_line_size_ = other.next_line_size_;
other.buffer_ = nullptr; other.buffer_ = nullptr;
other.next_line_buffer_ = nullptr; other.next_line_buffer_ = nullptr;
@ -621,8 +623,7 @@ private:
} }
} }
size_ = size; next_line_size_ = size;
ssize_ = ssize;
return true; return true;
} }
@ -630,13 +631,13 @@ private:
size_t limit = 0; size_t limit = 0;
if constexpr (escaped_multiline_enabled) { if constexpr (escaped_multiline_enabled) {
while (escaped_eol(size_)) { while (escaped_eol(next_line_size_)) {
if (multiline_limit_reached(limit)) { if (multiline_limit_reached(limit)) {
return; return;
} }
if (!append_next_line_to_buffer(next_line_buffer_, size_)) { if (!append_next_line_to_buffer(next_line_buffer_,
// remove_eol(next_line_buffer_, ssize_); next_line_size_)) {
next_line_converter_.set_error_unterminated_escape(); next_line_converter_.set_error_unterminated_escape();
return; return;
} }
@ -651,22 +652,20 @@ private:
return; return;
} }
if (!append_next_line_to_buffer(next_line_buffer_, size_)) { if (!append_next_line_to_buffer(next_line_buffer_,
// remove_eol(next_line_buffer_, ssize_); next_line_size_)) {
next_line_converter_.set_error_unterminated_quote(); next_line_converter_.set_error_unterminated_quote();
return; return;
} }
if constexpr (escaped_multiline_enabled) { if constexpr (escaped_multiline_enabled) {
while (escaped_eol(size_)) { while (escaped_eol(next_line_size_)) {
if (multiline_limit_reached(limit)) { if (multiline_limit_reached(limit)) {
return; return;
} }
if (!append_next_line_to_buffer(next_line_buffer_, if (!append_next_line_to_buffer(next_line_buffer_,
size_)) { next_line_size_)) {
// TODO not needed
// remove_eol(next_line_buffer_, ssize_);
next_line_converter_ next_line_converter_
.set_error_unterminated_escape(); .set_error_unterminated_escape();
return; return;
@ -674,7 +673,8 @@ private:
} }
} }
next_line_converter_.resplit(next_line_buffer_, size_); next_line_converter_.resplit(next_line_buffer_,
next_line_size_);
} }
} }
} }
@ -735,15 +735,15 @@ private:
return size; return size;
} }
// TODO check why multiline fields result in additional allocations
void realloc_concat(char*& first, size_t& first_size, void realloc_concat(char*& first, size_t& first_size,
const char* const second, size_t second_size) { const char* const second, size_t second_size) {
// TODO make buffer_size an argument !!!!!! // TODO make buffer_size an argument
next_line_buffer_size_ = first_size + second_size + 3; next_line_buffer_size_ = first_size + second_size + 3;
first = static_cast<char*>( first = static_cast<char*>(
realloc(static_cast<void*>(first), next_line_buffer_size_)); realloc(static_cast<void*>(first), next_line_buffer_size_));
// TODO handle realloc
if (!first) { if (!first) {
exit(EXIT_FAILURE); throw std::bad_alloc{};
} }
std::copy_n(second, second_size + 1, first + first_size); std::copy_n(second, second_size + 1, first + first_size);
first_size += second_size; first_size += second_size;
@ -794,9 +794,7 @@ private:
bool crlf_; bool crlf_;
size_t line_number_{0}; size_t line_number_{0};
// TODO check if needed size_t next_line_size_{0};
size_t size_{0};
ssize_t ssize_{0};
}; };
//////////////// ////////////////