mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 04:55:20 +01:00
Add buffer_size_ to reader move constructor and move operator=, apply minor changes
This commit is contained in:
parent
567995aafb
commit
9f4bcb03e1
@ -382,30 +382,27 @@ private:
|
||||
template <typename... Ts>
|
||||
no_void_validator_tup_t<Ts...> convert_impl(const split_data& elems) {
|
||||
clear_error();
|
||||
// TODO check if this is needed
|
||||
using return_type = no_void_validator_tup_t<Ts...>;
|
||||
|
||||
if (!splitter_.valid()) {
|
||||
set_error_bad_split();
|
||||
no_void_validator_tup_t<Ts...> ret{};
|
||||
return ret;
|
||||
return {};
|
||||
}
|
||||
|
||||
if (!columns_mapped()) {
|
||||
if (sizeof...(Ts) != elems.size()) {
|
||||
set_error_number_of_columns(sizeof...(Ts), elems.size());
|
||||
return return_type{};
|
||||
return {};
|
||||
}
|
||||
} else {
|
||||
if (sizeof...(Ts) != column_mappings_.size()) {
|
||||
set_error_incompatible_mapping(sizeof...(Ts),
|
||||
column_mappings_.size());
|
||||
return return_type{};
|
||||
return {};
|
||||
}
|
||||
|
||||
if (elems.size() != number_of_columns_) {
|
||||
set_error_number_of_columns(number_of_columns_, elems.size());
|
||||
return return_type{};
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -541,18 +541,19 @@ private:
|
||||
: delim_{delim}, file_{fopen(file_name_.c_str(), "rb")} {
|
||||
}
|
||||
|
||||
// TODO update for size_ and ssize_
|
||||
// TODO test for next_line_size_
|
||||
reader(reader&& other)
|
||||
: buffer_{other.buffer_},
|
||||
next_line_buffer_{other.next_line_buffer_},
|
||||
helper_buffer_{other.helper_buffer_}, converter_{std::move(
|
||||
other.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_},
|
||||
helper_size_{other.helper_size_}, delim_{std::move(other.delim_)},
|
||||
file_{other.file_}, crlf_{other.crlf_}, line_number_{
|
||||
other.line_number_} {
|
||||
file_{other.file_}, crlf_{other.crlf_},
|
||||
line_number_{other.line_number_}, next_line_size_{
|
||||
other.next_line_size_} {
|
||||
other.buffer_ = nullptr;
|
||||
other.next_line_buffer_ = nullptr;
|
||||
other.helper_buffer_ = nullptr;
|
||||
@ -566,13 +567,14 @@ private:
|
||||
helper_buffer_ = other.helper_buffer_;
|
||||
converter_ = std::move(other.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_;
|
||||
helper_size_ = other.helper_size_;
|
||||
delim_ = std::move(other.delim_);
|
||||
file_ = other.file_;
|
||||
crlf_ = other.crlf_;
|
||||
line_number_ = other.line_number_;
|
||||
next_line_size_ = other.next_line_size_;
|
||||
|
||||
other.buffer_ = nullptr;
|
||||
other.next_line_buffer_ = nullptr;
|
||||
@ -621,8 +623,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
size_ = size;
|
||||
ssize_ = ssize;
|
||||
next_line_size_ = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -630,13 +631,13 @@ private:
|
||||
size_t limit = 0;
|
||||
|
||||
if constexpr (escaped_multiline_enabled) {
|
||||
while (escaped_eol(size_)) {
|
||||
while (escaped_eol(next_line_size_)) {
|
||||
if (multiline_limit_reached(limit)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!append_next_line_to_buffer(next_line_buffer_, size_)) {
|
||||
// remove_eol(next_line_buffer_, ssize_);
|
||||
if (!append_next_line_to_buffer(next_line_buffer_,
|
||||
next_line_size_)) {
|
||||
next_line_converter_.set_error_unterminated_escape();
|
||||
return;
|
||||
}
|
||||
@ -651,22 +652,20 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
if (!append_next_line_to_buffer(next_line_buffer_, size_)) {
|
||||
// remove_eol(next_line_buffer_, ssize_);
|
||||
if (!append_next_line_to_buffer(next_line_buffer_,
|
||||
next_line_size_)) {
|
||||
next_line_converter_.set_error_unterminated_quote();
|
||||
return;
|
||||
}
|
||||
|
||||
if constexpr (escaped_multiline_enabled) {
|
||||
while (escaped_eol(size_)) {
|
||||
while (escaped_eol(next_line_size_)) {
|
||||
if (multiline_limit_reached(limit)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!append_next_line_to_buffer(next_line_buffer_,
|
||||
size_)) {
|
||||
// TODO not needed
|
||||
// remove_eol(next_line_buffer_, ssize_);
|
||||
next_line_size_)) {
|
||||
next_line_converter_
|
||||
.set_error_unterminated_escape();
|
||||
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;
|
||||
}
|
||||
|
||||
// TODO check why multiline fields result in additional allocations
|
||||
void realloc_concat(char*& first, size_t& first_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;
|
||||
first = static_cast<char*>(
|
||||
realloc(static_cast<void*>(first), next_line_buffer_size_));
|
||||
// TODO handle realloc
|
||||
if (!first) {
|
||||
exit(EXIT_FAILURE);
|
||||
throw std::bad_alloc{};
|
||||
}
|
||||
std::copy_n(second, second_size + 1, first + first_size);
|
||||
first_size += second_size;
|
||||
@ -794,9 +794,7 @@ private:
|
||||
bool crlf_;
|
||||
size_t line_number_{0};
|
||||
|
||||
// TODO check if needed
|
||||
size_t size_{0};
|
||||
ssize_t ssize_{0};
|
||||
size_t next_line_size_{0};
|
||||
};
|
||||
|
||||
////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user